mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-02-23 19:50:06 -05:00
string_or_bytes (manual)
This commit is contained in:
parent
be25741c2b
commit
e6e8d42e82
@ -34,7 +34,7 @@ from calibre.prints import debug_print
|
||||
from calibre.ptempfile import PersistentTemporaryFile, TemporaryDirectory, better_mktemp
|
||||
from calibre.utils.config_base import prefs
|
||||
from calibre.utils.date import parse_date
|
||||
from polyglot.builtins import itervalues, string_or_bytes
|
||||
from polyglot.builtins import itervalues
|
||||
|
||||
EPUB_EXT = '.epub'
|
||||
KEPUB_EXT = '.kepub'
|
||||
@ -4299,14 +4299,14 @@ class KOBOTOUCH(KOBO):
|
||||
# a string, so looking for that.
|
||||
start_subclass_extra_options = OPT_MODIFY_CSS
|
||||
debugging_title = ''
|
||||
if isinstance(settings.extra_customization[OPT_MODIFY_CSS], string_or_bytes):
|
||||
if isinstance(settings.extra_customization[OPT_MODIFY_CSS], (str, bytes)):
|
||||
debug_print("KoboTouch::migrate_old_settings - Don't have update_series option")
|
||||
settings.update_series = config.get_option('update_series').default
|
||||
settings.modify_css = config.get_option('modify_css').default
|
||||
settings.support_newer_firmware = settings.extra_customization[OPT_UPDATE_SERIES_DETAILS]
|
||||
debugging_title = settings.extra_customization[OPT_MODIFY_CSS]
|
||||
start_subclass_extra_options = OPT_MODIFY_CSS + 1
|
||||
elif isinstance(settings.extra_customization[OPT_SUPPORT_NEWER_FIRMWARE], string_or_bytes):
|
||||
elif isinstance(settings.extra_customization[OPT_SUPPORT_NEWER_FIRMWARE], (str, bytes)):
|
||||
debug_print("KoboTouch::migrate_old_settings - Don't have modify_css option")
|
||||
settings.update_series = settings.extra_customization[OPT_UPDATE_SERIES_DETAILS]
|
||||
settings.modify_css = config.get_option('modify_css').default
|
||||
|
||||
@ -18,7 +18,6 @@ from calibre.ebooks.oeb.base import XPath, barename
|
||||
from calibre.ebooks.oeb.stylizer import Style as St
|
||||
from calibre.ebooks.oeb.stylizer import Stylizer as Sz
|
||||
from calibre.utils.localization import lang_as_iso639_1
|
||||
from polyglot.builtins import string_or_bytes
|
||||
|
||||
|
||||
def lang_for_tag(tag):
|
||||
@ -546,7 +545,7 @@ class Convert:
|
||||
self.add_block_tag(tagname, html_tag, tag_style, stylizer, float_spec=float_spec)
|
||||
|
||||
for child in html_tag.iterchildren():
|
||||
if isinstance(getattr(child, 'tag', None), string_or_bytes):
|
||||
if isinstance(getattr(child, 'tag', None), (str, bytes)):
|
||||
self.process_tag(child, stylizer, float_spec=float_spec)
|
||||
else: # Comment/PI/etc.
|
||||
tail = getattr(child, 'tail', None)
|
||||
|
||||
@ -43,7 +43,7 @@ from calibre.ebooks.lrf.pylrs.pylrs import (
|
||||
TextBlock,
|
||||
)
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from polyglot.builtins import itervalues, string_or_bytes
|
||||
from polyglot.builtins import itervalues
|
||||
from polyglot.urllib import unquote, urlparse
|
||||
|
||||
'''
|
||||
@ -1129,7 +1129,7 @@ class HTMLConverter:
|
||||
ans['sidemargin'] = int((factor*int(self.current_block.blockStyle.attrs['blockwidth'])) / 2)
|
||||
|
||||
for prop in ('topskip', 'footskip', 'sidemargin'):
|
||||
if isinstance(ans[prop], string_or_bytes):
|
||||
if isinstance(ans[prop], (str, bytes)):
|
||||
ans[prop] = int(ans[prop])
|
||||
ans[prop] = max(ans[prop], 0)
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ from css_parser.css import PropertyValue
|
||||
from tinycss.fonts3 import parse_font, serialize_font_family
|
||||
|
||||
from calibre.ebooks.oeb.base import css_text
|
||||
from polyglot.builtins import iteritems, string_or_bytes
|
||||
from polyglot.builtins import iteritems
|
||||
|
||||
DEFAULTS = {'azimuth': 'center', 'background-attachment': 'scroll', # {{{
|
||||
'background-color': 'transparent', 'background-image': 'none',
|
||||
@ -129,9 +129,9 @@ def normalize_font(cssvalue, font_family_as_list=False):
|
||||
ans = {k:DEFAULTS[k] for k in composition}
|
||||
ans.update(parse_font(val))
|
||||
if font_family_as_list:
|
||||
if isinstance(ans['font-family'], string_or_bytes):
|
||||
if isinstance(ans['font-family'], (str, bytes)):
|
||||
ans['font-family'] = [x.strip() for x in ans['font-family'].split(',')]
|
||||
elif not isinstance(ans['font-family'], string_or_bytes):
|
||||
elif not isinstance(ans['font-family'], (str, bytes)):
|
||||
ans['font-family'] = serialize_font_family(ans['font-family'])
|
||||
return ans
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ from calibre.utils.date import UNDEFINED_DATE, clean_date_for_sort, now, parse_d
|
||||
from calibre.utils.icu import lower as icu_lower
|
||||
from calibre.utils.localization import _, canonicalize_lang, get_udc, lang_map
|
||||
from calibre.utils.search_query_parser import ParseException, SearchQueryParser
|
||||
from polyglot.builtins import cmp, itervalues, string_or_bytes
|
||||
from polyglot.builtins import cmp, itervalues
|
||||
|
||||
|
||||
class MetadataBackup(Thread): # {{{
|
||||
@ -824,7 +824,7 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
continue
|
||||
|
||||
if q == 'true' and matchkind == CONTAINS_MATCH:
|
||||
if isinstance(item[loc], string_or_bytes):
|
||||
if isinstance(item[loc], (str, bytes)):
|
||||
if item[loc].strip() == '':
|
||||
continue
|
||||
matches.add(item[0])
|
||||
|
||||
@ -31,7 +31,7 @@ from calibre.utils.config_base import (
|
||||
tweaks,
|
||||
)
|
||||
from calibre.utils.localization import _
|
||||
from polyglot.builtins import native_string_type, string_or_bytes
|
||||
from polyglot.builtins import native_string_type
|
||||
|
||||
# optparse uses gettext.gettext instead of _ from builtins, so we
|
||||
# monkey patch it.
|
||||
@ -200,7 +200,7 @@ class OptionParser(optparse.OptionParser):
|
||||
upper.__dict__[dest] = lower.__dict__[dest]
|
||||
|
||||
def add_option_group(self, *args, **kwargs):
|
||||
if isinstance(args[0], string_or_bytes):
|
||||
if isinstance(args[0], (str, bytes)):
|
||||
args = list(args)
|
||||
args[0] = native_string_type(args[0])
|
||||
return optparse.OptionParser.add_option_group(self, *args, **kwargs)
|
||||
|
||||
@ -14,7 +14,7 @@ from calibre.constants import cache_dir, filesystem_encoding
|
||||
from calibre.utils.icu import numeric_sort_key as sort_key
|
||||
from calibre.utils.localization import canonicalize_lang, get_lang
|
||||
from calibre.utils.serialize import msgpack_dumps, msgpack_loads
|
||||
from polyglot.builtins import iteritems, string_or_bytes
|
||||
from polyglot.builtins import iteritems
|
||||
|
||||
|
||||
def parse_localized_key(key):
|
||||
@ -195,7 +195,7 @@ def process_desktop_file(data):
|
||||
data['Icon'] = icon
|
||||
else:
|
||||
data.pop('Icon')
|
||||
if not isinstance(data.get('Icon'), string_or_bytes):
|
||||
if not isinstance(data.get('Icon'), (str, bytes)):
|
||||
data.pop('Icon', None)
|
||||
for k in ('Name', 'GenericName', 'Comment'):
|
||||
val = data.get(k)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user