diff --git a/src/calibre/ebooks/oeb/polish/check/fonts.py b/src/calibre/ebooks/oeb/polish/check/fonts.py index 825d6aa8a9..8a6ba99d1c 100644 --- a/src/calibre/ebooks/oeb/polish/check/fonts.py +++ b/src/calibre/ebooks/oeb/polish/check/fonts.py @@ -12,7 +12,8 @@ from calibre import force_unicode from calibre.constants import plugins from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES from calibre.ebooks.oeb.polish.check.base import BaseError, WARN -from calibre.ebooks.oeb.polish.container import guess_type, OEB_FONTS +from calibre.ebooks.oeb.polish.container import OEB_FONTS +from calibre.ebooks.oeb.polish.utils import guess_type from calibre.ebooks.oeb.polish.pretty import pretty_script_or_style from calibre.utils.fonts.utils import get_all_font_names diff --git a/src/calibre/ebooks/oeb/polish/check/links.py b/src/calibre/ebooks/oeb/polish/check/links.py index bdcd0332df..a8627b7685 100644 --- a/src/calibre/ebooks/oeb/polish/check/links.py +++ b/src/calibre/ebooks/oeb/polish/check/links.py @@ -10,7 +10,8 @@ from collections import defaultdict from urlparse import urlparse from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES -from calibre.ebooks.oeb.polish.container import guess_type, OEB_FONTS +from calibre.ebooks.oeb.polish.container import OEB_FONTS +from calibre.ebooks.oeb.polish.utils import guess_type from calibre.ebooks.oeb.polish.check.base import BaseError, WARN, INFO class BadLink(BaseError): diff --git a/src/calibre/ebooks/oeb/polish/check/main.py b/src/calibre/ebooks/oeb/polish/check/main.py index 45a23fafc3..cdae11acc8 100644 --- a/src/calibre/ebooks/oeb/polish/check/main.py +++ b/src/calibre/ebooks/oeb/polish/check/main.py @@ -9,7 +9,7 @@ __copyright__ = '2013, Kovid Goyal ' from future_builtins import map from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES -from calibre.ebooks.oeb.polish.container import guess_type +from calibre.ebooks.oeb.polish.utils import guess_type from calibre.ebooks.oeb.polish.cover import is_raster_image from calibre.ebooks.oeb.polish.check.base import run_checkers from calibre.ebooks.oeb.polish.check.parsing import ( diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index d6554cf015..47c968c0fc 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -16,7 +16,7 @@ from future_builtins import zip from lxml import etree from cssutils import replaceUrls, getUrls -from calibre import guess_type as _guess_type, CurrentDir +from calibre import CurrentDir from calibre.customize.ui import (plugin_for_input_format, plugin_for_output_format) from calibre.ebooks.chardet import xml_to_unicode @@ -31,7 +31,7 @@ from calibre.ebooks.oeb.base import ( rewrite_links, iterlinks, itercsslinks, urlquote, urlunquote) from calibre.ebooks.oeb.polish.errors import InvalidBook, DRMError from calibre.ebooks.oeb.polish.parsing import parse as parse_html_tweak -from calibre.ebooks.oeb.polish.utils import PositionFinder, CommentFinder +from calibre.ebooks.oeb.polish.utils import PositionFinder, CommentFinder, guess_type from calibre.ebooks.oeb.parse_utils import NotHTML, parse_html, RECOVER_PARSER from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile from calibre.utils.filenames import nlinks_file, hardlink_file @@ -41,8 +41,6 @@ from calibre.utils.zipfile import ZipFile exists, join, relpath = os.path.exists, os.path.join, os.path.relpath -def guess_type(x): - return _guess_type(x)[0] or 'application/octet-stream' OEB_FONTS = {guess_type('a.ttf'), guess_type('b.otf'), guess_type('a.woff'), 'application/x-font-ttf', 'application/x-font-otf'} OPF_NAMESPACES = {'opf':OPF2_NS, 'dc':DC11_NS} diff --git a/src/calibre/ebooks/oeb/polish/create.py b/src/calibre/ebooks/oeb/polish/create.py index 95e276b08e..73e5b3fd5b 100644 --- a/src/calibre/ebooks/oeb/polish/create.py +++ b/src/calibre/ebooks/oeb/polish/create.py @@ -15,7 +15,8 @@ from calibre.ptempfile import TemporaryDirectory from calibre.ebooks.oeb.base import serialize from calibre.ebooks.metadata.opf2 import metadata_to_opf from calibre.ebooks.oeb.polish.parsing import parse -from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, guess_type, opf_to_azw3 +from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, opf_to_azw3 +from calibre.ebooks.oeb.polish.utils import guess_type from calibre.ebooks.oeb.polish.pretty import pretty_xml_tree, pretty_html_tree from calibre.ebooks.oeb.polish.toc import TOC, create_ncx from calibre.utils.localization import lang_as_iso639_1 diff --git a/src/calibre/ebooks/oeb/polish/pretty.py b/src/calibre/ebooks/oeb/polish/pretty.py index c0944d4755..b44f45ebcb 100644 --- a/src/calibre/ebooks/oeb/polish/pretty.py +++ b/src/calibre/ebooks/oeb/polish/pretty.py @@ -14,7 +14,8 @@ from future_builtins import map from calibre import force_unicode from calibre.ebooks.oeb.base import ( serialize, OEB_DOCS, barename, OEB_STYLES, XPNSMAP, XHTML, SVG) -from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, guess_type +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 def isspace(x): diff --git a/src/calibre/ebooks/oeb/polish/replace.py b/src/calibre/ebooks/oeb/polish/replace.py index 77cc8c7073..4d0ad97b9d 100644 --- a/src/calibre/ebooks/oeb/polish/replace.py +++ b/src/calibre/ebooks/oeb/polish/replace.py @@ -147,7 +147,8 @@ def replace_file(container, name, path, basename, force_mt=None): shutil.copyfileobj(src, dest) def mt_to_category(container, mt): - from calibre.ebooks.oeb.polish.container import guess_type, OEB_FONTS + from calibre.ebooks.oeb.polish.utils import guess_type + from calibre.ebooks.oeb.polish.container import OEB_FONTS from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES if mt in OEB_DOCS: category = 'text' @@ -165,7 +166,7 @@ def mt_to_category(container, mt): def get_recommended_folders(container, names): ' Return the folders that are recommended for the given filenames ' - from calibre.ebooks.oeb.polish.container import guess_type + from calibre.ebooks.oeb.polish.utils import guess_type counts = defaultdict(Counter) for name, mt in container.mime_map.iteritems(): folder = name.rpartition('/')[0] if '/' in name else '' diff --git a/src/calibre/ebooks/oeb/polish/subset.py b/src/calibre/ebooks/oeb/polish/subset.py index 7cd918ae36..8b03693cda 100644 --- a/src/calibre/ebooks/oeb/polish/subset.py +++ b/src/calibre/ebooks/oeb/polish/subset.py @@ -11,7 +11,8 @@ import os, sys from calibre import prints, as_unicode from calibre.ebooks.oeb.base import OEB_STYLES, OEB_DOCS, XPath -from calibre.ebooks.oeb.polish.container import OEB_FONTS, guess_type +from calibre.ebooks.oeb.polish.container import OEB_FONTS +from calibre.ebooks.oeb.polish.utils import guess_type from calibre.utils.fonts.sfnt.subset import subset from calibre.utils.fonts.sfnt.errors import UnsupportedFont from calibre.utils.fonts.utils import get_font_names diff --git a/src/calibre/ebooks/oeb/polish/toc.py b/src/calibre/ebooks/oeb/polish/toc.py index cb63a82afc..b459d91dba 100644 --- a/src/calibre/ebooks/oeb/polish/toc.py +++ b/src/calibre/ebooks/oeb/polish/toc.py @@ -17,7 +17,7 @@ from lxml import etree from calibre import __version__ from calibre.ebooks.oeb.base import XPath, uuid_id, xml2text, NCX, NCX_NS, XML, XHTML -from calibre.ebooks.oeb.polish.container import guess_type +from calibre.ebooks.oeb.polish.utils import guess_type from calibre.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1 ns = etree.FunctionNamespace('calibre_xpath_extensions') diff --git a/src/calibre/ebooks/oeb/polish/utils.py b/src/calibre/ebooks/oeb/polish/utils.py index 1a9aa2f968..3bfc465ec3 100644 --- a/src/calibre/ebooks/oeb/polish/utils.py +++ b/src/calibre/ebooks/oeb/polish/utils.py @@ -9,6 +9,11 @@ __copyright__ = '2013, Kovid Goyal ' import re from bisect import bisect +from calibre import guess_type as _guess_type + +def guess_type(x): + return _guess_type(x)[0] or 'application/octet-stream' + class PositionFinder(object): def __init__(self, raw):