def attributes(cls): ''' 표 33 문단 번호 ''' yield ARRAY(NumberingLevel, 7), 'levels' yield UINT16, 'starting_number' yield dict(type=ARRAY(UINT32, 7), name='unknown', version=(5, 0, 3, 0))
def attributes(): yield UINT16, 'byteorder' yield UINT16, 'format' yield UINT16, 'osversion' yield UINT16, 'os' yield ARRAY(BYTE, 16), 'clsid' yield N_ARRAY(UINT32, MSOLEPropertySectionDesc), 'sections'
def test_typed_struct_attributes(self): class SomeRandomStruct(Struct): @staticmethod def attributes(): yield INT32, 'a' yield BSTR, 'b' yield ARRAY(INT32, 3), 'c' attributes = dict(a=1, b=u'abc', c=(4, 5, 6)) typed_attributes = typed_struct_attributes(SomeRandomStruct, attributes, dict()) typed_attributes = list(typed_attributes) expected = [ dict(name='a', type=INT32, value=1), dict(name='b', type=BSTR, value='abc'), dict(name='c', type=ARRAY(INT32, 3), value=(4, 5, 6)) ] self.assertEqual(expected, typed_attributes)
class ParaCharShapeList(list): __metaclass__ = ArrayType itemtype = ARRAY(UINT16, 2) def read(cls, f, context): bytes = f.read() return cls.decode(bytes, context) read = classmethod(read) def decode(payload, context=None): import struct fmt = 'II' unitsize = struct.calcsize('<' + fmt) unitcount = len(payload) / unitsize values = struct.unpack('<' + (fmt * unitcount), payload) return list( tuple(values[i * 2:i * 2 + 2]) for i in range(0, unitcount)) decode = staticmethod(decode)
def attributes(): ''' 표 56 문단의 글자 모양 ''' yield dict(name='charshapes', type=X_ARRAY(ARRAY(UINT32, 2), ref_parent_member('charshapes')))
def attributes(): yield ARRAY(BYTE, 16), 'formatid' yield UINT32, 'offset'
def attributes(): yield UINT16, 'byteOrder' yield UINT16, 'version' yield UINT32, 'systemIdentifier' yield ARRAY(BYTE, 16), 'clsid' yield N_ARRAY(UINT32, PropertySetDesc), 'propsetDescList'
def attributes(): yield INT32, 'a' yield BSTR, 'b' yield ARRAY(INT32, 3), 'c'
def test_new(self): t1 = ARRAY(INT32, 3) t2 = ARRAY(INT32, 3) assert t1 is t2 assert N_ARRAY(INT32, INT32) is N_ARRAY(INT32, INT32)