Exemplo n.º 1
0
    def _repr_pretty_(self, p, cycle):
        if cycle:
            p.text(repr(self))
        else:
            blend_mode = self.blend_mode
            if blend_mode is not None:
                blend_mode = BlendMode.name_of(blend_mode)

            sub_type = self.sub_type
            if sub_type is not None:
                sub_type = SectionDividerSub.name_of(sub_type)

            p.begin_group(2, "Divider(")
            p.begin_group(0)

            p.break_()
            p.text("type = %s," % SectionDivider.name_of(self.type))
            p.break_()
            p.text("blend_mode = %s," % blend_mode)
            p.break_()
            p.text("sub_type = %s" % sub_type)

            p.end_group(2)
            p.break_()
            p.end_group(0, ")")
Exemplo n.º 2
0
def _decode_section_divider(data):
    data_length = len(data)
    blend_mode = None
    sub_type = None

    fp = io.BytesIO(data)
    tp = read_fmt("I", fp)[0]
    if not SectionDivider.is_known(tp):
        warnings.warn("Unknown section divider type (%s)" % tp)

    if data_length >= 12:
        sig = fp.read(4)
        if sig != b"8BIM":
            raise Error("Invalid signature in section divider block (%r)" % sig)

        blend_mode = fp.read(4)
        if not BlendMode.is_known(blend_mode):
            warnings.warn("Unknown section divider blend mode (%s)" % blend_mode)

        if data_length >= 16:
            sub_type = read_fmt("I", fp)[0]
            if not SectionDividerSub.is_known(sub_type):
                warnings.warn("Unknown section divider sub-type (%s)" % sub_type)

    return Divider(tp, blend_mode, sub_type)
Exemplo n.º 3
0
 def read(cls, fp, **kwargs):
     kind = SectionDivider(read_fmt('I', fp)[0])
     signature, key = None, None
     if is_readable(fp, 8):
         signature = read_fmt('4s', fp)[0]
         assert signature == b'8BIM', 'Invalid signature %r' % signature
         key = BlendMode(read_fmt('4s', fp)[0])
     sub_type = None
     if is_readable(fp, 4):
         sub_type = read_fmt('I', fp)[0]
     return cls(kind, signature=signature, key=key, sub_type=sub_type)
Exemplo n.º 4
0
    def __repr__(self):
        blend_mode = self.blend_mode
        if blend_mode is not None:
            blend_mode = BlendMode.name_of(blend_mode)

        sub_type = self.sub_type
        if sub_type is not None:
            sub_type = SectionDividerSub.name_of(sub_type)

        return "Divider(type=%s, blend_mode=%s, sub_type=%s)" % (
            SectionDivider.name_of(self.type),
            blend_mode,
            sub_type,
        )
Exemplo n.º 5
0
def _decode_divider(data):
    fp = io.BytesIO(data)
    key = None
    tp = read_fmt("I", fp)[0]
    if not SectionDivider.is_known(tp):
        warnings.warn("Unknown section divider type (%s)" % tp)

    if len(data) == 12:
        sig = fp.read(4)
        if sig != b'8BIM':
            warnings.warn("Invalid signature in section divider block")
        key = fp.read(4)

    return tp, key
Exemplo n.º 6
0
def _decode_divider(data):
    fp = io.BytesIO(data)
    key = None
    tp = read_fmt("I", fp)[0]
    if not SectionDivider.is_known(tp):
        warnings.warn("Unknown section divider type (%s)" % tp)

    if len(data) == 12:
        sig = fp.read(4)
        if sig != b'8BIM':
            warnings.warn("Invalid signature in section divider block")
        key = fp.read(4)

    return tp, key
Exemplo n.º 7
0
 def __repr__(self):
     return "Divider(%s %r %s, %s)" % (
         self.block, self.type, SectionDivider.name_of(self.type), self.key)
Exemplo n.º 8
0
 def __repr__(self):
     return "Divider(%s %r %s, %s)" % (
         self.block, self.type, SectionDivider.name_of(self.type), self.key)