1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-17 23:33:43 +01: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:
2020-06-14 15:41:18 +02:00
parent b23a59f223
commit 1465e4267f
22 changed files with 94 additions and 112 deletions

View File

@@ -1,9 +1,10 @@
import textwrap, operator
from copy import deepcopy, copy
import copy
import mimetypes
import operator
import textwrap
from lxml import etree
from ebook_converter import guess_type
from ebook_converter.polyglot.builtins import as_bytes
@@ -87,7 +88,7 @@ class MediaType(etree.XSLTExtension):
def execute(self, context, self_node, input_node, output_parent):
name = input_node.get('file', None)
typ = guess_type(name)[0]
typ = mimetypes.guess_type(name)[0]
if not typ:
typ = 'application/octet-stream'
output_parent.text = typ
@@ -120,7 +121,7 @@ class TextBlock(etree.XSLTExtension):
self.plot_map = plot_map
def execute(self, context, self_node, input_node, output_parent):
input_node = deepcopy(input_node)
input_node = copy.deepcopy(input_node)
div = etree.Element('div')
self.render_block(input_node, div)
output_parent.append(div)
@@ -190,7 +191,7 @@ class TextBlock(etree.XSLTExtension):
for child in children:
p.remove(child)
if pattrib and child.tag == "Span":
attrib = copy(pattrib)
attrib = copy.copy(pattrib)
attrib.update(child.attrib)
child.attrib.update(attrib)