# Path: resources/lib/kindleunpack/compatibility_utils.py
# PY2 = sys.version_info[0] == 2
# 
# def bchr(s):
#     return bytes([s])
# 
# def lmap(*args, **kwargs):
#     return list(map(*args, **kwargs))
# 
# def bstr(s):
#     if isinstance(s, str):
#         return bytes(s, 'latin-1')
#     else:
#         return bytes(s)


from .compatibility_utils import PY2, bchr, lmap, bstr
import struct
                o += i[p:p+c]
                p += c
            elif (c < 128):
                o += bchr(c)
            elif (c >= 192):
                o += b' ' + bchr(c ^ 128)
            else:
                if p < len(i):
                    c = (c << 8) | ord(i[p:p+1])
                    p += 1
                    m = (c >> 3) & 0x07ff
                    n = (c & 7) + 3
                    if (m > n):
                        o += o[-m:n-m]
                    else:
                        for _ in range(n):
                            # because of completely ass-backwards decision by python mainters for python 3
                            # we must use slice for bytes as i[p] returns int while slice returns character
                            if m == 1:
                                o += o[-m:]
                            else:
                                o += o[-m:-m+1]
        return o

class HuffcdicReader:
    q = struct.Struct(b'>Q').unpack_from

    def loadHuff(self, huff):
        if huff[0:8] != b'HUFF\x00\x00\x00\x18':
            raise unpackException('invalid huff header')

# Path: resources/lib/kindleunpack/compatibility_utils.py
# PY2 = sys.version_info[0] == 2
# 
# def bchr(s):
#     return bytes([s])
# 
# def lmap(*args, **kwargs):
#     return list(map(*args, **kwargs))
# 
# def bstr(s):
#     if isinstance(s, str):
#         return bytes(s, 'latin-1')
#     else:
#         return bytes(s)


# Path: resources/lib/kindleunpack/mobi_uncompress.py
from .compatibility_utils import PY2, bchr, lmap, bstr
import struct

                o += i[p:p+c]
                p += c
            elif (c < 128):
                o += bchr(c)
            elif (c >= 192):
                o += b' ' + bchr(c ^ 128)
            else:
                if p < len(i):
                    c = (c << 8) | ord(i[p:p+1])
                    p += 1
                    m = (c >> 3) & 0x07ff
                    n = (c & 7) + 3
                    if (m > n):
                        o += o[-m:n-m]
                    else:
                        for _ in range(n):
                            # because of completely ass-backwards decision by python mainters for python 3
                            # we must use slice for bytes as i[p] returns int while slice returns character
                            if m == 1:
                                o += o[-m:]
                            else:
                                o += o[-m:-m+1]
        return o

class HuffcdicReader:
    q = struct.Struct(b'>Q').unpack_from

    def loadHuff(self, huff):
        if huff[0:8] != b'HUFF\x00\x00\x00\x18':
            raise unpackException('invalid huff header')

        off1, off2 = struct.unpack_from(b'>LL', huff, 8)