mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-13 13:15:53 +01:00
Removed polyglots unicode_type usage
This commit is contained in:
@@ -10,7 +10,7 @@ from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.polyglot.builtins import unicode_type, as_bytes
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = ('2008, Kovid Goyal <kovid at kovidgoyal.net>, '
|
||||
@@ -41,7 +41,7 @@ class CHMInput(InputFormatPlugin):
|
||||
|
||||
log.debug('Processing CHM...')
|
||||
with TemporaryDirectory('_chm2oeb') as tdir:
|
||||
if not isinstance(tdir, unicode_type):
|
||||
if not isinstance(tdir, str):
|
||||
tdir = tdir.decode(filesystem_encoding)
|
||||
html_input = plugin_for_input_format('html')
|
||||
for opt in html_input.options:
|
||||
@@ -129,7 +129,7 @@ class CHMInput(InputFormatPlugin):
|
||||
base = os.path.dirname(os.path.abspath(htmlpath))
|
||||
|
||||
def unquote(x):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('utf-8')
|
||||
return _unquote(x).decode('utf-8')
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from ebook_converter.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter import CurrentDir
|
||||
from ebook_converter.polyglot.builtins import unicode_type, as_bytes
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -225,15 +225,15 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
identifiers = oeb.metadata['identifier']
|
||||
uuid = None
|
||||
for x in identifiers:
|
||||
if x.get(OPF('scheme'), None).lower() == 'uuid' or unicode_type(x).startswith('urn:uuid:'):
|
||||
uuid = unicode_type(x).split(':')[-1]
|
||||
if x.get(OPF('scheme'), None).lower() == 'uuid' or str(x).startswith('urn:uuid:'):
|
||||
uuid = str(x).split(':')[-1]
|
||||
break
|
||||
encrypted_fonts = getattr(input_plugin, 'encrypted_fonts', [])
|
||||
|
||||
if uuid is None:
|
||||
self.log.warn('No UUID identifier found')
|
||||
from uuid import uuid4
|
||||
uuid = unicode_type(uuid4())
|
||||
uuid = str(uuid4())
|
||||
oeb.metadata.add('identifier', uuid, scheme='uuid', id=uuid)
|
||||
|
||||
if encrypted_fonts and not uuid.startswith('urn:uuid:'):
|
||||
@@ -241,7 +241,7 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
# for some absurd reason, or it will throw a hissy fit and refuse
|
||||
# to use the obfuscated fonts.
|
||||
for x in identifiers:
|
||||
if unicode_type(x) == uuid:
|
||||
if str(x) == uuid:
|
||||
x.content = 'urn:uuid:'+uuid
|
||||
|
||||
with TemporaryDirectory('_epub_output') as tdir:
|
||||
@@ -336,7 +336,7 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
f.write(bytes(bytearray(data[i] ^ key[i%16] for i in range(1024))))
|
||||
else:
|
||||
self.log.warn('Font', path, 'is invalid, ignoring')
|
||||
if not isinstance(uri, unicode_type):
|
||||
if not isinstance(uri, str):
|
||||
uri = uri.decode('utf-8')
|
||||
fonts.append('''
|
||||
<enc:EncryptedData>
|
||||
|
||||
@@ -10,7 +10,7 @@ from ebook_converter.customize.conversion import (InputFormatPlugin,
|
||||
from ebook_converter.utils.localization import get_lang
|
||||
from ebook_converter.utils.filenames import ascii_filename
|
||||
from ebook_converter.utils.imghdr import what
|
||||
from ebook_converter.polyglot.builtins import unicode_type, getcwd, as_unicode
|
||||
from ebook_converter.polyglot.builtins import getcwd, as_unicode
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -135,7 +135,7 @@ class HTMLInput(InputFormatPlugin):
|
||||
if not metadata.title:
|
||||
oeb.logger.warn('Title not specified')
|
||||
metadata.add('title', self.oeb.translate(__('Unknown')))
|
||||
bookid = unicode_type(uuid.uuid4())
|
||||
bookid = str(uuid.uuid4())
|
||||
metadata.add('identifier', bookid, id='uuid_id', scheme='uuid')
|
||||
for ident in metadata.identifier:
|
||||
if 'id' in ident.attrib:
|
||||
@@ -225,7 +225,7 @@ class HTMLInput(InputFormatPlugin):
|
||||
|
||||
def link_to_local_path(self, link_, base=None):
|
||||
from ebook_converter.ebooks.html.input import Link
|
||||
if not isinstance(link_, unicode_type):
|
||||
if not isinstance(link_, str):
|
||||
try:
|
||||
link_ = link_.decode('utf-8', 'error')
|
||||
except:
|
||||
@@ -288,7 +288,7 @@ class HTMLInput(InputFormatPlugin):
|
||||
# bhref refers to an already existing file. The read() method of
|
||||
# DirContainer will call unquote on it before trying to read the
|
||||
# file, therefore we quote it here.
|
||||
if isinstance(bhref, unicode_type):
|
||||
if isinstance(bhref, str):
|
||||
bhref = bhref.encode('utf-8')
|
||||
item.html_input_href = as_unicode(urllib.parse.quote(bhref))
|
||||
if guessed in self.OEB_STYLES:
|
||||
|
||||
@@ -8,7 +8,6 @@ from lxml import etree
|
||||
from ebook_converter import CurrentDir
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter.ebooks.oeb.base import element
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter.ptempfile import PersistentTemporaryDirectory
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
@@ -155,7 +154,7 @@ class HTMLOutput(OutputFormatPlugin):
|
||||
toc=html_toc, meta=meta, nextLink=nextLink,
|
||||
tocUrl=tocUrl, cssLink=cssLink,
|
||||
firstContentPageLink=nextLink)
|
||||
if isinstance(t, unicode_type):
|
||||
if isinstance(t, str):
|
||||
t = t.encode('utf-8')
|
||||
f.write(t)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import os
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin, \
|
||||
OptionRecommendation
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
@@ -78,9 +77,9 @@ class HTMLZOutput(OutputFormatPlugin):
|
||||
fname = u'index'
|
||||
if opts.htmlz_title_filename:
|
||||
from ebook_converter.utils.filenames import shorten_components_to
|
||||
fname = shorten_components_to(100, (ascii_filename(unicode_type(oeb_book.metadata.title[0])),))[0]
|
||||
fname = shorten_components_to(100, (ascii_filename(str(oeb_book.metadata.title[0])),))[0]
|
||||
with open(os.path.join(tdir, fname+u'.html'), 'wb') as tf:
|
||||
if isinstance(html, unicode_type):
|
||||
if isinstance(html, str):
|
||||
html = html.encode('utf-8')
|
||||
tf.write(html)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import sys, os
|
||||
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin
|
||||
from ebook_converter.customize.conversion import OptionRecommendation
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -15,7 +14,7 @@ class LRFOptions(object):
|
||||
def __init__(self, output, opts, oeb):
|
||||
def f2s(f):
|
||||
try:
|
||||
return unicode_type(f[0])
|
||||
return str(f[0])
|
||||
except:
|
||||
return ''
|
||||
m = oeb.metadata
|
||||
@@ -29,13 +28,13 @@ class LRFOptions(object):
|
||||
self.title_sort = self.author_sort = ''
|
||||
for x in m.creator:
|
||||
if x.role == 'aut':
|
||||
self.author = unicode_type(x)
|
||||
fa = unicode_type(getattr(x, 'file_as', ''))
|
||||
self.author = str(x)
|
||||
fa = str(getattr(x, 'file_as', ''))
|
||||
if fa:
|
||||
self.author_sort = fa
|
||||
for x in m.title:
|
||||
if unicode_type(x.file_as):
|
||||
self.title_sort = unicode_type(x.file_as)
|
||||
if str(x.file_as):
|
||||
self.title_sort = str(x.file_as)
|
||||
self.freetext = f2s(m.description)
|
||||
self.category = f2s(m.subject)
|
||||
self.cover = None
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
@@ -50,7 +49,7 @@ class MOBIInput(InputFormatPlugin):
|
||||
|
||||
raw = parse_cache.pop('calibre_raw_mobi_markup', False)
|
||||
if raw:
|
||||
if isinstance(raw, unicode_type):
|
||||
if isinstance(raw, str):
|
||||
raw = raw.encode('utf-8')
|
||||
with lopen('debug-raw.html', 'wb') as f:
|
||||
f.write(raw)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from ebook_converter.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -119,7 +118,7 @@ class MOBIOutput(OutputFormatPlugin):
|
||||
if not found:
|
||||
from ebook_converter.ebooks import generate_masthead
|
||||
self.oeb.log.debug('No masthead found in manifest, generating default mastheadImage...')
|
||||
raw = generate_masthead(unicode_type(self.oeb.metadata['title'][0]))
|
||||
raw = generate_masthead(str(self.oeb.metadata['title'][0]))
|
||||
id, href = self.oeb.manifest.generate('masthead', 'masthead')
|
||||
self.oeb.manifest.add(id, href, 'image/gif', data=raw)
|
||||
self.oeb.guide.add('masthead', 'Masthead Image', href)
|
||||
@@ -163,7 +162,7 @@ class MOBIOutput(OutputFormatPlugin):
|
||||
sec.nodes.remove(a)
|
||||
|
||||
root = TOC(klass='periodical', href=self.oeb.spine[0].href,
|
||||
title=unicode_type(self.oeb.metadata.title[0]))
|
||||
title=str(self.oeb.metadata.title[0]))
|
||||
|
||||
for s in sections:
|
||||
if articles[id(s)]:
|
||||
|
||||
@@ -6,7 +6,7 @@ import glob, os
|
||||
from ebook_converter.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
@@ -190,8 +190,8 @@ class PDFOutput(OutputFormatPlugin):
|
||||
|
||||
def get_cover_data(self):
|
||||
oeb = self.oeb
|
||||
if (oeb.metadata.cover and unicode_type(oeb.metadata.cover[0]) in oeb.manifest.ids):
|
||||
cover_id = unicode_type(oeb.metadata.cover[0])
|
||||
if (oeb.metadata.cover and str(oeb.metadata.cover[0]) in oeb.manifest.ids):
|
||||
cover_id = str(oeb.metadata.cover[0])
|
||||
item = oeb.manifest.ids[cover_id]
|
||||
self.cover_data = item.data
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import os, io
|
||||
from ebook_converter.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
@@ -40,7 +39,7 @@ class PMLOutput(OutputFormatPlugin):
|
||||
|
||||
with TemporaryDirectory('_pmlz_output') as tdir:
|
||||
pmlmlizer = PMLMLizer(log)
|
||||
pml = unicode_type(pmlmlizer.extract_content(oeb_book, opts))
|
||||
pml = str(pmlmlizer.extract_content(oeb_book, opts))
|
||||
with lopen(os.path.join(tdir, 'index.pml'), 'wb') as out:
|
||||
out.write(pml.encode(opts.pml_output_encoding, 'replace'))
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import os
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter.constants import numeric_version
|
||||
from ebook_converter import walk
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -161,6 +160,6 @@ class RecipeInput(InputFormatPlugin):
|
||||
|
||||
def save_download(self, zf):
|
||||
raw = self.recipe_source
|
||||
if isinstance(raw, unicode_type):
|
||||
if isinstance(raw, str):
|
||||
raw = raw.encode('utf-8')
|
||||
zf.writestr('download.recipe', raw)
|
||||
|
||||
@@ -3,7 +3,6 @@ import os
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.utils.filenames import ascii_filename
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
@@ -73,7 +72,7 @@ class SNBInput(InputFormatPlugin):
|
||||
if d['cover'] != '':
|
||||
oeb.guide.add('cover', 'Cover', d['cover'])
|
||||
|
||||
bookid = unicode_type(uuid.uuid4())
|
||||
bookid = str(uuid.uuid4())
|
||||
oeb.metadata.add('identifier', bookid, id='uuid_id', scheme='uuid')
|
||||
for ident in oeb.metadata.identifier:
|
||||
if 'id' in ident.attrib:
|
||||
|
||||
@@ -3,7 +3,6 @@ import os
|
||||
from ebook_converter.customize.conversion import OutputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.constants import __appname__, __version__
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
@@ -73,20 +72,20 @@ class SNBOutput(OutputFormatPlugin):
|
||||
# Process Meta data
|
||||
meta = oeb_book.metadata
|
||||
if meta.title:
|
||||
title = unicode_type(meta.title[0])
|
||||
title = str(meta.title[0])
|
||||
else:
|
||||
title = ''
|
||||
authors = [unicode_type(x) for x in meta.creator if x.role == 'aut']
|
||||
authors = [str(x) for x in meta.creator if x.role == 'aut']
|
||||
if meta.publisher:
|
||||
publishers = unicode_type(meta.publisher[0])
|
||||
publishers = str(meta.publisher[0])
|
||||
else:
|
||||
publishers = ''
|
||||
if meta.language:
|
||||
lang = unicode_type(meta.language[0]).upper()
|
||||
lang = str(meta.language[0]).upper()
|
||||
else:
|
||||
lang = ''
|
||||
if meta.description:
|
||||
abstract = unicode_type(meta.description[0])
|
||||
abstract = str(meta.description[0])
|
||||
else:
|
||||
abstract = ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user