# Path: resources/lib/kindleunpack/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: resources/lib/kindleunpack/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


from .compatibility_utils import unicode_str
from .unipath import pathof
import os
import imghdr
import struct
            height = self.height
            viewBox = "0 0 {0:d} {1:d}".format(width, height)

            data = ''
            data += '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html>'
            data += '<html xmlns="http://www.w3.org/1999/xhtml"'
            data += ' xml:lang="{:s}">\n'.format(lang)
            data += '<head>\n  <title>{:s}</title>\n'.format(title)
            data += '<style type="text/css">\n'
            data += 'svg {padding: 0pt; margin:0pt}\n'
            data += 'body { text-align: center; padding:0pt; margin: 0pt; }\n'
            data += '</style>\n</head>\n'
            data += '<body>\n  <div>\n'
            data += '    <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet"'
            data += ' version="1.1" viewBox="{0:s}" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">\n'.format(viewBox)
            data += '      <image height="{0}" width="{1}" xlink:href="{2}"/>\n'.format(height, width, image_path)
            data += '    </svg>\n'
            data += '  </div>\n</body>\n</html>'
        return data

    def writeXHTML(self):
        files = self.files
        cover_page = self.cover_page

        data = self.buildXHTML()

        outfile = os.path.join(files.k8text, cover_page)
        if os.path.exists(pathof(outfile)):
            print('Warning: {:s} already exists.'.format(cover_page))
            os.remove(pathof(outfile))

# Path: resources/lib/kindleunpack/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: resources/lib/kindleunpack/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: resources/lib/kindleunpack/mobi_cover.py
from .compatibility_utils import unicode_str
from .unipath import pathof
import os
import imghdr
import struct

            height = self.height
            viewBox = "0 0 {0:d} {1:d}".format(width, height)

            data = ''
            data += '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html>'
            data += '<html xmlns="http://www.w3.org/1999/xhtml"'
            data += ' xml:lang="{:s}">\n'.format(lang)
            data += '<head>\n  <title>{:s}</title>\n'.format(title)
            data += '<style type="text/css">\n'
            data += 'svg {padding: 0pt; margin:0pt}\n'
            data += 'body { text-align: center; padding:0pt; margin: 0pt; }\n'
            data += '</style>\n</head>\n'
            data += '<body>\n  <div>\n'
            data += '    <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet"'
            data += ' version="1.1" viewBox="{0:s}" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">\n'.format(viewBox)
            data += '      <image height="{0}" width="{1}" xlink:href="{2}"/>\n'.format(height, width, image_path)
            data += '    </svg>\n'
            data += '  </div>\n</body>\n</html>'
        return data

    def writeXHTML(self):
        files = self.files
        cover_page = self.cover_page

        data = self.buildXHTML()

        outfile = os.path.join(files.k8text, cover_page)
        if os.path.exists(pathof(outfile)):
            print('Warning: {:s} already exists.'.format(cover_page))
            os.remove(pathof(outfile))

        with open(pathof(outfile), 'wb') as f: