Exemplo n.º 1
0
class InternationalText(bin.Structure, encoding='utf8'):
    keyword = bin.String()
    is_compressed = bin.Integer(size=1)
    compression = bin.Integer(size=1, choices=COMPRESSION_CHOICES)
    language = bin.String()
    translated_keyword = bin.String()
    content = bin.Bytes(size=bin.Remainder)  # TODO: decompress
Exemplo n.º 2
0
class _669(bin.File):
    marker = bin.FixedString('if')
    message = bin.List(bin.String(size=36, encoding='ascii', padding=' '), size=3)
    sample_count = bin.PositiveInteger(size=1, max_value=64)
    pattern_count = bin.PositiveInteger(size=1, max_value=128)
    restart_position = bin.PositiveInteger(size=1)
    pattern_order = bin.List(bin.PositiveInteger(size=1, max_value=128), size=128)
    pattern_tempos = bin.List(bin.PositiveInteger(size=1), size=128)
    pattern_breaks = bin.List(bin.PositiveInteger(size=1), size=128)
    samples = bin.List(Sample, size=sample_count)
    patterns = bin.List(Pattern, size=pattern_count)
    sample_data = bin.ByteString(size=bin.REMAINDER)
    
    @sample_data.getter
    def sample_data(self, data):
        offset = 0
        output = []
        for info in self.samples:
            output.append(data[offset:offset + info.size])
            offset += info.size
        return output
    
    @sample_data.setter
    def sample_data(self, data_list):
        return ''.join(data_list)
    
    def __iter__(self):
        for index in self.pattern_order:
            yield self.patterns[index]
    
    def __unicode__(self):
        return self.message[0]
    
    class Options:
        endianness = bin.LittleEndian
Exemplo n.º 3
0
class GIF(bin.Structure, endianness=bin.LittleEndian, encoding='ascii'):
    tag = bin.FixedString('GIF')
    version = bin.String(size=3, choices=VERSIONS)

    #    with tag == 'GIF':
    #        version = bin.String(size=3, choices=VERSIONS)

    screen = bin.SubStructure(ScreenDescriptor)

    @property
    def width(self):
        return self.screen.width

    @property
    def height(self):
        return self.screen.height
Exemplo n.º 4
0
class Chunk(bin.Chunk, encoding='ascii'):
    """
    A special chunk for PNG, which puts the size before the type
    and includes a CRC field for verifying data integrity.
    """
    size = bin.Integer(size=4)
    id = bin.String(size=4)
    payload = bin.Payload(size=size)
    crc = bin.CRC32(first=id)

    @property
    def is_critical(self):
        # Critical chunks will always have an uppercase letter for the
        # first character in the type. Ancillary will always be lower.
        return self.type[0].upper() == self.type[0]

    @property
    def is_public(self):
        # Public chunks will always have an uppercase letter for the
        # second character in the type. Private will always be lower.
        return self.type[1].upper() == self.type[1]
Exemplo n.º 5
0
class Chunk(bin.Chunk):
    id = bin.String(size=4, encoding='ascii')
    size = bin.Integer(size=4)
    payload = bin.Payload(size=size)
Exemplo n.º 6
0
class Form(bin.Chunk, encoding='ascii'):
    tag = bin.FixedString('FORM')
    size = bin.Integer(size=4)
    id = bin.String(size=4)
    payload = bin.Payload(size=size)
Exemplo n.º 7
0
class Comment(bin.Structure):
    value = bin.String(encoding='utf8', size=bin.Remainder)

    def __str__(self):
        return self.value
Exemplo n.º 8
0
 class TestStructure(bin.Structure):
     integer = bin.Integer('number', size=1)
     string = bin.String(encoding='ascii')
Exemplo n.º 9
0
 class TestStructure(bin.Structure):
     forty_two = bin.Integer(size=2, endianness=bin.LittleEndian)
     sixty_six = bin.Integer(size=1)
     valid = bin.String(encoding='ascii')
     test = bin.String(encoding='ascii')
Exemplo n.º 10
0
 class TestStructure(bin.Structure):
     length = bin.Integer('number', size=1)
     content = bin.String(encoding='ascii', size=length)
Exemplo n.º 11
0
class ICCProfile(bin.Structure):
    name = bin.String(encoding='latin-1')
    compression = bin.Integer(size=1, choices=COMPRESSION_CHOICES)
    profile = bin.Bytes(size=bin.Remainder)  # TODO: decompress
Exemplo n.º 12
0
class CompressedText(bin.Structure, encoding='latin-1'):
    keyword = bin.String()
    compression = bin.Integer(size=1, choices=COMPRESSION_CHOICES)
    content = bin.Bytes(size=bin.Remainder)  # TODO: decompress
Exemplo n.º 13
0
class Text(bin.Structure, encoding='latin-1'):
    keyword = bin.String()
    content = bin.String(size=bin.Remainder)
Exemplo n.º 14
0
class SuggestedPalette(bin.Structure):
    name = bin.String(encoding='latin-1')
    sample_depth = bin.Integer(size=1)
    colors = bin.List(bin.SubStructure(SuggestedPaletteEntry), size=bin.Remainder)
Exemplo n.º 15
0
class GIF(bin.Structure, endianness=bin.LittleEndian, encoding='ascii'):
    tag = bin.FixedString('GIF')
    version = bin.String(size=3, choices=GIF_VERSIONS)
    width = bin.Integer(size=2)
    height = bin.Integer(size=2)