mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-06 09:15:55 +01:00
Removed another unicode/string nonsense
This commit is contained in:
@@ -1,8 +1,3 @@
|
|||||||
''' E-book management software'''
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@@ -14,7 +9,7 @@ import urllib.parse
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from ebook_converter.polyglot.builtins import hasenv, native_string_type
|
from ebook_converter.polyglot.builtins import hasenv
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
if not hasenv('CALIBRE_SHOW_DEPRECATION_WARNINGS'):
|
if not hasenv('CALIBRE_SHOW_DEPRECATION_WARNINGS'):
|
||||||
@@ -191,10 +186,6 @@ def prints(*args, **kwargs):
|
|||||||
raise
|
raise
|
||||||
arg = repr(arg)
|
arg = repr(arg)
|
||||||
if not isinstance(arg, bytes):
|
if not isinstance(arg, bytes):
|
||||||
try:
|
|
||||||
arg = native_string_type(arg)
|
|
||||||
except ValueError:
|
|
||||||
arg = str(arg)
|
|
||||||
if isinstance(arg, str):
|
if isinstance(arg, str):
|
||||||
try:
|
try:
|
||||||
arg = arg.encode(enc)
|
arg = arg.encode(enc)
|
||||||
@@ -612,10 +603,7 @@ def as_unicode(obj, enc=preferred_encoding):
|
|||||||
try:
|
try:
|
||||||
obj = str(obj)
|
obj = str(obj)
|
||||||
except Exception:
|
except Exception:
|
||||||
try:
|
obj = repr(obj)
|
||||||
obj = native_string_type(obj)
|
|
||||||
except Exception:
|
|
||||||
obj = repr(obj)
|
|
||||||
return force_unicode(obj, enc=enc)
|
return force_unicode(obj, enc=enc)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import locale
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ebook_converter.polyglot.builtins import environ_item, hasenv, as_unicode, native_string_type
|
from ebook_converter.polyglot.builtins import environ_item, hasenv, as_unicode
|
||||||
|
|
||||||
__appname__ = 'calibre'
|
__appname__ = 'calibre'
|
||||||
numeric_version = (4, 12, 0)
|
numeric_version = (4, 12, 0)
|
||||||
@@ -178,7 +178,7 @@ class Plugins(collections.Mapping):
|
|||||||
try:
|
try:
|
||||||
plugin_err = str(err)
|
plugin_err = str(err)
|
||||||
except Exception:
|
except Exception:
|
||||||
plugin_err = as_unicode(native_string_type(err), encoding=preferred_encoding, errors='replace')
|
plugin_err = as_unicode(err, encoding=preferred_encoding, errors='replace')
|
||||||
self._plugins[name] = p, plugin_err
|
self._plugins[name] = p, plugin_err
|
||||||
# sys.path.remove(plugins_loc)
|
# sys.path.remove(plugins_loc)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
|
|
||||||
class ConversionUserFeedBack(Exception):
|
class ConversionUserFeedBack(Exception):
|
||||||
|
|
||||||
def __init__(self, title, msg, level='info', det_msg=''):
|
def __init__(self, title, msg, level='info', det_msg=''):
|
||||||
@@ -25,4 +17,4 @@ class ConversionUserFeedBack(Exception):
|
|||||||
|
|
||||||
# Ensure exception uses fully qualified name as this is used to detect it in
|
# Ensure exception uses fully qualified name as this is used to detect it in
|
||||||
# the GUI.
|
# the GUI.
|
||||||
ConversionUserFeedBack.__name__ = native_string_type('ebook_converter.ebooks.conversion.ConversionUserFeedBack')
|
ConversionUserFeedBack.__name__ = 'ebook_converter.ebooks.conversion.ConversionUserFeedBack'
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from ebook_converter.ebooks.docx.index import process_index, polish_index_markup
|
from ebook_converter.ebooks.docx.index import process_index, polish_index_markup
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
||||||
|
|
||||||
|
|
||||||
class Field(object):
|
class Field(object):
|
||||||
@@ -72,7 +67,7 @@ def parser(name, field_map, default_field_name=None):
|
|||||||
ans.pop(null, None)
|
ans.pop(null, None)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
parse.__name__ = native_string_type('parse_' + name)
|
parse.__name__ = 'parse_' + name
|
||||||
|
|
||||||
return parse
|
return parse
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ from ebook_converter.ebooks.pdf.render.common import PAPER_SIZES
|
|||||||
from ebook_converter.utils.date import utcnow
|
from ebook_converter.utils.date import utcnow
|
||||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||||
from ebook_converter.utils.zipfile import ZipFile
|
from ebook_converter.utils.zipfile import ZipFile
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
||||||
|
|
||||||
|
|
||||||
def xml2str(root, pretty_print=False, with_tail=False):
|
def xml2str(root, pretty_print=False, with_tail=False):
|
||||||
@@ -237,7 +232,7 @@ class DOCX(object):
|
|||||||
namespaces = self.namespace.namespaces
|
namespaces = self.namespace.namespaces
|
||||||
E = ElementMaker(namespace=namespaces['cp'], nsmap={x:namespaces[x] for x in 'cp dc dcterms xsi'.split()})
|
E = ElementMaker(namespace=namespaces['cp'], nsmap={x:namespaces[x] for x in 'cp dc dcterms xsi'.split()})
|
||||||
cp = E.coreProperties(E.revision("1"), E.lastModifiedBy('calibre'))
|
cp = E.coreProperties(E.revision("1"), E.lastModifiedBy('calibre'))
|
||||||
ts = utcnow().isoformat(native_string_type('T')).rpartition('.')[0] + 'Z'
|
ts = utcnow().isoformat('T').rpartition('.')[0] + 'Z'
|
||||||
for x in 'created modified'.split():
|
for x in 'created modified'.split():
|
||||||
x = cp.makeelement('{%s}%s' % (namespaces['dcterms'], x), **{'{%s}type' % namespaces['xsi']:'dcterms:W3CDTF'})
|
x = cp.makeelement('{%s}%s' % (namespaces['dcterms'], x), **{'{%s}type' % namespaces['xsi']:'dcterms:W3CDTF'})
|
||||||
x.text = ts
|
x.text = ts
|
||||||
|
|||||||
@@ -4,11 +4,6 @@ from ebook_converter.ebooks.lrf.fonts import get_font
|
|||||||
from ebook_converter.ebooks.lrf.pylrs.pylrs import TextBlock, Text, CR, Span, \
|
from ebook_converter.ebooks.lrf.pylrs.pylrs import TextBlock, Text, CR, Span, \
|
||||||
CharButton, Plot, Paragraph, \
|
CharButton, Plot, Paragraph, \
|
||||||
LrsTextTag
|
LrsTextTag
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
||||||
|
|
||||||
|
|
||||||
def ceil(num):
|
def ceil(num):
|
||||||
@@ -17,8 +12,8 @@ def ceil(num):
|
|||||||
|
|
||||||
def print_xml(elem):
|
def print_xml(elem):
|
||||||
from ebook_converter.ebooks.lrf.pylrs.pylrs import ElementWriter
|
from ebook_converter.ebooks.lrf.pylrs.pylrs import ElementWriter
|
||||||
elem = elem.toElement(native_string_type('utf8'))
|
elem = elem.toElement('utf8')
|
||||||
ew = ElementWriter(elem, sourceEncoding=native_string_type('utf8'))
|
ew = ElementWriter(elem, sourceEncoding='utf8')
|
||||||
ew.write(sys.stdout)
|
ew.write(sys.stdout)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ DEFAULT_GENREADING = "fs" # default is yes to both lrf and lrs
|
|||||||
|
|
||||||
from ebook_converter import __appname__, __version__
|
from ebook_converter import __appname__, __version__
|
||||||
from ebook_converter import entity_to_unicode
|
from ebook_converter import entity_to_unicode
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
class LrsError(Exception):
|
class LrsError(Exception):
|
||||||
@@ -617,7 +616,7 @@ class Book(Delegator):
|
|||||||
|
|
||||||
_formatXml(root)
|
_formatXml(root)
|
||||||
tree = ElementTree(element=root)
|
tree = ElementTree(element=root)
|
||||||
tree.write(f, encoding=native_string_type(outputEncodingName), xml_declaration=True)
|
tree.write(f, encoding=outputEncodingName, xml_declaration=True)
|
||||||
|
|
||||||
|
|
||||||
class BookInformation(Delegator):
|
class BookInformation(Delegator):
|
||||||
@@ -669,7 +668,7 @@ class Info(Delegator):
|
|||||||
# NB: generates an encoding attribute, which lrs2lrf does not
|
# NB: generates an encoding attribute, which lrs2lrf does not
|
||||||
tree = ElementTree(element=info)
|
tree = ElementTree(element=info)
|
||||||
f = io.BytesIO()
|
f = io.BytesIO()
|
||||||
tree.write(f, encoding=native_string_type('utf-8'), xml_declaration=True)
|
tree.write(f, encoding='utf-8', xml_declaration=True)
|
||||||
xmlInfo = f.getvalue().decode('utf-8')
|
xmlInfo = f.getvalue().decode('utf-8')
|
||||||
xmlInfo = re.sub(r"<CThumbnail.*?>\n", "", xmlInfo)
|
xmlInfo = re.sub(r"<CThumbnail.*?>\n", "", xmlInfo)
|
||||||
xmlInfo = xmlInfo.replace("SumPage>", "Page>")
|
xmlInfo = xmlInfo.replace("SumPage>", "Page>")
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from ebook_converter.constants import iswindows
|
|||||||
from ebook_converter.ptempfile import TemporaryDirectory
|
from ebook_converter.ptempfile import TemporaryDirectory
|
||||||
from ebook_converter.ebooks.metadata import (
|
from ebook_converter.ebooks.metadata import (
|
||||||
MetaInformation, string_to_authors, check_isbn, check_doi)
|
MetaInformation, string_to_authors, check_isbn, check_doi)
|
||||||
from ebook_converter.utils.ipc.simple_worker import fork_job, WorkerError
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import importlib
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
native_string_type = str
|
|
||||||
iterkeys = iter
|
|
||||||
|
|
||||||
|
|
||||||
def hasenv(x):
|
def hasenv(x):
|
||||||
return os.getenv(x) is not None
|
return os.getenv(x) is not None
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,6 @@ from ebook_converter.utils.config_base import (
|
|||||||
tweaks, from_json, to_json
|
tweaks, from_json, to_json
|
||||||
)
|
)
|
||||||
from ebook_converter.utils.lock import ExclusiveFile
|
from ebook_converter.utils.lock import ExclusiveFile
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
|
|
||||||
# optparse uses gettext.gettext instead of _ from builtins, so we
|
# optparse uses gettext.gettext instead of _ from builtins, so we
|
||||||
@@ -164,11 +158,11 @@ class OptionParser(optparse.OptionParser):
|
|||||||
|
|
||||||
def options_iter(self):
|
def options_iter(self):
|
||||||
for opt in self.option_list:
|
for opt in self.option_list:
|
||||||
if native_string_type(opt).strip():
|
if str(opt).strip():
|
||||||
yield opt
|
yield opt
|
||||||
for gr in self.option_groups:
|
for gr in self.option_groups:
|
||||||
for opt in gr.option_list:
|
for opt in gr.option_list:
|
||||||
if native_string_type(opt).strip():
|
if str(opt).strip():
|
||||||
yield opt
|
yield opt
|
||||||
|
|
||||||
def option_by_dest(self, dest):
|
def option_by_dest(self, dest):
|
||||||
@@ -193,7 +187,6 @@ class OptionParser(optparse.OptionParser):
|
|||||||
def add_option_group(self, *args, **kwargs):
|
def add_option_group(self, *args, **kwargs):
|
||||||
if isinstance(args[0], (str, bytes)):
|
if isinstance(args[0], (str, bytes)):
|
||||||
args = list(args)
|
args = list(args)
|
||||||
args[0] = native_string_type(args[0])
|
|
||||||
return optparse.OptionParser.add_option_group(self, *args, **kwargs)
|
return optparse.OptionParser.add_option_group(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,8 @@ from ebook_converter import strftime
|
|||||||
from ebook_converter.constants import iswindows, isosx, plugins, preferred_encoding
|
from ebook_converter.constants import iswindows, isosx, plugins, preferred_encoding
|
||||||
from ebook_converter.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
from ebook_converter.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
||||||
from ebook_converter.utils.localization import lcdata
|
from ebook_converter.utils.localization import lcdata
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
_utc_tz = utc_tz
|
_utc_tz = utc_tz
|
||||||
_local_tz = local_tz
|
_local_tz = local_tz
|
||||||
|
|
||||||
@@ -39,7 +34,7 @@ else:
|
|||||||
def first_index(raw, queries):
|
def first_index(raw, queries):
|
||||||
for q in queries:
|
for q in queries:
|
||||||
try:
|
try:
|
||||||
return raw.index(native_string_type(q))
|
return raw.index(q)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return -1
|
return -1
|
||||||
@@ -191,8 +186,7 @@ def isoformat(date_time, assume_utc=False, as_utc=True, sep='T'):
|
|||||||
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
date_time = date_time.replace(tzinfo=_utc_tz if assume_utc else
|
||||||
_local_tz)
|
_local_tz)
|
||||||
date_time = date_time.astimezone(_utc_tz if as_utc else _local_tz)
|
date_time = date_time.astimezone(_utc_tz if as_utc else _local_tz)
|
||||||
# native_string_type(sep) because isoformat barfs with unicode sep on python 2.x
|
return str(date_time.isoformat(sep))
|
||||||
return str(date_time.isoformat(native_string_type(sep)))
|
|
||||||
|
|
||||||
|
|
||||||
def internal_iso_format_string():
|
def internal_iso_format_string():
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from ebook_converter.constants import isosx, isfrozen, filesystem_encoding
|
|||||||
from ebook_converter.utils.config import prefs
|
from ebook_converter.utils.config import prefs
|
||||||
from ebook_converter.ptempfile import PersistentTemporaryFile, base_dir
|
from ebook_converter.ptempfile import PersistentTemporaryFile, base_dir
|
||||||
from ebook_converter.utils.serialize import msgpack_dumps
|
from ebook_converter.utils.serialize import msgpack_dumps
|
||||||
from ebook_converter.polyglot.builtins import environ_item, native_string_type
|
from ebook_converter.polyglot.builtins import environ_item
|
||||||
from ebook_converter.polyglot.binary import as_hex_unicode
|
from ebook_converter.polyglot.binary import as_hex_unicode
|
||||||
try:
|
try:
|
||||||
import win32process
|
import win32process
|
||||||
@@ -14,11 +14,6 @@ except ImportError:
|
|||||||
iswindows = False
|
iswindows = False
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
try:
|
try:
|
||||||
windows_null_file = open(os.devnull, 'wb')
|
windows_null_file = open(os.devnull, 'wb')
|
||||||
@@ -89,9 +84,9 @@ class Worker(object):
|
|||||||
@property
|
@property
|
||||||
def env(self):
|
def env(self):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env[native_string_type('CALIBRE_WORKER')] = environ_item('1')
|
env['CALIBRE_WORKER'] = environ_item('1')
|
||||||
td = as_hex_unicode(msgpack_dumps(base_dir()))
|
td = as_hex_unicode(msgpack_dumps(base_dir()))
|
||||||
env[native_string_type('CALIBRE_WORKER_TEMP_DIR')] = environ_item(td)
|
env['CALIBRE_WORKER_TEMP_DIR'] = environ_item(td)
|
||||||
env.update(self._env)
|
env.update(self._env)
|
||||||
return env
|
return env
|
||||||
|
|
||||||
@@ -154,7 +149,7 @@ class Worker(object):
|
|||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
# cwd no longer exists
|
# cwd no longer exists
|
||||||
origwd = cwd or os.path.expanduser('~')
|
origwd = cwd or os.path.expanduser('~')
|
||||||
env[native_string_type('ORIGWD')] = environ_item(as_hex_unicode(msgpack_dumps(origwd)))
|
env['ORIGWD'] = environ_item(as_hex_unicode(msgpack_dumps(origwd)))
|
||||||
_cwd = cwd
|
_cwd = cwd
|
||||||
if priority is None:
|
if priority is None:
|
||||||
priority = prefs['worker_process_priority']
|
priority = prefs['worker_process_priority']
|
||||||
|
|||||||
@@ -6,13 +6,6 @@ try:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
iswindows = False
|
iswindows = False
|
||||||
|
|
||||||
from ebook_converter.polyglot.builtins import native_string_type
|
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
|
|
||||||
def fmt(code):
|
def fmt(code):
|
||||||
return '\033[%dm' % code
|
return '\033[%dm' % code
|
||||||
@@ -128,7 +121,7 @@ class Detect(object):
|
|||||||
# Stream is a console
|
# Stream is a console
|
||||||
self.set_console = windll.kernel32.SetConsoleTextAttribute
|
self.set_console = windll.kernel32.SetConsoleTextAttribute
|
||||||
self.default_console_text_attributes = WCOLORS['white']
|
self.default_console_text_attributes = WCOLORS['white']
|
||||||
kernel32 = WinDLL(native_string_type('kernel32'), use_last_error=True)
|
kernel32 = WinDLL('kernel32', use_last_error=True)
|
||||||
self.write_console = kernel32.WriteConsoleW
|
self.write_console = kernel32.WriteConsoleW
|
||||||
self.write_console.argtypes = [wintypes.HANDLE, wintypes.c_wchar_p, wintypes.DWORD, POINTER(wintypes.DWORD), wintypes.LPVOID]
|
self.write_console.argtypes = [wintypes.HANDLE, wintypes.c_wchar_p, wintypes.DWORD, POINTER(wintypes.DWORD), wintypes.LPVOID]
|
||||||
self.write_console.restype = wintypes.BOOL
|
self.write_console.restype = wintypes.BOOL
|
||||||
|
|||||||
Reference in New Issue
Block a user