Exemple #1
0
 def read(cls, fp):
     slice_id, group_id, origin = read_fmt('3I', fp)
     associated_id = read_fmt('I', fp)[0] if origin == 1 else None
     name = read_unicode_string(fp)
     slice_type = read_fmt('I', fp)[0]
     bbox = read_fmt('4I', fp)
     url = read_unicode_string(fp)
     target = read_unicode_string(fp)
     message = read_unicode_string(fp)
     alt_tag = read_unicode_string(fp)
     cell_is_html = read_fmt('?', fp)[0]
     cell_text = read_unicode_string(fp)
     horizontal_align, vertical_align = read_fmt('2I', fp)
     alpha, red, green, blue = read_fmt('4B', fp)
     data = None
     if is_readable(fp, 4):
         # There is no easy distinction between descriptor block and
         # next slice v6 item here...
         current_position = fp.tell()
         version = read_fmt('I', fp)[0]
         fp.seek(-4, 1)
         if version == 16:
             try:
                 data = DescriptorBlock.read(fp)
                 if data.classID == b'\x00\x00\x00\x00':
                     data = None
                     raise ValueError(data)
             except ValueError:
                 logger.debug('Failed to read DescriptorBlock')
                 fp.seek(current_position)
     return cls(slice_id, group_id, origin, associated_id, name, slice_type,
                bbox, url, target, message, alt_tag, cell_is_html,
                cell_text, horizontal_align, vertical_align, alpha, red,
                green, blue, data)
Exemple #2
0
    def read(cls, fp, **kwargs):
        kind = LinkedLayerType(read_fmt('4s', fp)[0])
        version = read_fmt('I', fp)[0]
        assert 1 <= version and version <= 7, 'Invalid version %d' % (version)
        uuid = read_pascal_string(fp, 'macroman', padding=1)
        filename = read_unicode_string(fp)
        filetype, creator, datasize, open_file = read_fmt('4s4sQB', fp)
        if open_file:
            open_file = DescriptorBlock.read(fp, padding=1)
        else:
            open_file = None

        linked_file = None
        timestamp = None
        data = None
        filesize = None
        child_id = None
        mod_time = None
        lock_state = None

        if kind == LinkedLayerType.EXTERNAL:
            linked_file = DescriptorBlock.read(fp, padding=1)
            if version > 3:
                timestamp = read_fmt('I4Bd', fp)
            filesize = read_fmt('Q', fp)[0]  # External file size.
            if version > 2:
                data = fp.read(datasize)
        elif kind == LinkedLayerType.ALIAS:
            read_fmt('8x', fp)
        if kind == LinkedLayerType.DATA:
            data = fp.read(datasize)
            assert len(data) == datasize, '(%d vs %d)' % (len(data), datasize)

        # The followings are not well documented...
        if version >= 5:
            child_id = read_unicode_string(fp)
        if version >= 6:
            mod_time = read_fmt('d', fp)[0]
        if version >= 7:
            lock_state = read_fmt('B', fp)[0]
        if kind == LinkedLayerType.EXTERNAL and version == 2:
            data = fp.read(datasize)

        return cls(kind, version, uuid, filename, filetype, creator, filesize,
                   open_file, linked_file, timestamp, data, child_id, mod_time,
                   lock_state)
Exemple #3
0
 def read(cls, fp, **kwargs):
     version = read_fmt('H', fp)[0]
     transform = read_fmt('6d', fp)
     text_version = read_fmt('H', fp)[0]
     text_data = DescriptorBlock.read(fp)
     # Engine data.
     if b'EngineData' in text_data:
         try:
             engine_data = text_data[b'EngineData'].value
             engine_data = EngineData.frombytes(engine_data)
             text_data[b'EngineData'].value = engine_data
         except:
             logger.warning('Failed to read engine data')
     warp_version = read_fmt('H', fp)[0]
     warp = DescriptorBlock.read(fp)
     left, top, right, bottom = read_fmt("4i", fp)
     return cls(version, transform, text_version, text_data, warp_version,
                warp, left, top, right, bottom)
Exemple #4
0
 def read(cls, fp, **kwargs):
     kind, version = read_fmt('4sI', fp)
     data = DescriptorBlock.read(fp)
     return cls(kind, version, data)
Exemple #5
0
 def read(cls, fp, **kwargs):
     version = read_fmt('I', fp)[0]
     assert version in (6, 7, 8), 'Invalid version %d' % (version)
     if version == 6:
         return cls(version=version, data=SlicesV6.read(fp))
     return cls(version=version, data=DescriptorBlock.read(fp))