mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-01-06 19:44:12 +01:00
Removed check for python version
This commit is contained in:
@@ -9,16 +9,13 @@ from copy import deepcopy
|
||||
import pkg_resources
|
||||
|
||||
from ebook_converter.utils.lock import ExclusiveFile
|
||||
from ebook_converter.constants import config_dir, CONFIG_DIR_MODE, ispy3, preferred_encoding, filesystem_encoding, iswindows
|
||||
from ebook_converter.constants import config_dir, CONFIG_DIR_MODE, preferred_encoding, filesystem_encoding, iswindows
|
||||
|
||||
plugin_dir = os.path.join(config_dir, 'plugins')
|
||||
|
||||
|
||||
def parse_old_style(src):
|
||||
if ispy3:
|
||||
import pickle as cPickle
|
||||
else:
|
||||
import cPickle
|
||||
import pickle as cPickle
|
||||
options = {'cPickle':cPickle}
|
||||
try:
|
||||
if not isinstance(src, str):
|
||||
|
||||
@@ -10,7 +10,7 @@ from math import ceil
|
||||
|
||||
from ebook_converter import force_unicode, isbytestring, prints, sanitize_file_name
|
||||
from ebook_converter.constants import (
|
||||
filesystem_encoding, iswindows, plugins, preferred_encoding, isosx, ispy3
|
||||
filesystem_encoding, iswindows, plugins, preferred_encoding, isosx
|
||||
)
|
||||
from ebook_converter.utils.localization import get_udc
|
||||
|
||||
@@ -624,16 +624,3 @@ def copytree_using_links(path, dest, dest_is_parent=True, filecopyfunc=copyfile)
|
||||
hardlink(src, df)
|
||||
except Exception:
|
||||
filecopyfunc(src, df)
|
||||
|
||||
|
||||
if not ispy3 and not iswindows:
|
||||
# On POSIX in python2 if you pass a unicode path to rmtree
|
||||
# it tries to decode all filenames it encounters while walking
|
||||
# the tree which leads to unicode errors on Linux where there
|
||||
# can be non-decodeable filenames.
|
||||
def rmtree(x, **kw):
|
||||
if not isinstance(x, bytes):
|
||||
x = x.encode('utf-8')
|
||||
return shutil.rmtree(x, **kw)
|
||||
else:
|
||||
rmtree = shutil.rmtree
|
||||
|
||||
@@ -12,7 +12,7 @@ from threading import Thread
|
||||
#from PyQt5.QtGui import QColor, QImage, QImageReader, QImageWriter, QPixmap, QTransform
|
||||
|
||||
from ebook_converter import fit_image, force_unicode
|
||||
from ebook_converter.constants import iswindows, plugins, ispy3
|
||||
from ebook_converter.constants import iswindows, plugins
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.utils.config_base import tweaks
|
||||
from ebook_converter.utils.filenames import atomic_rename
|
||||
@@ -545,13 +545,7 @@ def run_optimizer(file_path, cmd, as_filter=False, input_data=None):
|
||||
cmd[cmd.index(q)] = r
|
||||
if not as_filter:
|
||||
repl(True, iname), repl(False, oname)
|
||||
if iswindows and not ispy3:
|
||||
# subprocess in python 2 cannot handle unicode strings that are not
|
||||
# encodeable in mbcs, so we fail here, where it is more explicit,
|
||||
# instead.
|
||||
cmd = [x.encode('mbcs') if isinstance(x, str) else x for x in cmd]
|
||||
if isinstance(cwd, str):
|
||||
cwd = cwd.encode('mbcs')
|
||||
|
||||
stdin = subprocess.PIPE if as_filter else None
|
||||
stderr = subprocess.PIPE if as_filter else subprocess.STDOUT
|
||||
creationflags = 0x08 if iswindows else 0
|
||||
|
||||
@@ -5,7 +5,6 @@ from struct import unpack, error
|
||||
import os
|
||||
|
||||
from ebook_converter.utils.speedups import ReadOnlyFileBuffer
|
||||
from ebook_converter.constants import ispy3
|
||||
|
||||
|
||||
HSIZE = 120
|
||||
@@ -122,12 +121,8 @@ def jpeg_dimensions(stream):
|
||||
raise ValueError('Truncated JPEG data')
|
||||
return ans
|
||||
|
||||
if ispy3:
|
||||
def read_byte():
|
||||
return read(1)[0]
|
||||
else:
|
||||
def read_byte():
|
||||
return ord(read(1)[0])
|
||||
def read_byte():
|
||||
return read(1)[0]
|
||||
|
||||
x = None
|
||||
while True:
|
||||
|
||||
@@ -8,7 +8,6 @@ from ebook_converter import force_unicode
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.constants import get_windows_username
|
||||
from ebook_converter.constants import islinux
|
||||
from ebook_converter.constants import ispy3
|
||||
from ebook_converter.constants import iswindows
|
||||
from ebook_converter.utils.filenames import ascii_filename
|
||||
|
||||
@@ -51,8 +50,6 @@ def socket_address(which):
|
||||
from tempfile import gettempdir
|
||||
tmp = force_unicode(gettempdir(), filesystem_encoding)
|
||||
ans = os.path.join(tmp, sock_name)
|
||||
if not ispy3 and not isinstance(ans, bytes):
|
||||
ans = ans.encode(filesystem_encoding)
|
||||
return ans
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import subprocess, os, sys, time
|
||||
from functools import partial
|
||||
|
||||
from ebook_converter.constants import isosx, isfrozen, filesystem_encoding, ispy3
|
||||
from ebook_converter.constants import isosx, isfrozen, filesystem_encoding
|
||||
from ebook_converter.utils.config import prefs
|
||||
from ebook_converter.ptempfile import PersistentTemporaryFile, base_dir
|
||||
from ebook_converter.utils.serialize import msgpack_dumps
|
||||
@@ -88,26 +88,7 @@ class Worker(object):
|
||||
|
||||
@property
|
||||
def env(self):
|
||||
if ispy3:
|
||||
env = os.environ.copy()
|
||||
else:
|
||||
# We use this inefficient method of copying the environment variables
|
||||
# because of non ascii env vars on windows. See https://bugs.launchpad.net/bugs/811191
|
||||
env = {}
|
||||
for key in os.environ:
|
||||
try:
|
||||
val = os.environ[key]
|
||||
if isinstance(val, str):
|
||||
# On windows subprocess cannot handle unicode env vars
|
||||
try:
|
||||
val = val.encode(filesystem_encoding)
|
||||
except ValueError:
|
||||
val = val.encode('utf-8')
|
||||
if isinstance(key, str):
|
||||
key = key.encode('ascii')
|
||||
env[key] = val
|
||||
except:
|
||||
pass
|
||||
env = os.environ.copy()
|
||||
env[native_string_type('CALIBRE_WORKER')] = environ_item('1')
|
||||
td = as_hex_unicode(msgpack_dumps(base_dir()))
|
||||
env[native_string_type('CALIBRE_WORKER_TEMP_DIR')] = environ_item(td)
|
||||
@@ -158,22 +139,8 @@ class Worker(object):
|
||||
self._env = {}
|
||||
self.gui = gui
|
||||
self.job_name = job_name
|
||||
if ispy3:
|
||||
self._env = env.copy()
|
||||
else:
|
||||
# Windows cannot handle unicode env vars
|
||||
for k, v in env.items():
|
||||
try:
|
||||
if isinstance(k, str):
|
||||
k = k.encode('ascii')
|
||||
if isinstance(v, str):
|
||||
try:
|
||||
v = v.encode(filesystem_encoding)
|
||||
except:
|
||||
v = v.encode('utf-8')
|
||||
self._env[k] = v
|
||||
except:
|
||||
pass
|
||||
self._env = env.copy()
|
||||
|
||||
|
||||
def __call__(self, redirect_output=True, cwd=None, priority=None):
|
||||
'''
|
||||
|
||||
@@ -9,7 +9,7 @@ import time
|
||||
from functools import partial
|
||||
|
||||
from ebook_converter.constants import (
|
||||
__appname__, fcntl, filesystem_encoding, islinux, isosx, iswindows, plugins, ispy3
|
||||
__appname__, fcntl, filesystem_encoding, islinux, isosx, iswindows, plugins
|
||||
)
|
||||
from ebook_converter.utils.monotonic import monotonic
|
||||
|
||||
@@ -156,8 +156,6 @@ elif islinux:
|
||||
)
|
||||
name = name
|
||||
address = '\0' + name.replace(' ', '_')
|
||||
if not ispy3:
|
||||
address = address.encode('utf-8')
|
||||
sock = socket.socket(family=socket.AF_UNIX)
|
||||
try:
|
||||
eintr_retry_call(sock.bind, address)
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from ebook_converter.constants import ispy3
|
||||
|
||||
|
||||
MSGPACK_MIME = 'application/x-msgpack'
|
||||
CANARY = 'jPoAv3zOyHvQ5JFNYg4hJ9'
|
||||
|
||||
@@ -111,22 +108,10 @@ def json_loads(data):
|
||||
return json.loads(data, object_hook=json_decoder)
|
||||
|
||||
|
||||
if ispy3:
|
||||
def pickle_dumps(data):
|
||||
import pickle
|
||||
return pickle.dumps(data, -1)
|
||||
|
||||
def pickle_dumps(data):
|
||||
import pickle
|
||||
return pickle.dumps(data, -1)
|
||||
|
||||
def pickle_loads(dump):
|
||||
import pickle
|
||||
return pickle.loads(dump, encoding='utf-8')
|
||||
|
||||
else:
|
||||
|
||||
def pickle_dumps(data):
|
||||
import cPickle as pickle
|
||||
return pickle.dumps(data, -1)
|
||||
|
||||
def pickle_loads(dump):
|
||||
import cPickle as pickle
|
||||
return pickle.loads(dump)
|
||||
def pickle_loads(dump):
|
||||
import pickle
|
||||
return pickle.loads(dump, encoding='utf-8')
|
||||
|
||||
@@ -17,7 +17,7 @@ file before deleting it.
|
||||
import os, sys
|
||||
|
||||
from ebook_converter.polyglot.builtins import reraise
|
||||
from ebook_converter.constants import iswindows, plugins, ispy3
|
||||
from ebook_converter.constants import iswindows, plugins
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,6 @@ try:
|
||||
except ValueError:
|
||||
iswindows = False
|
||||
|
||||
from ebook_converter.constants import ispy3
|
||||
from ebook_converter.polyglot.builtins import native_string_type
|
||||
|
||||
|
||||
@@ -152,12 +151,8 @@ class Detect(object):
|
||||
while text:
|
||||
t, text = text[:chunk], text[chunk:]
|
||||
wt = c_wchar_p(t)
|
||||
if ispy3:
|
||||
text_len = len(t.encode('utf-16'))
|
||||
else:
|
||||
# Use the fact that len(t) == wcslen(wt) in python 2.7 on
|
||||
# windows where the python unicode type uses UTF-16
|
||||
text_len = len(t)
|
||||
text_len = len(t.encode('utf-16'))
|
||||
|
||||
if not self.write_console(self.file_handle, wt, text_len, byref(written), None):
|
||||
# Older versions of windows can fail to write large strings
|
||||
# to console with WriteConsoleW (seen it happen on Win XP)
|
||||
|
||||
Reference in New Issue
Block a user