mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-22 22:21:31 +02:00
Moved misc functions from polyglot package to single polyglot module.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user