def test_xml__load_root(): # invalid with pytest.raises(XmlLoadError): xml.load_root(io.BytesIO(b'<root><child1/><child2/></root>')) with pytest.raises(XmlLoadError): xml.load_root(io.BytesIO(b'<root><child/></root>'), 'x') # valid for name in (None, 'child'): node = xml.load_root( io.BytesIO(b'<root><child><el>test</el></child></root>'), name) assert node.tag == 'child' assert node.el.text == 'test'
def _read(self, reader, config): prices = xmlutils.load_root(reader, 'online_prices') xmlutils.validate_schema( prices, { 'online_price': { 'aoc_id': None, 'eshop_sales_status': None, 'price': { 'regular_price': { 'amount': None, 'currency': None, 'raw_value': None } } } }, False) self.prices = {} for price in prices.online_price: assert len(price.price.getchildren()) == 1 regular_price = price.price.regular_price self.prices[ids.ContentID(price.aoc_id.text)] = SamuraiDlcPrice( price.eshop_sales_status.text, regular_price.get('id'), common.SamuraiPrice(float(regular_price.raw_value.text), regular_price.currency.text))
def _read(self, reader, config): news_xml = xmlutils.load_root(reader, 'news') xmlutils.validate_schema( news_xml, { 'news_entry': { 'headline': None, 'description': None, 'date': None, 'images': { 'image': None } } }, True) self.entries = [] for entry in getattr(news_xml, 'news_entry', []): if hasattr(entry, 'images'): images = [ SamuraiNewsImage(image.get('url'), image.get('type'), int(image.get('index')), int(image.get('width')), int(image.get('height'))) for image in entry.images.image ] else: images = [] self.entries.append( SamuraiNewsEntry(entry.headline.text, entry.description.text, entry.date.text, images))
def _read(self, reader, config): el = xmlutils.load_root(reader) self.length = int(el.get('length')) self.offset = int(el.get('offset')) self.total = int(el.get('total')) self._read_list(el)
def _read(self, reader, config): ec_info = xmlutils.load_root(reader, 'title_ec_info') xmlutils.validate_schema( ec_info, { 'title_id': None, 'content_size': None, 'title_version': None, 'disable_download': None, 'content_lock': { 'seed_published': None, 'external_seed': None, 'playable_date': None } }, True) self.title_id = ids.TitleID(ec_info.title_id.text) self.content_size = int(ec_info.content_size.text) self.version = int(ec_info.title_version.text) self.download_disabled = utils.misc.get_bool( ec_info.disable_download.text) if hasattr(ec_info, 'content_lock'): self.seed_published = utils.misc.get_bool( ec_info.content_lock.seed_published.text) self.external_seed = xmlutils.get_text(ec_info.content_lock, 'external_seed') self.playable_date = xmlutils.get_text(ec_info.content_lock, 'playable_date')
def _read(self, reader, config): aocs = xmlutils.load_root(reader, 'aocs') xmlutils.validate_schema(aocs, {'aoc': {'data_size': None}}, False) self.sizes = { ids.ContentID(aoc.get('id')): int(aoc.data_size.text) for aoc in aocs.aoc }
def _read(self, reader, config): pairs = xmlutils.load_root(reader, 'title_id_pairs') if len(pairs.getchildren()) == 0: raise NoIDPairMatchError xmlutils.validate_schema(pairs, { 'title_id_pair': { 'ns_uid': None, 'title_id': None, 'type': None } }, False) assert len(pairs.getchildren()) == 1 pair = pairs.title_id_pair assert pair.type.text in ( 'T', 'D' ) # 'Title'/'Demo'? # not sure if there are any other types self.content_id = ids.ContentID(pair.ns_uid.text) self.title_id = ids.TitleID(pair.title_id.text)
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 _read(self, reader, config): title_xml = xmlutils.load_root(reader, 'title') self._read_title(title_xml)
def _read(self, reader, config): aocs = xmlutils.load_root(reader, 'aocs') self._read_dlcs(aocs)
def _read(self, reader, config): telops_xml = xmlutils.load_root(reader, 'telops') xmlutils.validate_schema(telops_xml, {'telop': None}, True) self.entries = [el.text for el in getattr(telops_xml, 'telop', [])]
def _read(self, reader, config): movie_xml = xmlutils.load_root(reader, 'movie') self.movie = SamuraiMovieElement._parse(movie_xml)
def _read(self, reader, config): title_xml = xmlutils.load_root(reader, 'title') self.title = SamuraiTitleElement._parse(title_xml)