def read(cls, fp, version=1, padding=1): signature = read_fmt('4s', fp)[0] if signature not in cls._SIGNATURES: logger.warning('Invalid signature (%r)' % (signature)) fp.seek(-4, 1) return None key = read_fmt('4s', fp)[0] try: key = TaggedBlockID(key) except ValueError: message = 'Unknown key: %r' % (key) warn(message) logger.warning(message) fmt = cls._length_format(key, version) raw_data = read_length_block(fp, fmt=fmt, padding=padding) kls = TYPES.get(key) if kls: data = kls.frombytes(raw_data, version=version) # _raw_data = data.tobytes(version=version, # padding=1 if padding == 4 else 4) # assert raw_data == _raw_data, '%r: %s vs %s' % ( # kls, trimmed_repr(raw_data), trimmed_repr(_raw_data) # ) else: message = 'Unknown tagged block: %r, %s' % (key, trimmed_repr(raw_data)) warn(message) logger.warning(message) data = raw_data return cls(signature, key, data)
def _repr_pretty_(self, p, cycle): if cycle: return self.__repr__() if isinstance(self.value, bytes): p.text(trimmed_repr(self.value)) else: p.pretty(self.value)
def __repr__(self): return "ImageResource(%r %s, %r, %s)" % ( self.resource_id, ImageResourceID.name_of(self.resource_id), self.name, trimmed_repr(self.data), )
def _repr_pretty_(self, p, cycle): if cycle: p.text(repr(self)) else: with p.group(0, 'Block(', ')'): p.text("%s %s, " % (self.key, TaggedBlock.name_of(self.key))) if isinstance(self.data, bytes): p.text(trimmed_repr(self.data)) else: p.pretty(self.data)
def _repr_pretty_(self, p, cycle): if cycle: p.text("RawData(...)") else: with p.group(1, "RawData(", ")"): p.breakable() p.text("value=") if isinstance(self.value, bytes): p.text(trimmed_repr(self.value)) else: p.pretty(self.value)
def _repr_pretty_(self, p, cycle): if cycle: p.text('Block(...)') else: with p.group(1, 'Block(', ')'): p.breakable() p.text("%s %s," % (self.key, TaggedBlock.name_of(self.key))) p.breakable() if isinstance(self.data, bytes): p.text(trimmed_repr(self.data)) else: p.pretty(self.data)
def _repr_pretty_(self, p, cycle): if cycle: p.text(repr(self)) else: with p.group(0, 'ImageResource(', ')'): p.text("%r %s, %r, " % ( self.resource_id, ImageResourceID.name_of(self.resource_id), self.name )) if isinstance(self.data, bytes): p.text(trimmed_repr(self.data)) else: p.pretty(self.data)
def _repr_pretty_(self, p, cycle): if cycle: return "[...]".format(name=self.__class__.__name__) with p.group(2, '['.format(name=self.__class__.__name__), ']'): p.breakable('') for idx in range(len(self._items)): if idx: p.text(',') p.breakable() value = self._items[idx] if isinstance(value, bytes): value = trimmed_repr(value) p.pretty(value) p.breakable('')
def _repr_pretty_(self, p, cycle): if cycle: p.text(repr(self)) else: p.begin_group(2, "RawData(") p.begin_group(0) p.break_() p.text("value = ") if isinstance(self.value, bytes): p.text(trimmed_repr(self.value)) else: p.pretty(self.value) p.end_group(2) p.break_() p.end_group(0, ")")
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] p.pretty(key) p.text(': ') if isinstance(value, bytes): value = trimmed_repr(value) p.pretty(value) p.breakable('')
def _repr_pretty_(self, p, cycle): if cycle: return "{name}(...)".format(name=self.__class__.__name__) with p.group(2, '{name}('.format(name=self.__class__.__name__), ')'): p.breakable('') fields = [f for f in attr.fields(self.__class__) if f.repr] for idx, field in enumerate(fields): if idx: p.text(',') p.breakable() p.text('{field}='.format(field=field.name)) value = getattr(self, field.name) if isinstance(value, bytes): p.text(trimmed_repr(value)) elif isinstance(value, Enum): p.text(value.name) else: p.pretty(value) p.breakable('')
def _repr_pretty_(self, p, cycle): if cycle: return "{{...}".format(name=self.__class__.__name__) with p.group(2, '{{'.format(name=self.__class__.__name__), '}'): p.breakable('') for idx, key in enumerate(self._items): if idx: p.text(',') p.breakable() value = self._items[key] if hasattr(key, 'name'): p.text(key.name) else: p.pretty(key) p.text(': ') if isinstance(value, bytes): value = trimmed_repr(value) p.pretty(value) p.breakable('')
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(Tag(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('')
def _repr_pretty_(self, p, cycle): if cycle: return "{name}{{...}".format(name=self.__class__.__name__) prefix = '{cls}({name}){{'.format( cls=self.__class__.__name__, name=getattr(self.classID, 'name', self.classID), ) with p.group(2, prefix, '}'): p.breakable('') for idx, key in enumerate(self): if idx: p.text(',') p.breakable() value = self[key] p.pretty(key.decode('ascii')) p.text(': ') if isinstance(value, bytes): p.text(trimmed_repr(value)) else: p.pretty(value) p.breakable('')
def __repr__(self): return "RawData(value=%s)" % trimmed_repr(self.value)
def __repr__(self): return "ImageResource(%r %s, %r, %s)" % ( self.resource_id, ImageResourceID.name_of( self.resource_id), self.name, trimmed_repr(self.data))
def check_read_write(cls, data, *args, **kwargs): element = cls.frombytes(data, *args, **kwargs) new_data = element.tobytes(*args, **kwargs) assert data == new_data, '%s vs %s' % (trimmed_repr(data), trimmed_repr(new_data))
def __repr__(self): return "Block(%s %s, %s)" % (self.key, TaggedBlock.name_of( self.key), trimmed_repr(self.data))
def __repr__(self): return "Block(%s %s, %s)" % (self.key, TaggedBlock.name_of(self.key), trimmed_repr(self.data))