1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-13 09:03:33 +02:00

Removed polyglots unicode_type usage

This commit is contained in:
2020-04-20 19:25:28 +02:00
parent ef7e2b10be
commit 128705f258
130 changed files with 657 additions and 716 deletions

View File

@@ -6,7 +6,7 @@ from ebook_converter.customize import CatalogPlugin
from ebook_converter.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
from ebook_converter.customize.conversion import DummyReporter
from ebook_converter.ebooks.metadata import format_isbn
from ebook_converter.polyglot.builtins import string_or_bytes, unicode_type
from ebook_converter.polyglot.builtins import string_or_bytes
__license__ = 'GPL v3'
@@ -245,7 +245,7 @@ class BIBTEX(CatalogPlugin):
elif tpl_field in ['tags', 'authors'] :
tpl_field =entry[tpl_field][0]
elif tpl_field in ['id', 'series_index'] :
tpl_field = unicode_type(entry[tpl_field])
tpl_field = str(entry[tpl_field])
else :
tpl_field = entry[tpl_field]
return ascii_text(tpl_field)
@@ -264,7 +264,7 @@ class BIBTEX(CatalogPlugin):
template_citation = '%s' % re.sub(r'[\D]','', entry["isbn"])
else :
template_citation = '%s' % unicode_type(entry["id"])
template_citation = '%s' % str(entry["id"])
return bibtexclass.ValidateCitationKey(template_citation)

View File

@@ -4,7 +4,6 @@ from collections import namedtuple
from ebook_converter.customize import CatalogPlugin
from ebook_converter.library.catalogs import FIELDS
from ebook_converter.customize.conversion import DummyReporter
from ebook_converter.polyglot.builtins import unicode_type
__license__ = 'GPL v3'
@@ -152,14 +151,14 @@ class CSV_XML(CatalogPlugin):
item = '%.2g' % (item / 2)
# Convert HTML to markdown text
if isinstance(item, unicode_type):
if isinstance(item, str):
opening_tag = re.search(r'<(\w+)( |>)', item)
if opening_tag:
closing_tag = re.search(r'<\/%s>$' % opening_tag.group(1), item)
if closing_tag:
item = html2text(item)
outstr.append('"%s"' % unicode_type(item).replace('"', '""'))
outstr.append('"%s"' % str(item).replace('"', '""'))
outfile.write(','.join(outstr) + '\n')
outfile.close()
@@ -175,8 +174,8 @@ class CSV_XML(CatalogPlugin):
for field in fields:
if field.startswith('#'):
val = db.get_field(r['id'], field, index_is_id=True)
if not isinstance(val, unicode_type):
val = unicode_type(val)
if not isinstance(val, str):
val = str(val)
item = getattr(E, field.replace('#', '_'))(val)
record.append(item)
@@ -186,11 +185,11 @@ class CSV_XML(CatalogPlugin):
val = r[field]
if not val:
continue
if not isinstance(val, (bytes, unicode_type)):
if not isinstance(val, (bytes, str)):
if (fm.get(field, {}).get('datatype', None) ==
'rating' and val):
val = '%.2g' % (val / 2)
val = unicode_type(val)
val = str(val)
item = getattr(E, field)(val)
record.append(item)
@@ -219,7 +218,7 @@ class CSV_XML(CatalogPlugin):
if 'series' in fields and r['series']:
record.append(E.series(r['series'],
index=unicode_type(r['series_index'])))
index=str(r['series_index'])))
if 'cover' in fields and r['cover']:
record.append(E.cover(r['cover'].replace(os.sep, '/')))

View File

@@ -8,7 +8,6 @@ from ebook_converter.library import current_library_name
from ebook_converter.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.utils.localization import calibre_langcode_to_name, canonicalize_lang, get_lang
from ebook_converter.polyglot.builtins import unicode_type
__license__ = 'GPL v3'
@@ -395,7 +394,7 @@ class EPUB_MOBI(CatalogPlugin):
if opts.verbose:
log.info(" Begin catalog source generation (%s)" %
unicode_type(datetime.timedelta(seconds=int(time.time() - opts.start_time))))
str(datetime.timedelta(seconds=int(time.time() - opts.start_time))))
# Launch the Catalog builder
catalog = CatalogBuilder(db, opts, self, report_progress=notification)
@@ -404,7 +403,7 @@ class EPUB_MOBI(CatalogPlugin):
catalog.build_sources()
if opts.verbose:
log.info(" Completed catalog source generation (%s)\n" %
unicode_type(datetime.timedelta(seconds=int(time.time() - opts.start_time))))
str(datetime.timedelta(seconds=int(time.time() - opts.start_time))))
except (AuthorSortMismatchException, EmptyCatalogException) as e:
log.error(" *** Terminated catalog generation: %s ***" % e)
except:
@@ -497,7 +496,7 @@ class EPUB_MOBI(CatalogPlugin):
if opts.verbose:
log.info(" Catalog creation complete (%s)\n" %
unicode_type(datetime.timedelta(seconds=int(time.time() - opts.start_time))))
str(datetime.timedelta(seconds=int(time.time() - opts.start_time))))
# returns to gui2.actions.catalog:catalog_generated()
return catalog.error

View File

@@ -6,7 +6,6 @@ from ebook_converter import prepare_string_for_xml
from ebook_converter.constants import preferred_encoding
from ebook_converter.ebooks.BeautifulSoup import html5_parser
from ebook_converter.utils.html2text import html2text
from ebook_converter.polyglot.builtins import unicode_type
# Hackish - ignoring sentences ending or beginning in numbers to avoid
@@ -44,7 +43,7 @@ def comments_to_html(comments):
'''
if not comments:
return u'<p></p>'
if not isinstance(comments, unicode_type):
if not isinstance(comments, str):
comments = comments.decode(preferred_encoding, 'replace')
if comments.lstrip().startswith('<'):