diff --git a/setup/extensions.json b/setup/extensions.json index a22f98df65..6e22528dd8 100644 --- a/setup/extensions.json +++ b/setup/extensions.json @@ -31,7 +31,8 @@ "inc_dirs": "!zlib_inc_dirs", "lib_dirs": "!zlib_lib_dirs", "libraries": "z", - "windows_libraries": "zlib" + "windows_libraries": "zlib", + "needs_py2": true }, { "name": "certgen", diff --git a/src/calibre/srv/http_response.py b/src/calibre/srv/http_response.py index ead9aa4d6f..4d51ea1e21 100644 --- a/src/calibre/srv/http_response.py +++ b/src/calibre/srv/http_response.py @@ -12,9 +12,8 @@ from io import BytesIO, DEFAULT_BUFFER_SIZE from itertools import chain, repeat, izip_longest from operator import itemgetter from functools import wraps -from polyglot.builtins import map -from polyglot.builtins import reraise +from polyglot.builtins import reraise, map, is_py3 from calibre import guess_type, force_unicode from calibre.constants import __version__, plugins @@ -31,10 +30,13 @@ from calibre.utils.monotonic import monotonic Range = namedtuple('Range', 'start stop size') MULTIPART_SEPARATOR = uuid.uuid4().hex.decode('ascii') COMPRESSIBLE_TYPES = {'application/json', 'application/javascript', 'application/xml', 'application/oebps-package+xml'} -zlib, zlib2_err = plugins['zlib2'] -if zlib2_err: - raise RuntimeError('Failed to laod the zlib2 module with error: ' + zlib2_err) -del zlib2_err +if is_py3: + import zlib +else: + zlib, zlib2_err = plugins['zlib2'] + if zlib2_err: + raise RuntimeError('Failed to load the zlib2 module with error: ' + zlib2_err) + del zlib2_err def header_list_to_file(buf): # {{{