# Path: modules/compatibility_utils.py
# def unicode_str(p, enc='utf-8'):
#     if p is None:
#         return None
#     if isinstance(p, text_type):
#         return p
#     return p.decode(enc)


from .compatibility_utils import unicode_str
import struct
import re
    for m in re.finditer(_tup_pattern, data):
        tup = m.group(1)
        if pageMap != '':
            pageMap += ','
        pageMap += '(' + tup + ')'
        spos, nametype, svalue = tup.split(",")
        # print(spos, nametype, svalue)
        if nametype == 'a' or nametype == 'r':
            svalue = int(svalue)
        spos = int(spos)
        for i in range(spos - 1, numpages):
            if nametype == 'r':
                pname = int_to_roman(svalue)
                svalue += 1
            elif nametype == 'a':
                pname = "%s" % svalue
                svalue += 1
            elif nametype == 'c':
                sp = svalue.find('|')
                if sp == -1:
                    pname = svalue
                else:
                    pname = svalue[0:sp]
                    svalue = svalue[sp+1:]
            else:
                log.warning("Error: unknown page numbering type: {0}".format(nametype))
            pagenames[i] = pname
    return pagenames, pageMap



# Path: modules/compatibility_utils.py
# def unicode_str(p, enc='utf-8'):
#     if p is None:
#         return None
#     if isinstance(p, text_type):
#         return p
#     return p.decode(enc)


# Path: modules/mobi_pagemap.py
from .compatibility_utils import unicode_str
import struct
import re

    for m in re.finditer(_tup_pattern, data):
        tup = m.group(1)
        if pageMap != '':
            pageMap += ','
        pageMap += '(' + tup + ')'
        spos, nametype, svalue = tup.split(",")
        # print(spos, nametype, svalue)
        if nametype == 'a' or nametype == 'r':
            svalue = int(svalue)
        spos = int(spos)
        for i in range(spos - 1, numpages):
            if nametype == 'r':
                pname = int_to_roman(svalue)
                svalue += 1
            elif nametype == 'a':
                pname = "%s" % svalue
                svalue += 1
            elif nametype == 'c':
                sp = svalue.find('|')
                if sp == -1:
                    pname = svalue
                else:
                    pname = svalue[0:sp]
                    svalue = svalue[sp+1:]
            else:
                log.warning("Error: unknown page numbering type: {0}".format(nametype))
            pagenames[i] = pname
    return pagenames, pageMap



class PageMapProcessor: