mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-19 12:43:35 +02:00
Sorted out mime initialization.
Every mime related function in main __init__.py has a flag check for the check if initialization has already done. This is nonsense, since it should be done implicitly early on the converter is starting. This commit straight the things out, and initialization is done in cli module. Also, function guess_type was removed, since it's just a proxy for mimetypes.guess_type function.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import mimetypes
|
||||
import textwrap, os
|
||||
|
||||
from lxml import etree
|
||||
from lxml.builder import ElementMaker
|
||||
|
||||
from ebook_converter import guess_type
|
||||
from ebook_converter.constants_old import numeric_version, __appname__
|
||||
from ebook_converter.ebooks.docx.names import DOCXNamespace
|
||||
from ebook_converter.ebooks.metadata import authors_to_string
|
||||
@@ -179,16 +179,20 @@ class DOCX(object):
|
||||
types.append(E.Override(PartName=partname, ContentType=mt))
|
||||
added = {'png', 'gif', 'jpeg', 'jpg', 'svg', 'xml'}
|
||||
for ext in added:
|
||||
types.append(E.Default(Extension=ext, ContentType=guess_type('a.'+ext)[0]))
|
||||
for ext, mt in {"rels": "application/vnd.openxmlformats-package.relationships+xml",
|
||||
"odttf": "application/vnd.openxmlformats-officedocument.obfuscatedFont"}.items():
|
||||
types.append(E.Default(Extension=ext,
|
||||
ContentType=mimetypes.guess_type('a.' +
|
||||
ext)[0]))
|
||||
for ext, mt in {"rels": "application/vnd.openxmlformats-package"
|
||||
".relationships+xml",
|
||||
"odttf": "application/vnd.openxmlformats-"
|
||||
"officedocument.obfuscatedFont"}.items():
|
||||
added.add(ext)
|
||||
types.append(E.Default(Extension=ext, ContentType=mt))
|
||||
for fname in self.images:
|
||||
ext = fname.rpartition(os.extsep)[-1]
|
||||
if ext not in added:
|
||||
added.add(ext)
|
||||
mt = guess_type('a.' + ext)[0]
|
||||
mt = mimetypes.guess_type('a.' + ext)[0]
|
||||
if mt:
|
||||
types.append(E.Default(Extension=ext, ContentType=mt))
|
||||
return xml2str(types)
|
||||
|
||||
Reference in New Issue
Block a user