mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-22 18:33:34 +01:00
Convert calibre modules to ebook_converter.
Here is the first batch of modules, which are needed for converting several formats to LRF. Some of the logic has been change, more cleanups will follow.
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||
|
||||
@@ -13,19 +13,18 @@ from itertools import count
|
||||
from operator import attrgetter
|
||||
|
||||
from lxml import etree, html
|
||||
from calibre import force_unicode
|
||||
from calibre.constants import filesystem_encoding, __version__, ispy3
|
||||
from calibre.translations.dynamic import translate
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.ebooks.conversion.preprocess import CSSPreProcessor
|
||||
from calibre import (isbytestring, as_unicode, get_types_map)
|
||||
from calibre.ebooks.oeb.parse_utils import barename, XHTML_NS, namespace, XHTML, parse_html, NotHTML
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from calibre.utils.short_uuid import uuid4
|
||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, range, itervalues, filter, codepoint_to_chr
|
||||
from polyglot.urllib import unquote as urlunquote, urldefrag, urljoin, urlparse, urlunparse
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
from ebook_converter import force_unicode
|
||||
from ebook_converter.constants import filesystem_encoding, __version__, ispy3
|
||||
from ebook_converter.translations.dynamic import translate
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.ebooks.conversion.preprocess import CSSPreProcessor
|
||||
from ebook_converter import (isbytestring, as_unicode, get_types_map)
|
||||
from ebook_converter.ebooks.oeb.parse_utils import barename, XHTML_NS, namespace, XHTML, parse_html, NotHTML
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.short_uuid import uuid4
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes, range, itervalues, filter, codepoint_to_chr
|
||||
from ebook_converter.polyglot.urllib import unquote as urlunquote, urldefrag, urljoin, urlparse, urlunparse
|
||||
|
||||
XML_NS = 'http://www.w3.org/XML/1998/namespace'
|
||||
OEB_DOC_NS = 'http://openebook.org/namespaces/oeb-document/1.0/'
|
||||
@@ -971,7 +970,7 @@ class Manifest(object):
|
||||
|
||||
self.oeb.log.debug('Converting', self.href, '...')
|
||||
|
||||
from calibre.ebooks.txt.processor import convert_markdown
|
||||
from ebook_converter.ebooks.txt.processor import convert_markdown
|
||||
|
||||
title = self.oeb.metadata.title
|
||||
if title:
|
||||
@@ -1064,7 +1063,7 @@ class Manifest(object):
|
||||
def unload_data_from_memory(self, memory=None):
|
||||
if isinstance(self._data, bytes):
|
||||
if memory is None:
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from ebook_converter.ptempfile import PersistentTemporaryFile
|
||||
pt = PersistentTemporaryFile(suffix='_oeb_base_mem_unloader.img')
|
||||
with pt:
|
||||
pt.write(self._data)
|
||||
@@ -1124,7 +1123,8 @@ class Manifest(object):
|
||||
if isinstance(href, bytes):
|
||||
href = force_unicode(href)
|
||||
sp = self.spine_position if isinstance(self.spine_position, numbers.Number) else sys.maxsize
|
||||
return sp, (self.media_type or '').lower(), numeric_sort_key(href), self.id
|
||||
|
||||
return sp, (self.media_type or '').lower(), href, self.id
|
||||
|
||||
def relhref(self, href):
|
||||
"""Convert the URL provided in :param:`href` from a book-absolute
|
||||
|
||||
@@ -10,9 +10,9 @@ from functools import wraps
|
||||
|
||||
from css_parser.css import PropertyValue
|
||||
from css_parser import profile as cssprofiles, CSSParser
|
||||
from tinycss.fonts3 import parse_font, serialize_font_family
|
||||
from calibre.ebooks.oeb.base import css_text
|
||||
from polyglot.builtins import iteritems, string_or_bytes, unicode_type, zip
|
||||
from ebook_converter.tinycss.fonts3 import parse_font, serialize_font_family
|
||||
from ebook_converter.ebooks.oeb.base import css_text
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, unicode_type, zip
|
||||
|
||||
DEFAULTS = {'azimuth': 'center', 'background-attachment': 'scroll', # {{{
|
||||
'background-color': 'transparent', 'background-image': 'none',
|
||||
|
||||
@@ -10,11 +10,11 @@ import re
|
||||
|
||||
from lxml import etree, html
|
||||
|
||||
from calibre import xml_replace_entities, force_unicode
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes, map
|
||||
from ebook_converter import xml_replace_entities, force_unicode
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes, map
|
||||
|
||||
RECOVER_PARSER = etree.XMLParser(recover=True, no_network=True, resolve_entities=False)
|
||||
XHTML_NS = 'http://www.w3.org/1999/xhtml'
|
||||
@@ -94,7 +94,7 @@ def node_depth(node):
|
||||
|
||||
def html5_parse(data, max_nesting_depth=100):
|
||||
from html5_parser import parse
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
data = parse(clean_xml_chars(data), maybe_xhtml=True, keep_doctype=False, sanitize_names=True)
|
||||
# Check that the asinine HTML 5 algorithm did not result in a tree with
|
||||
# insane nesting depths
|
||||
@@ -160,7 +160,7 @@ def check_for_html5(prefix, root):
|
||||
def parse_html(data, log=None, decoder=None, preprocessor=None,
|
||||
filename='<string>', non_html_file_tags=frozenset()):
|
||||
if log is None:
|
||||
from calibre.utils.logging import default_log
|
||||
from ebook_converter.utils.logging import default_log
|
||||
log = default_log
|
||||
|
||||
filename = force_unicode(filename, enc=filesystem_encoding)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,42 +19,42 @@ from itertools import count
|
||||
|
||||
from css_parser import getUrls, replaceUrls
|
||||
|
||||
from calibre import CurrentDir, walk
|
||||
from calibre.constants import iswindows
|
||||
from calibre.customize.ui import plugin_for_input_format, plugin_for_output_format
|
||||
from calibre.ebooks import escape_xpath_attr
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.ebooks.conversion.plugins.epub_input import (
|
||||
from ebook_converter import CurrentDir, walk
|
||||
from ebook_converter.constants import iswindows
|
||||
from ebook_converter.customize.ui import plugin_for_input_format, plugin_for_output_format
|
||||
from ebook_converter.ebooks import escape_xpath_attr
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.ebooks.conversion.plugins.epub_input import (
|
||||
ADOBE_OBFUSCATION, IDPF_OBFUSCATION, decrypt_font_data
|
||||
)
|
||||
from calibre.ebooks.conversion.preprocess import (
|
||||
from ebook_converter.ebooks.conversion.preprocess import (
|
||||
CSSPreProcessor as cssp, HTMLPreProcessor
|
||||
)
|
||||
from calibre.ebooks.metadata.opf3 import (
|
||||
from ebook_converter.ebooks.metadata.opf3 import (
|
||||
CALIBRE_PREFIX, ensure_prefix, items_with_property, read_prefixes
|
||||
)
|
||||
from calibre.ebooks.metadata.utils import parse_opf_version
|
||||
from calibre.ebooks.mobi import MobiError
|
||||
from calibre.ebooks.mobi.reader.headers import MetadataHeader
|
||||
from calibre.ebooks.mobi.tweak import set_cover
|
||||
from calibre.ebooks.oeb.base import (
|
||||
from ebook_converter.ebooks.metadata.utils import parse_opf_version
|
||||
from ebook_converter.ebooks.mobi import MobiError
|
||||
from ebook_converter.ebooks.mobi.reader.headers import MetadataHeader
|
||||
from ebook_converter.ebooks.mobi.tweak import set_cover
|
||||
from ebook_converter.ebooks.oeb.base import (
|
||||
DC11_NS, OEB_DOCS, OEB_STYLES, OPF, OPF2_NS, Manifest, itercsslinks, iterlinks,
|
||||
rewrite_links, serialize, urlquote, urlunquote
|
||||
)
|
||||
from calibre.ebooks.oeb.parse_utils import NotHTML, parse_html
|
||||
from calibre.ebooks.oeb.polish.errors import DRMError, InvalidBook
|
||||
from calibre.ebooks.oeb.polish.parsing import parse as parse_html_tweak
|
||||
from calibre.ebooks.oeb.polish.utils import (
|
||||
from ebook_converter.ebooks.oeb.parse_utils import NotHTML, parse_html
|
||||
from ebook_converter.ebooks.oeb.polish.errors import DRMError, InvalidBook
|
||||
from ebook_converter.ebooks.oeb.polish.parsing import parse as parse_html_tweak
|
||||
from ebook_converter.ebooks.oeb.polish.utils import (
|
||||
CommentFinder, PositionFinder, guess_type, parse_css
|
||||
)
|
||||
from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile
|
||||
from calibre.utils.filenames import hardlink_file, nlinks_file
|
||||
from calibre.utils.ipc.simple_worker import WorkerError, fork_job
|
||||
from calibre.utils.logging import default_log
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
from polyglot.builtins import iteritems, map, unicode_type, zip
|
||||
from polyglot.urllib import urlparse
|
||||
from ebook_converter.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile
|
||||
from ebook_converter.utils.filenames import hardlink_file, nlinks_file
|
||||
from ebook_converter.utils.ipc.simple_worker import WorkerError, fork_job
|
||||
from ebook_converter.utils.logging import default_log
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type, zip
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
|
||||
|
||||
@@ -432,7 +432,7 @@ class Container(ContainerBase): # {{{
|
||||
if current_name == self.opf_name:
|
||||
self.opf_name = new_name
|
||||
if os.path.dirname(old_path) != os.path.dirname(new_path):
|
||||
from calibre.ebooks.oeb.polish.replace import LinkRebaser
|
||||
from ebook_converter.ebooks.oeb.polish.replace import LinkRebaser
|
||||
repl = LinkRebaser(self, current_name, new_name)
|
||||
self.replace_links(new_name, repl)
|
||||
self.dirty(new_name)
|
||||
@@ -641,7 +641,7 @@ class Container(ContainerBase): # {{{
|
||||
''' The metadata of this book as a Metadata object. Note that this
|
||||
object is constructed on the fly every time this property is requested,
|
||||
so use it sparingly. '''
|
||||
from calibre.ebooks.metadata.opf2 import OPF as O
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPF as O
|
||||
mi = self.serialize_item(self.opf_name)
|
||||
return O(BytesIO(mi), basedir=self.opf_dir, unquote_urls=False,
|
||||
populate_spine=False).to_book_metadata()
|
||||
@@ -1158,7 +1158,7 @@ class EpubContainer(Container):
|
||||
except:
|
||||
log.exception('EPUB appears to be invalid ZIP file, trying a'
|
||||
' more forgiving ZIP parser')
|
||||
from calibre.utils.localunzip import extractall
|
||||
from ebook_converter.utils.localunzip import extractall
|
||||
stream.seek(0)
|
||||
extractall(stream, path=tdir)
|
||||
try:
|
||||
@@ -1320,7 +1320,7 @@ class EpubContainer(Container):
|
||||
self.obfuscated_fonts[font] = (alg, tkey)
|
||||
|
||||
def update_modified_timestamp(self):
|
||||
from calibre.ebooks.metadata.opf3 import set_last_modified_in_opf
|
||||
from ebook_converter.ebooks.metadata.opf3 import set_last_modified_in_opf
|
||||
set_last_modified_in_opf(self.opf)
|
||||
self.dirty(self.opf_name)
|
||||
|
||||
@@ -1372,7 +1372,7 @@ class EpubContainer(Container):
|
||||
shutil.copyfileobj(src, dest)
|
||||
|
||||
else:
|
||||
from calibre.ebooks.tweak import zip_rebuilder
|
||||
from ebook_converter.ebooks.tweak import zip_rebuilder
|
||||
with lopen(join(self.root, 'mimetype'), 'wb') as f:
|
||||
et = guess_type('a.epub')
|
||||
if not isinstance(et, bytes):
|
||||
@@ -1401,8 +1401,8 @@ class InvalidMobi(InvalidBook):
|
||||
|
||||
|
||||
def do_explode(path, dest):
|
||||
from calibre.ebooks.mobi.reader.mobi6 import MobiReader
|
||||
from calibre.ebooks.mobi.reader.mobi8 import Mobi8Reader
|
||||
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
|
||||
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
|
||||
with lopen(path, 'rb') as stream:
|
||||
mr = MobiReader(stream, default_log, None, None)
|
||||
|
||||
@@ -1415,7 +1415,7 @@ def do_explode(path, dest):
|
||||
|
||||
|
||||
def opf_to_azw3(opf, outpath, container):
|
||||
from calibre.ebooks.conversion.plumber import Plumber, create_oebbook
|
||||
from ebook_converter.ebooks.conversion.plumber import Plumber, create_oebbook
|
||||
|
||||
class Item(Manifest.Item):
|
||||
|
||||
@@ -1489,7 +1489,7 @@ class AZW3Container(Container):
|
||||
|
||||
try:
|
||||
opf_path, obfuscated_fonts = fork_job(
|
||||
'calibre.ebooks.oeb.polish.container', 'do_explode',
|
||||
'ebook_converter.ebooks.oeb.polish.container', 'do_explode',
|
||||
args=(pathtoazw3, tdir), no_output=True)['result']
|
||||
except WorkerError as e:
|
||||
log(e.orig_tb)
|
||||
|
||||
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from calibre.ebooks import DRMError as _DRMError
|
||||
from ebook_converter.ebooks import DRMError as _DRMError
|
||||
|
||||
|
||||
class InvalidBook(ValueError):
|
||||
|
||||
@@ -7,8 +7,8 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from ebook_converter.ebooks.oeb.polish.container import OPF_NAMESPACES
|
||||
from ebook_converter.utils.localization import canonicalize_lang
|
||||
|
||||
|
||||
def get_book_language(container):
|
||||
|
||||
@@ -10,11 +10,11 @@ import re
|
||||
from lxml.etree import Element as LxmlElement
|
||||
import html5_parser
|
||||
|
||||
from calibre import xml_replace_entities
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from polyglot.builtins import unicode_type
|
||||
from ebook_converter import xml_replace_entities
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
XHTML_NS = 'http://www.w3.org/1999/xhtml'
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import textwrap
|
||||
from polyglot.builtins import iteritems, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, map
|
||||
|
||||
# from lxml.etree import Element
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.ebooks.oeb.base import (
|
||||
from ebook_converter import force_unicode
|
||||
from ebook_converter.ebooks.oeb.base import (
|
||||
serialize, OEB_DOCS, barename, OEB_STYLES, XPNSMAP, XHTML, SVG)
|
||||
from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES
|
||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||
from calibre.utils.icu import sort_key
|
||||
from ebook_converter.ebooks.oeb.polish.container import OPF_NAMESPACES
|
||||
from ebook_converter.ebooks.oeb.polish.utils import guess_type
|
||||
from ebook_converter.utils.icu import sort_key
|
||||
|
||||
|
||||
def isspace(x):
|
||||
|
||||
@@ -14,17 +14,17 @@ from operator import itemgetter
|
||||
from lxml import etree
|
||||
from lxml.builder import ElementMaker
|
||||
|
||||
from calibre import __version__
|
||||
from calibre.ebooks.oeb.base import (
|
||||
from ebook_converter import __version__
|
||||
from ebook_converter.ebooks.oeb.base import (
|
||||
XPath, uuid_id, xml2text, NCX, NCX_NS, XML, XHTML, XHTML_NS, serialize, EPUB_NS, XML_NS, OEB_DOCS)
|
||||
from calibre.ebooks.oeb.polish.errors import MalformedMarkup
|
||||
from calibre.ebooks.oeb.polish.utils import guess_type, extract
|
||||
from calibre.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
||||
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||
from calibre.translations.dynamic import translate
|
||||
from calibre.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
||||
from polyglot.builtins import iteritems, map, unicode_type
|
||||
from polyglot.urllib import urlparse
|
||||
from ebook_converter.ebooks.oeb.polish.errors import MalformedMarkup
|
||||
from ebook_converter.ebooks.oeb.polish.utils import guess_type, extract
|
||||
from ebook_converter.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||
from ebook_converter.translations.dynamic import translate
|
||||
from ebook_converter.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
ns = etree.FunctionNamespace('calibre_xpath_extensions')
|
||||
ns.prefix = 'calibre'
|
||||
@@ -677,7 +677,7 @@ def ensure_single_nav_of_type(root, ntype='toc'):
|
||||
|
||||
|
||||
def commit_nav_toc(container, toc, lang=None, landmarks=None, previous_nav=None):
|
||||
from calibre.ebooks.oeb.polish.pretty import pretty_xml_tree
|
||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_xml_tree
|
||||
tocname = find_existing_nav_toc(container)
|
||||
if previous_nav is not None:
|
||||
nav_name = container.href_to_name(previous_nav[0])
|
||||
|
||||
@@ -8,8 +8,8 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
import re, os
|
||||
from bisect import bisect
|
||||
|
||||
from calibre import guess_type as _guess_type, replace_entities
|
||||
from polyglot.builtins import filter
|
||||
from ebook_converter import guess_type as _guess_type, replace_entities
|
||||
from ebook_converter.polyglot.builtins import filter
|
||||
|
||||
|
||||
def guess_type(x):
|
||||
@@ -25,7 +25,7 @@ def setup_css_parser_serialization(tab_width=2):
|
||||
|
||||
|
||||
def actual_case_for_name(container, name):
|
||||
from calibre.utils.filenames import samefile
|
||||
from ebook_converter.utils.filenames import samefile
|
||||
if not container.exists(name):
|
||||
raise ValueError('Cannot get actual case for %s as it does not exist' % name)
|
||||
parts = name.split('/')
|
||||
@@ -103,7 +103,7 @@ class CommentFinder(object):
|
||||
|
||||
|
||||
def link_stylesheets(container, names, sheets, remove=False, mtype='text/css'):
|
||||
from calibre.ebooks.oeb.base import XPath, XHTML
|
||||
from ebook_converter.ebooks.oeb.base import XPath, XHTML
|
||||
changed_names = set()
|
||||
snames = set(sheets)
|
||||
lp = XPath('//h:link[@href]')
|
||||
@@ -164,7 +164,7 @@ def parse_css(data, fname='<string>', is_declaration=False, decode=None, log_lev
|
||||
import logging
|
||||
log_level = logging.WARNING
|
||||
from css_parser import CSSParser, log
|
||||
from calibre.ebooks.oeb.base import _css_logger
|
||||
from ebook_converter.ebooks.oeb.base import _css_logger
|
||||
log.setLevel(log_level)
|
||||
log.raiseExceptions = False
|
||||
data = data or ''
|
||||
|
||||
@@ -11,24 +11,24 @@ from collections import defaultdict
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre.ebooks.oeb.base import OPF1_NS, OPF2_NS, OPF2_NSMAP, DC11_NS, \
|
||||
from ebook_converter.ebooks.oeb.base import OPF1_NS, OPF2_NS, OPF2_NSMAP, DC11_NS, \
|
||||
DC_NSES, OPF, xml2text, XHTML_MIME
|
||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, OEB_IMAGES, \
|
||||
from ebook_converter.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, OEB_IMAGES, \
|
||||
PAGE_MAP_MIME, JPEG_MIME, NCX_MIME, SVG_MIME
|
||||
from calibre.ebooks.oeb.base import XMLDECL_RE, COLLAPSE_RE, \
|
||||
from ebook_converter.ebooks.oeb.base import XMLDECL_RE, COLLAPSE_RE, \
|
||||
MS_COVER_TYPE, iterlinks
|
||||
from calibre.ebooks.oeb.base import namespace, barename, XPath, xpath, \
|
||||
from ebook_converter.ebooks.oeb.base import namespace, barename, XPath, xpath, \
|
||||
urlnormalize, BINARY_MIME, \
|
||||
OEBError, OEBBook, DirContainer
|
||||
from calibre.ebooks.oeb.writer import OEBWriter
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from calibre.utils.localization import get_lang
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
from calibre.constants import __appname__, __version__
|
||||
from calibre import guess_type, xml_replace_entities
|
||||
from polyglot.builtins import unicode_type, zip
|
||||
from polyglot.urllib import unquote, urldefrag, urlparse
|
||||
from ebook_converter.ebooks.oeb.writer import OEBWriter
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.localization import get_lang
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.constants import __appname__, __version__
|
||||
from ebook_converter import guess_type, xml_replace_entities
|
||||
from ebook_converter.polyglot.builtins import unicode_type, zip
|
||||
from ebook_converter.polyglot.urllib import unquote, urldefrag, urlparse
|
||||
|
||||
__all__ = ['OEBReader']
|
||||
|
||||
@@ -129,8 +129,8 @@ class OEBReader(object):
|
||||
return opf
|
||||
|
||||
def _metadata_from_opf(self, opf):
|
||||
from calibre.ebooks.metadata.opf2 import OPF
|
||||
from calibre.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPF
|
||||
from ebook_converter.ebooks.oeb.transforms.metadata import meta_info_to_oeb_metadata
|
||||
stream = io.BytesIO(etree.tostring(opf, xml_declaration=True, encoding='utf-8'))
|
||||
o = OPF(stream)
|
||||
pwm = o.primary_writing_mode
|
||||
@@ -621,7 +621,7 @@ class OEBReader(object):
|
||||
return
|
||||
|
||||
def _cover_from_html(self, hcover):
|
||||
from calibre.ebooks import render_html_svg_workaround
|
||||
from ebook_converter.ebooks import render_html_svg_workaround
|
||||
with TemporaryDirectory('_html_cover') as tdir:
|
||||
writer = OEBWriter()
|
||||
writer(self.oeb, tdir)
|
||||
|
||||
@@ -16,13 +16,13 @@ from css_parser.css import (CSSStyleRule, CSSPageRule, CSSFontFaceRule,
|
||||
cssproperties)
|
||||
from css_parser import (profile as cssprofiles, parseString, parseStyle, log as
|
||||
css_parser_log, CSSParser, profiles, replaceUrls)
|
||||
from calibre import force_unicode, as_unicode
|
||||
from calibre.ebooks import unit_convert
|
||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, xpath, urlnormalize
|
||||
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||
from css_selectors import Select, SelectorError, INAPPROPRIATE_PSEUDO_CLASSES
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
from tinycss.media3 import CSSMedia3Parser
|
||||
from ebook_converter import force_unicode, as_unicode
|
||||
from ebook_converter.ebooks import unit_convert
|
||||
from ebook_converter.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, xpath, urlnormalize
|
||||
from ebook_converter.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||
from ebook_converter.css_selectors import Select, SelectorError, INAPPROPRIATE_PSEUDO_CLASSES
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, filter
|
||||
from ebook_converter.tinycss.media3 import CSSMedia3Parser
|
||||
|
||||
css_parser_log.setLevel(logging.WARN)
|
||||
|
||||
@@ -194,7 +194,7 @@ class Stylizer(object):
|
||||
# Use the default profile. This should really be using
|
||||
# opts.output_profile, but I don't want to risk changing it, as
|
||||
# doing so might well have hard to debug font size effects.
|
||||
from calibre.customize.ui import output_profiles
|
||||
from ebook_converter.customize.ui import output_profiles
|
||||
for x in output_profiles():
|
||||
if x.short_name == 'default':
|
||||
self.profile = x
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
@@ -6,14 +6,14 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import re
|
||||
from calibre.ebooks.oeb.base import XPath, urlunquote
|
||||
from polyglot.builtins import as_bytes
|
||||
from ebook_converter.ebooks.oeb.base import XPath, urlunquote
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
|
||||
|
||||
class DataURL(object):
|
||||
|
||||
def __call__(self, oeb, opts):
|
||||
from calibre.utils.imghdr import what
|
||||
from ebook_converter.utils.imghdr import what
|
||||
self.log = oeb.log
|
||||
attr_path = XPath('//h:img[@src]')
|
||||
for item in oeb.spine:
|
||||
@@ -29,7 +29,7 @@ class DataURL(object):
|
||||
continue
|
||||
if ';base64' in header:
|
||||
data = re.sub(r'\s+', '', data)
|
||||
from polyglot.binary import from_base64_bytes
|
||||
from ebook_converter.polyglot.binary import from_base64_bytes
|
||||
try:
|
||||
data = from_base64_bytes(data)
|
||||
except Exception:
|
||||
@@ -46,7 +46,7 @@ class DataURL(object):
|
||||
|
||||
def convert_image_data_uri(self, data, fmt, oeb):
|
||||
self.log('Found image encoded as data URI converting it to normal image')
|
||||
from calibre import guess_type
|
||||
from ebook_converter import guess_type
|
||||
item_id, item_href = oeb.manifest.generate('data-url-image', 'data-url-image.' + fmt)
|
||||
oeb.manifest.add(item_id, item_href, guess_type(item_href)[0], data=data)
|
||||
return item_href
|
||||
|
||||
@@ -14,14 +14,14 @@ from lxml import etree
|
||||
import css_parser
|
||||
from css_parser.css import Property
|
||||
|
||||
from calibre import guess_type
|
||||
from calibre.ebooks import unit_convert
|
||||
from calibre.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYLES,
|
||||
from ebook_converter import guess_type
|
||||
from ebook_converter.ebooks import unit_convert
|
||||
from ebook_converter.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYLES,
|
||||
namespace, barename, XPath, css_text)
|
||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||
from calibre.utils.filenames import ascii_filename, ascii_text
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, map
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.utils.filenames import ascii_filename, ascii_text
|
||||
from ebook_converter.utils.icu import numeric_sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes, map
|
||||
|
||||
COLLAPSE = re.compile(r'[ \t\r\n\v]+')
|
||||
STRIPNUM = re.compile(r'[-0-9]+$')
|
||||
@@ -139,7 +139,7 @@ class CSSFlattener(object):
|
||||
self.fbase = fbase
|
||||
self.transform_css_rules = transform_css_rules
|
||||
if self.transform_css_rules:
|
||||
from calibre.ebooks.css_transform_rules import compile_rules
|
||||
from ebook_converter.ebooks.css_transform_rules import compile_rules
|
||||
self.transform_css_rules = compile_rules(self.transform_css_rules)
|
||||
self.fkey = fkey
|
||||
self.lineh = lineh
|
||||
@@ -180,7 +180,7 @@ class CSSFlattener(object):
|
||||
except:
|
||||
self.oeb.log.warning('Failed to parse filter_css, ignoring')
|
||||
else:
|
||||
from calibre.ebooks.oeb.normalize_css import normalize_filter_css
|
||||
from ebook_converter.ebooks.oeb.normalize_css import normalize_filter_css
|
||||
self.filter_css = frozenset(normalize_filter_css(self.filter_css))
|
||||
self.oeb.log.debug('Filtering CSS properties: %s'%
|
||||
', '.join(self.filter_css))
|
||||
@@ -223,8 +223,8 @@ class CSSFlattener(object):
|
||||
body_font_family = None
|
||||
if not family:
|
||||
return body_font_family, efi
|
||||
from calibre.utils.fonts.scanner import font_scanner, NoFonts
|
||||
from calibre.utils.fonts.utils import panose_to_css_generic_family
|
||||
from ebook_converter.utils.fonts.scanner import font_scanner, NoFonts
|
||||
from ebook_converter.utils.fonts.utils import panose_to_css_generic_family
|
||||
try:
|
||||
faces = font_scanner.fonts_for_family(family)
|
||||
except NoFonts:
|
||||
@@ -610,7 +610,7 @@ class CSSFlattener(object):
|
||||
id, href = manifest.generate('css', 'stylesheet.css')
|
||||
sheet = css_parser.parseString(css, validate=False)
|
||||
if self.transform_css_rules:
|
||||
from calibre.ebooks.css_transform_rules import transform_sheet
|
||||
from ebook_converter.ebooks.css_transform_rules import transform_sheet
|
||||
transform_sheet(self.transform_css_rules, sheet)
|
||||
item = manifest.add(id, href, CSS_MIME, data=sheet)
|
||||
self.oeb.manifest.main_stylesheet = item
|
||||
@@ -642,7 +642,7 @@ class CSSFlattener(object):
|
||||
id_, href = manifest.generate('page_css', 'page_styles.css')
|
||||
sheet = css_parser.parseString(css, validate=False)
|
||||
if self.transform_css_rules:
|
||||
from calibre.ebooks.css_transform_rules import transform_sheet
|
||||
from ebook_converter.ebooks.css_transform_rules import transform_sheet
|
||||
transform_sheet(self.transform_css_rules, sheet)
|
||||
manifest.add(id_, href, CSS_MIME, data=sheet)
|
||||
gc_map[css] = href
|
||||
@@ -664,7 +664,7 @@ class CSSFlattener(object):
|
||||
fsize = self.context.dest.fbase
|
||||
self.flatten_node(html, stylizer, names, styles, pseudo_styles, fsize, item.id, recurse=False)
|
||||
self.flatten_node(html.find(XHTML('body')), stylizer, names, styles, pseudo_styles, fsize, item.id)
|
||||
items = sorted(((key, val) for (val, key) in iteritems(styles)), key=lambda x:numeric_sort_key(x[0]))
|
||||
items = sorted(((key, val) for (val, key) in iteritems(styles)))
|
||||
# :hover must come after link and :active must come after :hover
|
||||
psels = sorted(pseudo_styles, key=lambda x :
|
||||
{'hover':1, 'active':2}.get(x, 0))
|
||||
|
||||
@@ -10,15 +10,15 @@ import sys, os, re
|
||||
from xml.sax.saxutils import escape
|
||||
from string import Formatter
|
||||
|
||||
from calibre import guess_type, strftime
|
||||
from calibre.constants import iswindows
|
||||
from calibre.ebooks.oeb.base import XPath, XHTML_NS, XHTML, xml2text, urldefrag, urlnormalize
|
||||
from calibre.library.comments import comments_to_html, markdown
|
||||
from calibre.utils.date import is_date_undefined, as_local_time
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.ebooks.chardet import strip_encoding_declarations
|
||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||
from polyglot.builtins import unicode_type, map
|
||||
from ebook_converter import guess_type, strftime
|
||||
from ebook_converter.constants import iswindows
|
||||
from ebook_converter.ebooks.oeb.base import XPath, XHTML_NS, XHTML, xml2text, urldefrag, urlnormalize
|
||||
from ebook_converter.library.comments import comments_to_html, markdown
|
||||
from ebook_converter.utils.date import is_date_undefined, as_local_time
|
||||
from ebook_converter.utils.icu import sort_key
|
||||
from ebook_converter.ebooks.chardet import strip_encoding_declarations
|
||||
from ebook_converter.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||
from ebook_converter.polyglot.builtins import unicode_type, map
|
||||
|
||||
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
||||
|
||||
@@ -346,7 +346,7 @@ def render_jacket(mi, output_profile,
|
||||
|
||||
return strip_encoding_declarations(generated_html)
|
||||
|
||||
from calibre.ebooks.oeb.polish.parsing import parse
|
||||
from ebook_converter.ebooks.oeb.polish.parsing import parse
|
||||
raw = generate_html(comments)
|
||||
root = parse(raw, line_numbers=False, force_html5_parse=True)
|
||||
|
||||
@@ -367,7 +367,7 @@ def render_jacket(mi, output_profile,
|
||||
fw.append(child)
|
||||
body.append(fw)
|
||||
postprocess_jacket(root, output_profile, has_data)
|
||||
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||
pretty_html_tree(None, root)
|
||||
return root
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, re
|
||||
from calibre.utils.date import isoformat, now
|
||||
from calibre import guess_type
|
||||
from polyglot.builtins import iteritems
|
||||
from ebook_converter.utils.date import isoformat, now
|
||||
from ebook_converter import guess_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
|
||||
from calibre.ebooks.oeb.base import OPF
|
||||
from ebook_converter.ebooks.oeb.base import OPF
|
||||
if not mi.is_null('title'):
|
||||
m.clear('title')
|
||||
m.add('title', mi.title)
|
||||
@@ -167,7 +167,7 @@ class MergeMetadata(object):
|
||||
return id
|
||||
|
||||
def remove_old_cover(self, cover_item, new_cover_href=None):
|
||||
from calibre.ebooks.oeb.base import XPath, XLINK
|
||||
from ebook_converter.ebooks.oeb.base import XPath, XLINK
|
||||
from lxml import etree
|
||||
|
||||
self.oeb.manifest.remove(cover_item)
|
||||
|
||||
@@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
|
||||
import numbers
|
||||
from collections import Counter
|
||||
|
||||
from calibre.ebooks.oeb.base import barename, XPath
|
||||
from polyglot.builtins import iteritems
|
||||
from ebook_converter.ebooks.oeb.base import barename, XPath
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
class RemoveAdobeMargins(object):
|
||||
|
||||
@@ -11,10 +11,10 @@ import re, uuid
|
||||
from lxml import etree
|
||||
from collections import OrderedDict, Counter
|
||||
|
||||
from calibre.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text, barename
|
||||
from calibre.ebooks import ConversionError
|
||||
from polyglot.builtins import itervalues, unicode_type
|
||||
from polyglot.urllib import urlparse
|
||||
from ebook_converter.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text, barename
|
||||
from ebook_converter.ebooks import ConversionError
|
||||
from ebook_converter.polyglot.builtins import itervalues, unicode_type
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
|
||||
def XPath(x):
|
||||
|
||||
@@ -6,9 +6,9 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||
|
||||
from calibre.ebooks.oeb.base import CSS_MIME, OEB_DOCS
|
||||
from calibre.ebooks.oeb.base import urlnormalize, iterlinks
|
||||
from polyglot.urllib import urldefrag
|
||||
from ebook_converter.ebooks.oeb.base import CSS_MIME, OEB_DOCS
|
||||
from ebook_converter.ebooks.oeb.base import urlnormalize, iterlinks
|
||||
from ebook_converter.polyglot.urllib import urldefrag
|
||||
|
||||
|
||||
class ManifestTrimmer(object):
|
||||
|
||||
@@ -7,8 +7,8 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||
|
||||
import os
|
||||
from calibre.ebooks.oeb.base import OPF_MIME, xml2str
|
||||
from calibre.ebooks.oeb.base import DirContainer, OEBError
|
||||
from ebook_converter.ebooks.oeb.base import OPF_MIME, xml2str
|
||||
from ebook_converter.ebooks.oeb.base import DirContainer, OEBError
|
||||
|
||||
__all__ = ['OEBWriter']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user