Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def to_dict(self, depth=-1, **kwargs):
"""Returns a dict representation of the object."""
out = super(Link, self).to_dict(depth=-1, **kwargs)
out['url'] = self.url
return out
class Link(Element):
"""An abstract class for embedding a link in the HTML."""
def get_code(self):
"""Opens the link and returns the response's content."""
if self.code is None:
self.code = urlopen(self.url).read()
return self.code
def to_dict(self, depth=-1, **kwargs):
"""Returns a dict representation of the object."""
out = super(Link, self).to_dict(depth=-1, **kwargs)
out['url'] = self.url
return out
class JavascriptLink(Link):
"""Create a JavascriptLink object based on a url.
Parameters
----------
url : str
The url to be linked
download : bool, default False
Whether the target document shall be loaded right now.
"""
_template = Template(
'{% if kwargs.get("embedded",False) %}'
''
'{% else %}'
''
'{% endif %}'
''
'{% else %}'
''
'{% endif %}'
)
def __init__(self, url, download=False):
super(JavascriptLink, self).__init__()
self._name = 'JavascriptLink'
self.url = url
self.code = None
if download:
self.get_code()
class CssLink(Link):
"""Create a CssLink object based on a url.
Parameters
----------
url : str
The url to be linked
download : bool, default False
Whether the target document shall be loaded right now.
"""
_template = Template(
'{% if kwargs.get("embedded",False) %}'
'<style>{{this.get_code()}}</style>'
'{% else %}'
''
'{% endif %}'