def _parse(cls, xml: lxml.objectify.ObjectifiedElement) -> 'SamuraiListMovie': vals = utils.misc.dotdict() for child, tag, text in xmlutils.iter_children(xml): if _SamuraiListMovieBaseMixin._try_parse_value(vals, child, tag, text, {}): pass elif _SamuraiListMovieOptionalMixin._try_parse_value( vals, child, tag, text, { 'rating_info': common.SamuraiRating } ): pass else: raise ValueError(f'unknown tag: {tag}') return cls(**vals)
def _parse(cls, xml: lxml.objectify.ObjectifiedElement) -> 'SamuraiDlc3DS': vals = utils.misc.dotdict() for child, tag, text in xmlutils.iter_children(xml): if tag == 'name': vals.name = text elif tag == 'price': xmlutils.validate_schema( child, {'regular_price': { 'amount': None, 'currency': None }}, False) vals.price = common.SamuraiPrice( float(child.regular_price.amount.text), child.regular_price.currency.text) else: raise ValueError(f'unknown tag: {tag}') return cls(**vals)
def _read(self, reader, config): content = xmlutils.load_root(reader, 'content') assert len(content.getchildren()) == 1 demo = content.demo xmlutils.validate_schema( demo, { 'name': None, 'icon_url': None, 'rating_info': common.SamuraiRatingDetailed._get_schema()[0] }, True) for child, tag, text in xmlutils.iter_children(demo): if tag == 'name': self.name = text elif tag == 'icon_url': self.icon_url = text elif tag == 'rating_info': self.rating_info = common.SamuraiRatingDetailed._parse(child) else: raise ValueError(f'unknown tag: {tag}')
def _parse(cls, xml: lxml.objectify.ObjectifiedElement) -> 'SamuraiMovieFile': vals = utils.misc.dotdict() vals.quality = xml.get('quality') for child, tag, text in xmlutils.iter_children(xml): if tag == 'format': vals.format = text elif tag == 'movie_url': vals.url = text elif tag == 'width': vals.width = int(text) elif tag == 'height': vals.height = int(text) elif tag == 'dimension': vals.dimension = text elif tag == 'play_time_sec': vals.seconds = int(text) else: raise ValueError(f'unknown tag: {tag}') return cls(**vals)
def _parse(cls, xml: lxml.objectify.ObjectifiedElement) -> 'SamuraiDlcWiiU': vals = utils.misc.dotdict() vals.is_new = utils.misc.get_bool(xml.get('new')) vals.content_id = ids.ContentID(xml.get('id')) for child, tag, text in xmlutils.iter_children(xml): if tag == 'name': vals.name = text elif tag == 'item_new_since': vals.release_date = text elif tag == 'icon_url': vals.icon_url = text elif tag == 'screenshots': vals.screenshots = [ common.SamuraiScreenshot._parse(screenshot) for screenshot in child.screenshot ] elif tag == 'promotion_images': vals.promotion_image_urls = [] for image in child.promotion_image: assert set(image.attrib.keys()) == {'index', 'url'} vals.promotion_image_urls.append(image.get('url')) elif tag == 'promotion_movie_url': vals.promotion_video_url = text elif tag == 'content_indexes': xmlutils.validate_schema(child, {'content_index': None}, False) vals.content_indexes = SamuraiDlcContentIndexes( child.get('variation'), [int(i.text) for i in child.content_index]) elif tag == 'description': vals.description = text elif tag == 'disclaimer': vals.disclaimer = text elif tag == 'allow_overlap': vals.allow_overlap = utils.misc.get_bool(text) else: raise ValueError(f'unknown tag: {tag}') return cls(**vals)
def test_xml__iter_children(xml_element): it = xml.iter_children(xml_element.node) assert next(it) == (xml_element.node.el1[0], 'el1', 'text1.0') assert next(it) == (xml_element.node.el1[1], 'el1', 'text1.1') assert next(it) == (xml_element.node.el2, 'el2', 'text2') assert next(it, None) is None