1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-24 15:11:30 +02:00

Moved misc functions from polyglot package to single polyglot module.

This commit is contained in:
2021-05-25 19:06:31 +02:00
parent f46984267e
commit f47376830f
32 changed files with 244 additions and 219 deletions
+6 -8
View File
@@ -1,22 +1,20 @@
__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import io
from ebook_converter import polyglot
def base64_decode(raw):
from io import BytesIO
from ebook_converter.polyglot.binary import from_base64_bytes
# First try the python implementation as it is faster
try:
return from_base64_bytes(raw)
return polyglot.from_base64_bytes(raw)
except Exception:
pass
# Try a more robust version (adapted from FBReader sources)
A, Z, a, z, zero, nine, plus, slash, equal = bytearray(b'AZaz09+/=')
raw = bytearray(raw)
out = BytesIO()
out = io.BytesIO()
pos = 0
while pos < len(raw):
tot = 0
@@ -32,7 +30,7 @@ def base64_decode(raw):
elif zero <= byt <= nine:
num = byt - zero + 52
else:
num = {plus:62, slash:63, equal:64}.get(byt, None)
num = {plus: 62, slash: 63, equal: 64}.get(byt, None)
if num is None:
# Ignore this byte
continue
+3 -3
View File
@@ -13,7 +13,7 @@ from ebook_converter import constants as const
from ebook_converter.constants_old import __appname__, __version__
from ebook_converter.ebooks.oeb import base
from ebook_converter.ebooks.oeb import parse_utils
from ebook_converter.polyglot.binary import as_base64_unicode
from ebook_converter import polyglot
from ebook_converter.utils import entities
from ebook_converter.utils.img import save_cover_data_to
from ebook_converter.utils.localization import lang_as_iso639_1
@@ -355,10 +355,10 @@ class FB2MLizer(object):
if item.media_type not in ('image/jpeg', 'image/png'):
imdata = save_cover_data_to(item.data,
compression_quality=70)
raw_data = as_base64_unicode(imdata)
raw_data = polyglot.as_base64_unicode(imdata)
content_type = 'image/jpeg'
else:
raw_data = as_base64_unicode(item.data)
raw_data = polyglot.as_base64_unicode(item.data)
content_type = item.media_type
# Don't put the encoded image on a single line.
step = 72