def get_portraits(cls, data): portrait = data.get('portrait', None) if portrait is None: return width = convert(portrait.get('width'), float) height = convert(portrait.get('height'), float) if not width or not height: return return [ { '$source': 'node', 'file_id': portrait.get('id'), 'size': 0, 'width': width, 'height': height }, { '$source': 'node', 'file_id': portrait.get('small'), 'size': 1, 'width': math.ceil(width * 0.32), 'height': math.ceil(height * 0.32) }, { '$source': 'node', 'file_id': portrait.get('large'), 'size': 2, 'width': math.ceil(width * 3.2), 'height': math.ceil(height * 3.2) } ]
def get_portraits(cls, data): portrait = data.get('portrait', None) if portrait is None: return width = convert(portrait.get('width'), float) height = convert(portrait.get('height'), float) if not width or not height: return return [{ '$source': 'node', 'file_id': portrait.get('id'), 'size': 0, 'width': width, 'height': height }, { '$source': 'node', 'file_id': portrait.get('small'), 'size': 1, 'width': math.ceil(width * 0.32), 'height': math.ceil(height * 0.32) }, { '$source': 'node', 'file_id': portrait.get('large'), 'size': 2, 'width': math.ceil(width * 3.2), 'height': math.ceil(height * 3.2) }]
def create(cls, header, content_type, internal): params = dict([(field.name, field.value) for field in header.user_fields]) return cls( convert(params.get("MC-TTL"), int), convert(params.get("MD-Version"), int), params.get("MC-Cache-Policy"), content_type, internal, )
def create(cls, header, content_type, internal): params = dict([(field.name, field.value) for field in header.user_fields]) return cls( convert(params.get('MC-TTL'), int), convert(params.get('MD-Version'), int), params.get('MC-Cache-Policy'), content_type, internal )
def parse(cls, sp, data, parser): if type(data) is not dict: data = etree_convert(data) return Image(sp, { 'file_id': Uri.from_id('image', data.get('file_id')).to_gid(size=40), 'size': convert(data.get('size'), long), 'width': convert(data.get('width'), long), 'height': convert(data.get('height'), long) }, parser.XML, parser)
def parse(cls, sp, data, parser): if type(data) is not dict: data = etree_convert(data) return Image( sp, { 'file_id': Uri.from_id('image', data.get('file_id')).to_gid(size=40), 'size': convert(data.get('size'), long), 'width': convert(data.get('width'), long), 'height': convert(data.get('height'), long) }, parser.XML, parser)
def media_update(self, sp, xml, key): node_total = xml.find('total-%s' % key) # Media doesn't exist? if node_total is None: return # total-<media> setattr(self, '%s_total' % key, convert(node_total.text, int)) # <media> items = getattr(self, key) for node in xml.find(key): items.append(self.parse_node(sp, node))
def parse(cls, sp, data, parser): if type(data) is not dict: data = etree_convert(data) return Album(sp, { 'gid': Uri.from_id('album', data.get('id')).to_gid(), 'name': data.get('name'), 'artist': [ { '$source': 'node', 'id': data.get('artist-id'), 'name': data.get('artist-name') } ], 'type': cls.get_type(data.get('album-type')), 'cover': cls.get_covers(data), 'popularity': convert(data.get('popularity'), float), 'restriction': data.get('restrictions'), 'external_id': data.get('external-ids') }, parser.XML, parser)