mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move guess_type into the utils module
This commit is contained in:
parent
ba277fd169
commit
da50613e48
@ -12,7 +12,8 @@ from calibre import force_unicode
|
|||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES
|
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.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.ebooks.oeb.polish.pretty import pretty_script_or_style
|
||||||
from calibre.utils.fonts.utils import get_all_font_names
|
from calibre.utils.fonts.utils import get_all_font_names
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ from collections import defaultdict
|
|||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES
|
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
|
from calibre.ebooks.oeb.polish.check.base import BaseError, WARN, INFO
|
||||||
|
|
||||||
class BadLink(BaseError):
|
class BadLink(BaseError):
|
||||||
|
@ -9,7 +9,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES
|
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.cover import is_raster_image
|
||||||
from calibre.ebooks.oeb.polish.check.base import run_checkers
|
from calibre.ebooks.oeb.polish.check.base import run_checkers
|
||||||
from calibre.ebooks.oeb.polish.check.parsing import (
|
from calibre.ebooks.oeb.polish.check.parsing import (
|
||||||
|
@ -16,7 +16,7 @@ from future_builtins import zip
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
from cssutils import replaceUrls, getUrls
|
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,
|
from calibre.customize.ui import (plugin_for_input_format,
|
||||||
plugin_for_output_format)
|
plugin_for_output_format)
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
@ -31,7 +31,7 @@ from calibre.ebooks.oeb.base import (
|
|||||||
rewrite_links, iterlinks, itercsslinks, urlquote, urlunquote)
|
rewrite_links, iterlinks, itercsslinks, urlquote, urlunquote)
|
||||||
from calibre.ebooks.oeb.polish.errors import InvalidBook, DRMError
|
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.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.ebooks.oeb.parse_utils import NotHTML, parse_html, RECOVER_PARSER
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile
|
||||||
from calibre.utils.filenames import nlinks_file, hardlink_file
|
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
|
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'}
|
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}
|
OPF_NAMESPACES = {'opf':OPF2_NS, 'dc':DC11_NS}
|
||||||
|
@ -15,7 +15,8 @@ from calibre.ptempfile import TemporaryDirectory
|
|||||||
from calibre.ebooks.oeb.base import serialize
|
from calibre.ebooks.oeb.base import serialize
|
||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
from calibre.ebooks.oeb.polish.parsing import parse
|
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.pretty import pretty_xml_tree, pretty_html_tree
|
||||||
from calibre.ebooks.oeb.polish.toc import TOC, create_ncx
|
from calibre.ebooks.oeb.polish.toc import TOC, create_ncx
|
||||||
from calibre.utils.localization import lang_as_iso639_1
|
from calibre.utils.localization import lang_as_iso639_1
|
||||||
|
@ -14,7 +14,8 @@ from future_builtins import map
|
|||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.ebooks.oeb.base import (
|
from calibre.ebooks.oeb.base import (
|
||||||
serialize, OEB_DOCS, barename, OEB_STYLES, XPNSMAP, XHTML, SVG)
|
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
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
def isspace(x):
|
def isspace(x):
|
||||||
|
@ -147,7 +147,8 @@ def replace_file(container, name, path, basename, force_mt=None):
|
|||||||
shutil.copyfileobj(src, dest)
|
shutil.copyfileobj(src, dest)
|
||||||
|
|
||||||
def mt_to_category(container, mt):
|
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
|
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES
|
||||||
if mt in OEB_DOCS:
|
if mt in OEB_DOCS:
|
||||||
category = 'text'
|
category = 'text'
|
||||||
@ -165,7 +166,7 @@ def mt_to_category(container, mt):
|
|||||||
|
|
||||||
def get_recommended_folders(container, names):
|
def get_recommended_folders(container, names):
|
||||||
' Return the folders that are recommended for the given filenames '
|
' 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)
|
counts = defaultdict(Counter)
|
||||||
for name, mt in container.mime_map.iteritems():
|
for name, mt in container.mime_map.iteritems():
|
||||||
folder = name.rpartition('/')[0] if '/' in name else ''
|
folder = name.rpartition('/')[0] if '/' in name else ''
|
||||||
|
@ -11,7 +11,8 @@ import os, sys
|
|||||||
|
|
||||||
from calibre import prints, as_unicode
|
from calibre import prints, as_unicode
|
||||||
from calibre.ebooks.oeb.base import OEB_STYLES, OEB_DOCS, XPath
|
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.subset import subset
|
||||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
||||||
from calibre.utils.fonts.utils import get_font_names
|
from calibre.utils.fonts.utils import get_font_names
|
||||||
|
@ -17,7 +17,7 @@ from lxml import etree
|
|||||||
|
|
||||||
from calibre import __version__
|
from calibre import __version__
|
||||||
from calibre.ebooks.oeb.base import XPath, uuid_id, xml2text, NCX, NCX_NS, XML, XHTML
|
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
|
from calibre.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
||||||
|
|
||||||
ns = etree.FunctionNamespace('calibre_xpath_extensions')
|
ns = etree.FunctionNamespace('calibre_xpath_extensions')
|
||||||
|
@ -9,6 +9,11 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import re
|
import re
|
||||||
from bisect import bisect
|
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):
|
class PositionFinder(object):
|
||||||
|
|
||||||
def __init__(self, raw):
|
def __init__(self, raw):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user