Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4e562421cb
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (32 sloc) 1.187 kb
from django.utils import simplejson
from oembed.exceptions import OEmbedException
class OEmbedResource(object):
OEmbed resource, as well as a factory for creating resource instances
from response json
_data = {}
content_object = None
def __getattr__(self, name):
return self._data.get(name)
def get_data(self):
return self._data
def load_data(self, data):
self._data = data
def json(self):
return simplejson.dumps(self._data)
def create(cls, data):
if not 'type' in data or not 'version' in data:
raise OEmbedException('Missing required fields on OEmbed response.')
data['width'] = data.get('width') and int(data['width']) or None
data['height'] = data.get('height') and int(data['height']) or None
filtered_data = dict([(k, v) for k, v in data.items() if v])
resource = cls()
return resource
def create_json(cls, raw):
data = simplejson.loads(raw)
return cls.create(data)
Jump to Line
Something went wrong with that request. Please try again.