Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save(self, *args, **kwargs):
providers = micawber.bootstrap_basic()
try:
self.embed = providers.request(self.link)['html']
except micawber.ProviderException,e:
self.embed = None
super(Link,self).save(*args, **kwargs)
def main():
print('Please wait, loading providers from oembed.com')
providers = bootstrap_oembed()
while 1:
url = read_input('Enter a url (or q to quit): ')
if url.lower().strip() == 'q':
break
try:
result = providers.request(url)
except ProviderException:
print('No provider found for that url :/')
else:
print('Data for %s\n====================================================' % url)
pprint.pprint(result)
def clean(self):
# Avoid getting server errors when the URL is not valid.
try:
self.update_oembed_data()
except ProviderException as e:
raise ValidationError(str(e))
def clean(self):
""" Get OEmbed metadata on save. """
# load up rules for some default providers, such as youtube and flickr
providers = micawber.bootstrap_basic()
# Get the data
try:
oembed_data = providers.request(self.url)
except micawber.ProviderException as e:
msg = _(u"Could not find metadata for object: %s" % e.message)
raise ValidationError(msg)
logger.debug(u'Found OEmbed data on %s for %s',self.url, self)
for (key, value) in oembed_data.iteritems():
try:
if not getattr(self, key):
logger.debug(u'Setting field %s on %s to %s', key, self, value)
setattr(self, key, value)
except AttributeError:
pass
Render an OEmbed-compatible link as an embedded item.
:param url: A URL of an OEmbed provider.
:return: The OEMbed ```` code.
"""
# Note: this method isn't currently very efficient - the data isn't
# cached or stored.
kwargs = dict(urlparse.parse_qsl(params))
try:
return mark_safe(get_oembed_data(
url,
**kwargs
)['html'])
except (KeyError, ProviderException):
if settings.DEBUG:
return "No OEmbed data returned"
return ""