mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-07 13:33:33 +02:00
Moved misc functions from polyglot package to single polyglot module.
This commit is contained in:
@@ -5,17 +5,12 @@ import os
|
||||
from lxml import html
|
||||
from lxml.html import builder
|
||||
|
||||
from ebook_converter.polyglot.urllib import unquote as _unquote
|
||||
from ebook_converter.ebooks.oeb.base import urlquote
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.constants_old import filesystem_encoding
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = ('2008, Kovid Goyal <kovid at kovidgoyal.net>, '
|
||||
'and Alex Bramley <a.bramley at gmail.com>.')
|
||||
from ebook_converter import polyglot
|
||||
|
||||
|
||||
class CHMInput(InputFormatPlugin):
|
||||
@@ -133,7 +128,7 @@ class CHMInput(InputFormatPlugin):
|
||||
def unquote(x):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('utf-8')
|
||||
return _unquote(x).decode('utf-8')
|
||||
return polyglot.unquote(x).decode('utf-8')
|
||||
|
||||
def unquote_path(x):
|
||||
y = unquote(x)
|
||||
@@ -175,7 +170,7 @@ class CHMInput(InputFormatPlugin):
|
||||
pretty_print=True)
|
||||
f.write(raw)
|
||||
else:
|
||||
f.write(as_bytes(hhcdata))
|
||||
f.write(polyglot.as_bytes(hhcdata))
|
||||
return htmlpath, toc
|
||||
|
||||
def _read_file(self, name):
|
||||
|
||||
@@ -9,7 +9,7 @@ from ebook_converter.ebooks.oeb import parse_utils
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin
|
||||
from ebook_converter.customize.conversion import OptionRecommendation
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
from ebook_converter import polyglot
|
||||
from ebook_converter.utils import directory
|
||||
|
||||
|
||||
@@ -266,7 +266,8 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
extra_entries=extra_entries) as epub:
|
||||
epub.add_dir(tdir)
|
||||
if encryption is not None:
|
||||
epub.writestr('META-INF/encryption.xml', as_bytes(encryption))
|
||||
epub.writestr('META-INF/encryption.xml',
|
||||
polyglot.as_bytes(encryption))
|
||||
if metadata_xml is not None:
|
||||
epub.writestr('META-INF/metadata.xml',
|
||||
metadata_xml.encode('utf-8'))
|
||||
@@ -308,12 +309,10 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
pass
|
||||
|
||||
def encrypt_fonts(self, uris, tdir, _uuid): # {{{
|
||||
from ebook_converter.polyglot.binary import from_hex_bytes
|
||||
|
||||
key = re.sub(r'[^a-fA-F0-9]', '', _uuid)
|
||||
if len(key) < 16:
|
||||
raise ValueError('UUID identifier %r is invalid'% _uuid)
|
||||
key = bytearray(from_hex_bytes((key + key)[:32]))
|
||||
key = bytearray(polyglot.from_hex_bytes((key + key)[:32]))
|
||||
paths = []
|
||||
with directory.CurrentDir(tdir):
|
||||
paths = [os.path.join(*x.split('/')) for x in uris]
|
||||
|
||||
@@ -7,7 +7,7 @@ from lxml import etree
|
||||
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter.ebooks.oeb.base import element
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter import polyglot
|
||||
from ebook_converter.ptempfile import PersistentTemporaryDirectory
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils import directory
|
||||
@@ -56,7 +56,8 @@ class HTMLOutput(OutputFormatPlugin):
|
||||
parent = element(parent, ('ul'))
|
||||
for node in current_node.nodes:
|
||||
point = element(parent, 'li')
|
||||
href = relpath(os.path.abspath(unquote(node.href)),
|
||||
href = relpath(os.path.abspath(polyglot
|
||||
.unquote(node.href)),
|
||||
os.path.dirname(ref_url))
|
||||
if isinstance(href, bytes):
|
||||
href = href.decode('utf-8')
|
||||
@@ -84,7 +85,6 @@ class HTMLOutput(OutputFormatPlugin):
|
||||
from lxml import etree
|
||||
from ebook_converter.utils import zipfile
|
||||
from templite import Templite
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter.ebooks.html.meta import EasyMeta
|
||||
|
||||
# read template files
|
||||
@@ -156,7 +156,7 @@ class HTMLOutput(OutputFormatPlugin):
|
||||
|
||||
with directory.CurrentDir(output_dir):
|
||||
for item in oeb_book.manifest:
|
||||
path = os.path.abspath(unquote(item.href))
|
||||
path = os.path.abspath(polyglot.unquote(item.href))
|
||||
dir = os.path.dirname(path)
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
@@ -169,7 +169,7 @@ class HTMLOutput(OutputFormatPlugin):
|
||||
item.unload_data_from_memory(memory=path)
|
||||
|
||||
for item in oeb_book.spine:
|
||||
path = os.path.abspath(unquote(item.href))
|
||||
path = os.path.abspath(polyglot.unquote(item.href))
|
||||
dir = os.path.dirname(path)
|
||||
root = item.data.getroottree()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from lxml import etree
|
||||
|
||||
from ebook_converter.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter import polyglot
|
||||
from ebook_converter.ebooks.oeb.base import OPF_MIME, NCX_MIME, PAGE_MAP_MIME, OEB_STYLES
|
||||
from ebook_converter.ebooks.oeb.normalize_css import condense_sheet
|
||||
from ebook_converter.utils import directory
|
||||
@@ -56,7 +56,7 @@ class OEBOutput(OutputFormatPlugin):
|
||||
not self.opts.expand_css and item.media_type in OEB_STYLES and hasattr(
|
||||
item.data, 'cssText') and 'nook' not in self.opts.output_profile.short_name):
|
||||
condense_sheet(item.data)
|
||||
path = os.path.abspath(unquote(item.href))
|
||||
path = os.path.abspath(polyglot.unquote(item.href))
|
||||
dir = os.path.dirname(path)
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import os
|
||||
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
from ebook_converter import polyglot
|
||||
|
||||
|
||||
class PDFInput(InputFormatPlugin):
|
||||
@@ -72,7 +67,8 @@ class PDFInput(InputFormatPlugin):
|
||||
ncxid = opf.manifest.id_for_path('toc.ncx')
|
||||
if ncxid:
|
||||
with open('metadata.opf', 'r+b') as f:
|
||||
raw = f.read().replace(b'<spine', b'<spine toc="%s"' % as_bytes(ncxid))
|
||||
raw = f.read().replace(b'<spine', b'<spine toc="%s"' %
|
||||
polyglot.as_bytes(ncxid))
|
||||
f.seek(0)
|
||||
f.write(raw)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from lxml import etree
|
||||
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||
from ebook_converter.customize.conversion import OptionRecommendation
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
from ebook_converter import polyglot
|
||||
|
||||
|
||||
border_style_map = {'single': 'solid',
|
||||
@@ -296,7 +296,7 @@ class RTFInput(InputFormatPlugin):
|
||||
result = transform(doc)
|
||||
html = u'index.xhtml'
|
||||
with open(html, 'wb') as f:
|
||||
res = as_bytes(transform.tostring(result))
|
||||
res = polyglot.as_bytes(transform.tostring(result))
|
||||
# res = res[:100].replace('xmlns:html', 'xmlns') + res[100:]
|
||||
# clean multiple \n
|
||||
res = re.sub(b'\n+', b'\n', res)
|
||||
|
||||
Reference in New Issue
Block a user