# Path: modules/unipath.py
# def pathof(s, enc=fsencoding):
#     if s is None:
#         return None
#     if isinstance(s, text_type):
#         return s
#     if isinstance(s, binary_type):
#         try:
#             return s.decode(enc)
#         except:
#             pass
#     return s


import struct
import string
import re
from PIL import Image
from io import BytesIO
from .unipath import pathof
                   struct.pack(b'>L', enum) + rec0[ebase + 12:ebase_idx + 4] + \
                   struct.pack(b'>L', len(exth_bytes) + 8) + exth_bytes + \
                   rec0[ebase_idx + getint(rec0, ebase_idx + 4):]
        enum_idx = enum_idx - 1
        ebase_idx = ebase_idx + getint(rec0, ebase_idx + 4)
    return rec0


def del_exth(rec0, exth_num):
    ebase, elen, enum = get_exth_params(rec0)
    ebase_idx = ebase + 12
    enum_idx = 0
    while enum_idx < enum:
        exth_id = getint(rec0, ebase_idx)
        exth_size = getint(rec0, ebase_idx + 4)
        if exth_id == exth_num:
            newrec0 = rec0
            newrec0 = writeint(newrec0, title_offset, getint(newrec0, title_offset) - exth_size)
            newrec0 = newrec0[:ebase_idx] + newrec0[ebase_idx + exth_size:]
            newrec0 = newrec0[0:ebase + 4] + struct.pack(b'>L', elen - exth_size) + struct.pack(b'>L', enum - 1) + newrec0[ebase + 12:]
            return newrec0
        enum_idx += 1
        ebase_idx = ebase_idx + exth_size
    return rec0


class mobi_split:
    def __init__(self, infile, document_id, remove_personal_label, format):
        if format == 'mobi':
            datain = b''

# Path: modules/unipath.py
# def pathof(s, enc=fsencoding):
#     if s is None:
#         return None
#     if isinstance(s, text_type):
#         return s
#     if isinstance(s, binary_type):
#         try:
#             return s.decode(enc)
#         except:
#             pass
#     return s


# Path: modules/mobi_split.py
import struct
import string
import re
from PIL import Image
from io import BytesIO
from .unipath import pathof

                   struct.pack(b'>L', enum) + rec0[ebase + 12:ebase_idx + 4] + \
                   struct.pack(b'>L', len(exth_bytes) + 8) + exth_bytes + \
                   rec0[ebase_idx + getint(rec0, ebase_idx + 4):]
        enum_idx = enum_idx - 1
        ebase_idx = ebase_idx + getint(rec0, ebase_idx + 4)
    return rec0


def del_exth(rec0, exth_num):
    ebase, elen, enum = get_exth_params(rec0)
    ebase_idx = ebase + 12
    enum_idx = 0
    while enum_idx < enum:
        exth_id = getint(rec0, ebase_idx)
        exth_size = getint(rec0, ebase_idx + 4)
        if exth_id == exth_num:
            newrec0 = rec0
            newrec0 = writeint(newrec0, title_offset, getint(newrec0, title_offset) - exth_size)
            newrec0 = newrec0[:ebase_idx] + newrec0[ebase_idx + exth_size:]
            newrec0 = newrec0[0:ebase + 4] + struct.pack(b'>L', elen - exth_size) + struct.pack(b'>L', enum - 1) + newrec0[ebase + 12:]
            return newrec0
        enum_idx += 1
        ebase_idx = ebase_idx + exth_size
    return rec0


class mobi_split:
    def __init__(self, infile, document_id, remove_personal_label, format):
        if format == 'mobi':
            datain = b''

            with open(pathof(infile), 'rb') as f: