def read(cls, fp, encoding='macroman'): signature, key = read_fmt('4sH', fp) try: key = Resource(key) except ValueError: if Resource.is_path_info(key): logger.debug('Undefined PATH_INFO found: %d' % (key)) elif Resource.is_plugin_resource(key): logger.debug('Undefined PLUGIN_RESOURCE found: %d' % (key)) else: logger.warning('Unknown image resource %d' % (key)) name = read_pascal_string(fp, encoding, padding=2) raw_data = read_length_block(fp, padding=2) if key in TYPES: data = TYPES[key].frombytes(raw_data) # try: # _raw_data = data.tobytes(padding=1) # assert _raw_data == raw_data, '%r vs %r' % ( # _raw_data, raw_data # ) # except AssertionError as e: # logger.error(e) # raise else: data = raw_data return cls(signature, key, name, data)
def _repr_pretty_(self, p, cycle): if cycle: return '{{...}' with p.group(2, '{', '}'): p.breakable('') for idx, key in enumerate(self._items): if idx: p.text(',') p.breakable() value = self._items[key] try: p.text(Resource(key).name) except ValueError: p.pretty(key) p.text(': ') if isinstance(value.data, bytes): p.text(trimmed_repr(value.data)) else: p.pretty(value.data) p.breakable('')