mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: port uses of builtin functions that were changed to return iterators
This commit is contained in:
parent
b8832d5a31
commit
50af7ba51f
@ -13,7 +13,7 @@ __all__ = [
|
|||||||
'git_version',
|
'git_version',
|
||||||
'develop', 'install',
|
'develop', 'install',
|
||||||
'kakasi', 'coffee', 'rapydscript', 'cacerts', 'recent_uas', 'resources',
|
'kakasi', 'coffee', 'rapydscript', 'cacerts', 'recent_uas', 'resources',
|
||||||
'check', 'to3', 'unicode_check', 'test',
|
'check', 'to3', 'unicode_check', 'iterators_check', 'test',
|
||||||
'sdist', 'bootstrap',
|
'sdist', 'bootstrap',
|
||||||
'manual', 'tag_release',
|
'manual', 'tag_release',
|
||||||
'upload_to_server',
|
'upload_to_server',
|
||||||
@ -55,9 +55,10 @@ gui = GUI()
|
|||||||
|
|
||||||
from setup.check import Check
|
from setup.check import Check
|
||||||
check = Check()
|
check = Check()
|
||||||
from setup.port import To3, UnicodeCheck
|
from setup.port import To3, UnicodeCheck, IteratorsCheck
|
||||||
to3 = To3()
|
to3 = To3()
|
||||||
unicode_check = UnicodeCheck()
|
unicode_check = UnicodeCheck()
|
||||||
|
iterators_check = IteratorsCheck()
|
||||||
|
|
||||||
from setup.test import Test
|
from setup.test import Test
|
||||||
test = Test()
|
test = Test()
|
||||||
|
@ -131,6 +131,12 @@ class To3(Base):
|
|||||||
return re.search(r'^RefactoringTool: No changes to ' + f, output, flags=re.M) is None
|
return re.search(r'^RefactoringTool: No changes to ' + f, output, flags=re.M) is None
|
||||||
|
|
||||||
|
|
||||||
|
def edit_file(f):
|
||||||
|
subprocess.Popen([
|
||||||
|
'vim', '-S', os.path.join(Command.SRC, '../session.vim'), '-f', f
|
||||||
|
]).wait()
|
||||||
|
|
||||||
|
|
||||||
class UnicodeCheck(Base):
|
class UnicodeCheck(Base):
|
||||||
|
|
||||||
description = 'Check for unicode porting status'
|
description = 'Check for unicode porting status'
|
||||||
@ -169,9 +175,63 @@ class UnicodeCheck(Base):
|
|||||||
return self.get_error_statement(f) is not None
|
return self.get_error_statement(f) is not None
|
||||||
|
|
||||||
def report_file_error(self, f, num_left):
|
def report_file_error(self, f, num_left):
|
||||||
subprocess.Popen([
|
edit_file(f)
|
||||||
'vim', '-S', os.path.join(self.SRC, '../session.vim'), '-f', f
|
self.info('%d files left to check' % num_left)
|
||||||
]).wait()
|
|
||||||
if self.file_has_errors(f):
|
if self.file_has_errors(f):
|
||||||
raise SystemExit(self.get_error_statement(f))
|
raise SystemExit(self.get_error_statement(f))
|
||||||
|
|
||||||
|
|
||||||
|
def has_import(text, module, name):
|
||||||
|
pat = re.compile(r'^from\s+{}\s+import\s+.*\b{}\b'.format(module, name), re.MULTILINE)
|
||||||
|
if pat.search(text) is not None:
|
||||||
|
return True
|
||||||
|
pat = re.compile(r'^from\s+{}\s+import\s+\([^)]*\b{}\b'.format(module, name), re.MULTILINE | re.DOTALL)
|
||||||
|
if pat.search(text) is not None:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class IteratorsCheck(Base):
|
||||||
|
|
||||||
|
description = 'Check for builtins changed to return iterators porting status'
|
||||||
|
CACHE = 'check_iterators.json'
|
||||||
|
|
||||||
|
def get_errors_in_file(self, f):
|
||||||
|
pat = re.compile(r'\b(range|map|filter|zip)\(')
|
||||||
|
text = open(f, 'rb').read().decode('utf-8')
|
||||||
|
matches = tuple(pat.finditer(text))
|
||||||
|
if not matches:
|
||||||
|
return []
|
||||||
|
ans = []
|
||||||
|
names = {m.group(1) for m in matches}
|
||||||
|
imported_names = {n for n in names if has_import(text, 'polyglot.builtins', n)}
|
||||||
|
safe_funcs = 'list|tuple|set|frozenset|join'
|
||||||
|
func_pat = r'({})\('.format(safe_funcs)
|
||||||
|
for_pat = re.compile(r'\bfor\s+.+?\s+\bin\b')
|
||||||
|
for i, line in enumerate(text.splitlines()):
|
||||||
|
m = pat.search(line)
|
||||||
|
if m is not None:
|
||||||
|
itname = m.group(1)
|
||||||
|
if itname in imported_names:
|
||||||
|
continue
|
||||||
|
start = m.start()
|
||||||
|
if start > 0:
|
||||||
|
if line[start-1] == '*':
|
||||||
|
continue
|
||||||
|
if line[start-1] == '(':
|
||||||
|
if re.search(func_pat + itname, line) is not None:
|
||||||
|
continue
|
||||||
|
fm = for_pat.search(line)
|
||||||
|
if fm is not None and fm.start() < start:
|
||||||
|
continue
|
||||||
|
ans.append('%s:%s' % (i, itname))
|
||||||
|
return ans
|
||||||
|
|
||||||
|
def file_has_errors(self, f):
|
||||||
|
return bool(self.get_errors_in_file(f))
|
||||||
|
|
||||||
|
def report_file_error(self, f, num_left):
|
||||||
|
edit_file(f)
|
||||||
self.info('%d files left to check' % num_left)
|
self.info('%d files left to check' % num_left)
|
||||||
|
if self.file_has_errors(f):
|
||||||
|
raise SystemExit('\n'.join(self.get_errors_in_file(f)))
|
||||||
|
@ -13,7 +13,7 @@ from calibre import prints
|
|||||||
from calibre.db.cli.utils import str_width
|
from calibre.db.cli.utils import str_width
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
from calibre.utils.date import isoformat
|
from calibre.utils.date import isoformat
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, map
|
||||||
|
|
||||||
readonly = True
|
readonly = True
|
||||||
version = 0 # change this if you change signature of implementation()
|
version = 0 # change this if you change signature of implementation()
|
||||||
@ -183,7 +183,7 @@ def do_list(
|
|||||||
if not screen_width:
|
if not screen_width:
|
||||||
screen_width = 80
|
screen_width = 80
|
||||||
field_width = screen_width // len(fields)
|
field_width = screen_width // len(fields)
|
||||||
base_widths = map(lambda x: min(x + 1, field_width), widths)
|
base_widths = list(map(lambda x: min(x + 1, field_width), widths))
|
||||||
|
|
||||||
while sum(base_widths) < screen_width:
|
while sum(base_widths) < screen_width:
|
||||||
adjusted = False
|
adjusted = False
|
||||||
|
@ -10,7 +10,7 @@ from textwrap import TextWrapper
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
|
|
||||||
readonly = True
|
readonly = True
|
||||||
version = 0 # change this if you change signature of implementation()
|
version = 0 # change this if you change signature of implementation()
|
||||||
@ -86,7 +86,7 @@ def do_list(fields, data, opts):
|
|||||||
if not screen_width:
|
if not screen_width:
|
||||||
screen_width = 80
|
screen_width = 80
|
||||||
field_width = screen_width // len(fields)
|
field_width = screen_width // len(fields)
|
||||||
base_widths = map(lambda x: min(x + 1, field_width), widths)
|
base_widths = list(map(lambda x: min(x + 1, field_width), widths))
|
||||||
|
|
||||||
while sum(base_widths) < screen_width:
|
while sum(base_widths) < screen_width:
|
||||||
adjusted = False
|
adjusted = False
|
||||||
@ -107,7 +107,7 @@ def do_list(fields, data, opts):
|
|||||||
with ColoredStream(sys.stdout, fg='green'):
|
with ColoredStream(sys.stdout, fg='green'):
|
||||||
prints(''.join(titles))
|
prints(''.join(titles))
|
||||||
|
|
||||||
wrappers = map(lambda x: TextWrapper(x - 1), widths)
|
wrappers = list(map(lambda x: TextWrapper(x - 1), widths))
|
||||||
|
|
||||||
for record in data:
|
for record in data:
|
||||||
text = [
|
text = [
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
|
from polyglot.builtins import map
|
||||||
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
eaw = unicodedata.east_asian_width
|
eaw = unicodedata.east_asian_width
|
||||||
|
@ -13,7 +13,7 @@ from operator import itemgetter
|
|||||||
|
|
||||||
from calibre.library.field_metadata import fm_as_dict
|
from calibre.library.field_metadata import fm_as_dict
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
from polyglot.builtins import iteritems, range
|
from polyglot.builtins import iteritems, range, zip
|
||||||
from polyglot import reprlib
|
from polyglot import reprlib
|
||||||
|
|
||||||
# Utils {{{
|
# Utils {{{
|
||||||
|
@ -8,6 +8,7 @@ Device drivers.
|
|||||||
|
|
||||||
import sys, time, pprint
|
import sys, time, pprint
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from polyglot.builtins import zip
|
||||||
|
|
||||||
DAY_MAP = dict(Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6)
|
DAY_MAP = dict(Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6)
|
||||||
MONTH_MAP = dict(Jan=1, Feb=2, Mar=3, Apr=4, May=5, Jun=6, Jul=7, Aug=8, Sep=9, Oct=10, Nov=11, Dec=12)
|
MONTH_MAP = dict(Jan=1, Feb=2, Mar=3, Apr=4, May=5, Jun=6, Jul=7, Aug=8, Sep=9, Oct=10, Nov=11, Dec=12)
|
||||||
|
@ -14,7 +14,7 @@ import sys
|
|||||||
|
|
||||||
from calibre.devices.usbms.driver import USBMS
|
from calibre.devices.usbms.driver import USBMS
|
||||||
from calibre.ebooks.metadata import string_to_authors
|
from calibre.ebooks.metadata import string_to_authors
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class JETBOOK(USBMS):
|
class JETBOOK(USBMS):
|
||||||
@ -79,7 +79,7 @@ class JETBOOK(USBMS):
|
|||||||
if match is not None:
|
if match is not None:
|
||||||
mi.title = check_unicode(match.group('title'))
|
mi.title = check_unicode(match.group('title'))
|
||||||
authors = string_to_authors(match.group('authors'))
|
authors = string_to_authors(match.group('authors'))
|
||||||
mi.authors = map(check_unicode, authors)
|
mi.authors = list(map(check_unicode, authors))
|
||||||
|
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ from calibre.ebooks.chardet import xml_to_unicode
|
|||||||
from calibre.ebooks.metadata import authors_to_string, title_sort, \
|
from calibre.ebooks.metadata import authors_to_string, title_sort, \
|
||||||
authors_to_sort_string
|
authors_to_sort_string
|
||||||
from polyglot.binary import from_base64_bytes
|
from polyglot.binary import from_base64_bytes
|
||||||
|
from polyglot.builtins import zip
|
||||||
|
|
||||||
'''
|
'''
|
||||||
cahceExt.xml
|
cahceExt.xml
|
||||||
|
@ -23,7 +23,7 @@ from calibre.devices.errors import DeviceError
|
|||||||
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
from calibre.devices.usbms.deviceconfig import DeviceConfig
|
||||||
from calibre.constants import iswindows, islinux, isosx, isfreebsd, plugins
|
from calibre.constants import iswindows, islinux, isosx, isfreebsd, plugins
|
||||||
from calibre.utils.filenames import ascii_filename as sanitize
|
from calibre.utils.filenames import ascii_filename as sanitize
|
||||||
from polyglot.builtins import iteritems, string_or_bytes
|
from polyglot.builtins import iteritems, string_or_bytes, map
|
||||||
|
|
||||||
if isosx:
|
if isosx:
|
||||||
usbobserver, usbobserver_err = plugins['usbobserver']
|
usbobserver, usbobserver_err = plugins['usbobserver']
|
||||||
@ -355,7 +355,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
g = m.groupdict()
|
g = m.groupdict()
|
||||||
if g['p'] is None:
|
if g['p'] is None:
|
||||||
g['p'] = 0
|
g['p'] = 0
|
||||||
return map(int, (g.get('m'), g.get('p')))
|
return list(map(int, (g.get('m'), g.get('p'))))
|
||||||
|
|
||||||
def cmp_key(x):
|
def cmp_key(x):
|
||||||
'''
|
'''
|
||||||
|
@ -20,7 +20,7 @@ from calibre.devices.usbms.cli import CLI
|
|||||||
from calibre.devices.usbms.device import Device
|
from calibre.devices.usbms.device import Device
|
||||||
from calibre.devices.usbms.books import BookList, Book
|
from calibre.devices.usbms.books import BookList, Book
|
||||||
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
from calibre.ebooks.metadata.book.json_codec import JsonCodec
|
||||||
from polyglot.builtins import itervalues, unicode_type, string_or_bytes
|
from polyglot.builtins import itervalues, unicode_type, string_or_bytes, zip
|
||||||
|
|
||||||
BASE_TIME = None
|
BASE_TIME = None
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ class USBMS(CLI, Device):
|
|||||||
|
|
||||||
self.report_progress(1.0, _('Transferring books to device...'))
|
self.report_progress(1.0, _('Transferring books to device...'))
|
||||||
debug_print('USBMS: finished uploading %d books'%(len(files)))
|
debug_print('USBMS: finished uploading %d books'%(len(files)))
|
||||||
return zip(paths, cycle([on_card]))
|
return list(zip(paths, cycle([on_card])))
|
||||||
|
|
||||||
def upload_cover(self, path, filename, metadata, filepath):
|
def upload_cover(self, path, filename, metadata, filepath):
|
||||||
'''
|
'''
|
||||||
|
@ -15,7 +15,7 @@ from calibre.ptempfile import PersistentTemporaryDirectory
|
|||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from calibre.utils.ipc.server import Server
|
from calibre.utils.ipc.server import Server
|
||||||
from calibre.utils.ipc.job import ParallelJob
|
from calibre.utils.ipc.job import ParallelJob
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
from polyglot.queue import Empty
|
from polyglot.queue import Empty
|
||||||
|
|
||||||
# If the specified screen has either dimension larger than this value, no image
|
# If the specified screen has either dimension larger than this value, no image
|
||||||
|
@ -12,7 +12,7 @@ import shutil, textwrap, codecs, os
|
|||||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from polyglot.builtins import getcwd
|
from polyglot.builtins import getcwd, map
|
||||||
|
|
||||||
|
|
||||||
class ComicInput(InputFormatPlugin):
|
class ComicInput(InputFormatPlugin):
|
||||||
|
@ -12,7 +12,7 @@ from calibre.customize.conversion import (OutputFormatPlugin,
|
|||||||
OptionRecommendation)
|
OptionRecommendation)
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
from polyglot.builtins import unicode_type, filter
|
from polyglot.builtins import unicode_type, filter, map, zip
|
||||||
|
|
||||||
block_level_tags = (
|
block_level_tags = (
|
||||||
'address',
|
'address',
|
||||||
|
@ -18,7 +18,7 @@ from calibre.utils.zipfile import ZipFile
|
|||||||
from calibre import (extract, walk, isbytestring, filesystem_encoding,
|
from calibre import (extract, walk, isbytestring, filesystem_encoding,
|
||||||
get_types_map)
|
get_types_map)
|
||||||
from calibre.constants import __version__
|
from calibre.constants import __version__
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes, map
|
||||||
|
|
||||||
DEBUG_README=u'''
|
DEBUG_README=u'''
|
||||||
This debug directory contains snapshots of the e-book as it passes through the
|
This debug directory contains snapshots of the e-book as it passes through the
|
||||||
@ -1172,7 +1172,7 @@ OptionRecommendation(name='search_replace',
|
|||||||
fkey = self.opts.dest.fkey
|
fkey = self.opts.dest.fkey
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
fkey = map(float, fkey.split(','))
|
fkey = list(map(float, fkey.split(',')))
|
||||||
except:
|
except:
|
||||||
self.log.error('Invalid font size key: %r ignoring'%fkey)
|
self.log.error('Invalid font size key: %r ignoring'%fkey)
|
||||||
fkey = self.opts.dest.fkey
|
fkey = self.opts.dest.fkey
|
||||||
|
@ -29,7 +29,7 @@ from calibre.ebooks.docx.fields import Fields
|
|||||||
from calibre.ebooks.docx.settings import Settings
|
from calibre.ebooks.docx.settings import Settings
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||||
from polyglot.builtins import iteritems, itervalues, filter, getcwd
|
from polyglot.builtins import iteritems, itervalues, filter, getcwd, map
|
||||||
|
|
||||||
|
|
||||||
NBSP = '\xa0'
|
NBSP = '\xa0'
|
||||||
@ -183,7 +183,7 @@ class Convert(object):
|
|||||||
indent = float(style.text_indent[:-2]) + indent
|
indent = float(style.text_indent[:-2]) + indent
|
||||||
style.text_indent = '%.3gpt' % indent
|
style.text_indent = '%.3gpt' % indent
|
||||||
parent.text = tabs[-1].tail or ''
|
parent.text = tabs[-1].tail or ''
|
||||||
map(parent.remove, tabs)
|
list(map(parent.remove, tabs))
|
||||||
|
|
||||||
self.images.rid_map = orig_rid_map
|
self.images.rid_map = orig_rid_map
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.date import utcnow
|
|||||||
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
from calibre.ebooks.pdf.render.common import PAPER_SIZES
|
from calibre.ebooks.pdf.render.common import PAPER_SIZES
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems, map
|
||||||
|
|
||||||
|
|
||||||
def xml2str(root, pretty_print=False, with_tail=False):
|
def xml2str(root, pretty_print=False, with_tail=False):
|
||||||
|
@ -12,7 +12,7 @@ from copy import deepcopy, copy
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
from polyglot.builtins import as_bytes
|
from polyglot.builtins import as_bytes, map
|
||||||
|
|
||||||
|
|
||||||
class Canvas(etree.XSLTExtension):
|
class Canvas(etree.XSLTExtension):
|
||||||
|
@ -14,7 +14,7 @@ from calibre.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
|||||||
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from polyglot.builtins import iteritems, unicode_type, filter
|
from polyglot.builtins import iteritems, unicode_type, filter, map
|
||||||
|
|
||||||
# Special sets used to optimize the performance of getting and setting
|
# Special sets used to optimize the performance of getting and setting
|
||||||
# attributes on Metadata objects
|
# attributes on Metadata objects
|
||||||
|
@ -207,8 +207,9 @@ class Ozon(Source):
|
|||||||
title = type(u'')(title).upper() if title else ''
|
title = type(u'')(title).upper() if title else ''
|
||||||
if reRemoveFromTitle:
|
if reRemoveFromTitle:
|
||||||
title = reRemoveFromTitle.sub('', title)
|
title = reRemoveFromTitle.sub('', title)
|
||||||
authors = map(_normalizeAuthorNameWithInitials,
|
authors = [
|
||||||
map(type(u'').upper, map(type(u''), authors))) if authors else None
|
_normalizeAuthorNameWithInitials(type(u'')(a).upper()) for a in authors
|
||||||
|
] if authors else None
|
||||||
|
|
||||||
ozon_id = identifiers.get('ozon', None)
|
ozon_id = identifiers.get('ozon', None)
|
||||||
# log.debug(u'ozonid: ', ozon_id)
|
# log.debug(u'ozonid: ', ozon_id)
|
||||||
@ -246,7 +247,7 @@ class Ozon(Source):
|
|||||||
relevance += 1
|
relevance += 1
|
||||||
|
|
||||||
if authors:
|
if authors:
|
||||||
miauthors = map(type(u'').upper, map(type(u''), mi.authors)) if mi.authors else []
|
miauthors = [type(u'')(a).upper() for a in mi.authors or ()]
|
||||||
# log.debug('Authors %s vs miauthors %s'%(','.join(authors), ','.join(miauthors)))
|
# log.debug('Authors %s vs miauthors %s'%(','.join(authors), ','.join(miauthors)))
|
||||||
|
|
||||||
if (in_authors(authors, miauthors)):
|
if (in_authors(authors, miauthors)):
|
||||||
@ -332,7 +333,7 @@ class Ozon(Source):
|
|||||||
author = type(u'')(entry.xpath(u'normalize-space(.//div[contains(@class, "mPerson")])'))
|
author = type(u'')(entry.xpath(u'normalize-space(.//div[contains(@class, "mPerson")])'))
|
||||||
# log.debug(u'Author: -----> %s' % author)
|
# log.debug(u'Author: -----> %s' % author)
|
||||||
|
|
||||||
norm_authors = map(_normalizeAuthorNameWithInitials, map(type(u'').strip, type(u'')(author).split(u',')))
|
norm_authors = [_normalizeAuthorNameWithInitials(a.strip()) for a in type(u'')(author).split(u',')]
|
||||||
mi = Metadata(title, norm_authors)
|
mi = Metadata(title, norm_authors)
|
||||||
|
|
||||||
ozon_id = entry.get('data-href').split('/')[-2]
|
ozon_id = entry.get('data-href').split('/')[-2]
|
||||||
|
@ -128,8 +128,7 @@ def wayback_url_processor(url):
|
|||||||
|
|
||||||
def ddg_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60):
|
def ddg_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60):
|
||||||
# https://duck.co/help/results/syntax
|
# https://duck.co/help/results/syntax
|
||||||
terms = map(ddg_term, terms)
|
terms = [quote_term(ddg_term(t)) for t in terms]
|
||||||
terms = [quote_term(t) for t in terms]
|
|
||||||
if site is not None:
|
if site is not None:
|
||||||
terms.append(quote_term(('site:' + site)))
|
terms.append(quote_term(('site:' + site)))
|
||||||
q = '+'.join(terms)
|
q = '+'.join(terms)
|
||||||
@ -170,8 +169,7 @@ def bing_url_processor(url):
|
|||||||
|
|
||||||
def bing_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60):
|
def bing_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60):
|
||||||
# http://vlaurie.com/computers2/Articles/bing_advanced_search.htm
|
# http://vlaurie.com/computers2/Articles/bing_advanced_search.htm
|
||||||
terms = map(bing_term, terms)
|
terms = [quote_term(bing_term(t)) for t in terms]
|
||||||
terms = [quote_term(t) for t in terms]
|
|
||||||
if site is not None:
|
if site is not None:
|
||||||
terms.append(quote_term(('site:' + site)))
|
terms.append(quote_term(('site:' + site)))
|
||||||
q = '+'.join(terms)
|
q = '+'.join(terms)
|
||||||
@ -226,8 +224,7 @@ def google_url_processor(url):
|
|||||||
|
|
||||||
|
|
||||||
def google_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60):
|
def google_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60):
|
||||||
terms = map(google_term, terms)
|
terms = [quote_term(google_term(t)) for t in terms]
|
||||||
terms = [quote_term(t) for t in terms]
|
|
||||||
if site is not None:
|
if site is not None:
|
||||||
terms.append(quote_term(('site:' + site)))
|
terms.append(quote_term(('site:' + site)))
|
||||||
q = '+'.join(terms)
|
q = '+'.join(terms)
|
||||||
|
@ -12,7 +12,7 @@ from collections import OrderedDict, namedtuple
|
|||||||
|
|
||||||
from calibre.ebooks.mobi.utils import (decint, count_set_bits,
|
from calibre.ebooks.mobi.utils import (decint, count_set_bits,
|
||||||
decode_string)
|
decode_string)
|
||||||
from polyglot.builtins import iteritems, range
|
from polyglot.builtins import iteritems, range, zip
|
||||||
|
|
||||||
TagX = namedtuple('TagX', 'tag num_of_values bitmask eof')
|
TagX = namedtuple('TagX', 'tag num_of_values bitmask eof')
|
||||||
PTagX = namedtuple('PTagX', 'tag value_count value_bytes num_of_values')
|
PTagX = namedtuple('PTagX', 'tag value_count value_bytes num_of_values')
|
||||||
|
@ -23,7 +23,7 @@ from calibre.ebooks.metadata.toc import TOC
|
|||||||
from calibre.ebooks.mobi.reader.headers import BookHeader
|
from calibre.ebooks.mobi.reader.headers import BookHeader
|
||||||
from calibre.utils.img import save_cover_data_to
|
from calibre.utils.img import save_cover_data_to
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from polyglot.builtins import iteritems, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range, map
|
||||||
|
|
||||||
|
|
||||||
class TopazError(ValueError):
|
class TopazError(ValueError):
|
||||||
|
@ -14,7 +14,7 @@ from io import BytesIO
|
|||||||
from calibre.utils.img import save_cover_data_to, scale_image, image_to_data, image_from_data, resize_image
|
from calibre.utils.img import save_cover_data_to, scale_image, image_to_data, image_from_data, resize_image
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from calibre.ebooks import normalize
|
from calibre.ebooks import normalize
|
||||||
from polyglot.builtins import unicode_type, range, as_bytes
|
from polyglot.builtins import unicode_type, range, as_bytes, map
|
||||||
from tinycss.color3 import parse_color_string
|
from tinycss.color3 import parse_color_string
|
||||||
|
|
||||||
IMAGE_MAX_SIZE = 10 * 1024 * 1024
|
IMAGE_MAX_SIZE = 10 * 1024 * 1024
|
||||||
|
@ -14,7 +14,7 @@ from lxml import etree, html
|
|||||||
from calibre import xml_replace_entities, force_unicode
|
from calibre import xml_replace_entities, force_unicode
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
from calibre.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||||
from polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes
|
from polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes, map
|
||||||
|
|
||||||
RECOVER_PARSER = etree.XMLParser(recover=True, no_network=True)
|
RECOVER_PARSER = etree.XMLParser(recover=True, no_network=True)
|
||||||
XHTML_NS = 'http://www.w3.org/1999/xhtml'
|
XHTML_NS = 'http://www.w3.org/1999/xhtml'
|
||||||
@ -65,7 +65,7 @@ def merge_multiple_html_heads_and_bodies(root, log=None):
|
|||||||
for b in bodies:
|
for b in bodies:
|
||||||
for x in b:
|
for x in b:
|
||||||
body.append(x)
|
body.append(x)
|
||||||
map(root.append, (head, body))
|
tuple(map(root.append, (head, body)))
|
||||||
if log is not None:
|
if log is not None:
|
||||||
log.warn('Merging multiple <head> and <body> sections')
|
log.warn('Merging multiple <head> and <body> sections')
|
||||||
return root
|
return root
|
||||||
|
@ -14,7 +14,7 @@ import time
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
import uuid
|
import uuid
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from polyglot.builtins import iteritems, unicode_type, zip, as_bytes
|
from polyglot.builtins import iteritems, unicode_type, zip, as_bytes, map
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
|
||||||
@ -801,7 +801,7 @@ class Container(ContainerBase): # {{{
|
|||||||
imap = {name:item_id for item_id, name in iteritems(imap)}
|
imap = {name:item_id for item_id, name in iteritems(imap)}
|
||||||
items = [item for item, name, linear in self.spine_iter]
|
items = [item for item, name, linear in self.spine_iter]
|
||||||
tail, last_tail = (items[0].tail, items[-1].tail) if items else ('\n ', '\n ')
|
tail, last_tail = (items[0].tail, items[-1].tail) if items else ('\n ', '\n ')
|
||||||
map(self.remove_from_xml, items)
|
tuple(map(self.remove_from_xml, items))
|
||||||
spine = self.opf_xpath('//opf:spine')[0]
|
spine = self.opf_xpath('//opf:spine')[0]
|
||||||
spine.text = tail
|
spine.text = tail
|
||||||
for name, linear in spine_items:
|
for name, linear in spine_items:
|
||||||
|
@ -10,6 +10,7 @@ import re, os
|
|||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
|
|
||||||
from calibre import guess_type as _guess_type, replace_entities
|
from calibre import guess_type as _guess_type, replace_entities
|
||||||
|
from polyglot.builtins import filter
|
||||||
|
|
||||||
|
|
||||||
def guess_type(x):
|
def guess_type(x):
|
||||||
|
@ -21,7 +21,7 @@ from calibre.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYLES,
|
|||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.utils.filenames import ascii_filename, ascii_text
|
from calibre.utils.filenames import ascii_filename, ascii_text
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, map
|
||||||
|
|
||||||
COLLAPSE = re.compile(r'[ \t\r\n\v]+')
|
COLLAPSE = re.compile(r'[ \t\r\n\v]+')
|
||||||
STRIPNUM = re.compile(r'[-0-9]+$')
|
STRIPNUM = re.compile(r'[-0-9]+$')
|
||||||
|
@ -21,7 +21,7 @@ from calibre.utils.date import is_date_undefined, as_local_time
|
|||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.ebooks.chardet import strip_encoding_declarations
|
from calibre.ebooks.chardet import strip_encoding_declarations
|
||||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
|
|
||||||
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
||||||
|
|
||||||
@ -104,8 +104,8 @@ class Jacket(Base):
|
|||||||
self.log('Inserting metadata into book...')
|
self.log('Inserting metadata into book...')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tags = map(unicode_type, self.oeb.metadata.subject)
|
tags = list(map(unicode_type, self.oeb.metadata.subject))
|
||||||
except:
|
except Exception:
|
||||||
tags = []
|
tags = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -9,7 +9,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os, re
|
import os, re
|
||||||
from calibre.utils.date import isoformat, now
|
from calibre.utils.date import isoformat, now
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, filter
|
||||||
|
filter
|
||||||
|
|
||||||
|
|
||||||
def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
|
def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
|
||||||
|
@ -20,7 +20,7 @@ from calibre.ebooks.epub import rules
|
|||||||
from calibre.ebooks.oeb.base import (OEB_STYLES, XPNSMAP as NAMESPACES,
|
from calibre.ebooks.oeb.base import (OEB_STYLES, XPNSMAP as NAMESPACES,
|
||||||
urldefrag, rewrite_links, urlunquote, XHTML, urlnormalize)
|
urldefrag, rewrite_links, urlunquote, XHTML, urlnormalize)
|
||||||
from calibre.ebooks.oeb.polish.split import do_split
|
from calibre.ebooks.oeb.polish.split import do_split
|
||||||
from polyglot.builtins import iteritems, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range, map
|
||||||
from css_selectors import Select, SelectorError
|
from css_selectors import Select, SelectorError
|
||||||
|
|
||||||
XPath = functools.partial(_XPath, namespaces=NAMESPACES)
|
XPath = functools.partial(_XPath, namespaces=NAMESPACES)
|
||||||
|
@ -18,7 +18,7 @@ from calibre.ebooks import DRMError
|
|||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from calibre.ebooks.pdb.ereader import EreaderError
|
from calibre.ebooks.pdb.ereader import EreaderError
|
||||||
from calibre.ebooks.pdb.formatreader import FormatReader
|
from calibre.ebooks.pdb.formatreader import FormatReader
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
class HeaderRecord(object):
|
class HeaderRecord(object):
|
||||||
@ -99,7 +99,7 @@ class Reader132(FormatReader):
|
|||||||
assumed to be encoded as Windows-1252. The encoding is part of
|
assumed to be encoded as Windows-1252. The encoding is part of
|
||||||
the eReader file spec and should always be this encoding.
|
the eReader file spec and should always be this encoding.
|
||||||
'''
|
'''
|
||||||
if number not in range(1, self.header_record.num_text_pages + 1):
|
if not (1 <= number <= self.header_record.num_text_pages):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return self.decompress_text(number)
|
return self.decompress_text(number)
|
||||||
|
@ -14,7 +14,7 @@ from calibre import CurrentDir
|
|||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from calibre.ebooks.pdb.formatreader import FormatReader
|
from calibre.ebooks.pdb.formatreader import FormatReader
|
||||||
from calibre.ebooks.pdb.ereader import EreaderError
|
from calibre.ebooks.pdb.ereader import EreaderError
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
class HeaderRecord(object):
|
class HeaderRecord(object):
|
||||||
@ -76,7 +76,7 @@ class Reader202(FormatReader):
|
|||||||
assumed to be encoded as Windows-1252. The encoding is part of
|
assumed to be encoded as Windows-1252. The encoding is part of
|
||||||
the eReader file spec and should always be this encoding.
|
the eReader file spec and should always be this encoding.
|
||||||
'''
|
'''
|
||||||
if number not in range(1, self.header_record.num_text_pages + 1):
|
if not (1 <= number <= self.header_record.num_text_pages):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return self.decompress_text(number)
|
return self.decompress_text(number)
|
||||||
|
@ -16,6 +16,7 @@ from calibre import prepare_string_for_xml
|
|||||||
from calibre.ebooks.pdb.formatreader import FormatReader
|
from calibre.ebooks.pdb.formatreader import FormatReader
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ebooks.txt.processor import opf_writer, HTML_TEMPLATE
|
from calibre.ebooks.txt.processor import opf_writer, HTML_TEMPLATE
|
||||||
|
from polyglot.builtins import range, map
|
||||||
|
|
||||||
BPDB_IDENT = b'BOOKMTIT'
|
BPDB_IDENT = b'BOOKMTIT'
|
||||||
UPDB_IDENT = b'BOOKMTIU'
|
UPDB_IDENT = b'BOOKMTIU'
|
||||||
@ -62,9 +63,9 @@ class LegacyHeaderRecord(object):
|
|||||||
fields = raw.lstrip().replace(b'\x1b\x1b\x1b', b'\x1b').split(b'\x1b')
|
fields = raw.lstrip().replace(b'\x1b\x1b\x1b', b'\x1b').split(b'\x1b')
|
||||||
self.title = fix_punct(fields[0].decode('cp950', 'replace'))
|
self.title = fix_punct(fields[0].decode('cp950', 'replace'))
|
||||||
self.num_records = int(fields[1])
|
self.num_records = int(fields[1])
|
||||||
self.chapter_titles = map(
|
self.chapter_titles = list(map(
|
||||||
lambda x: fix_punct(x.decode('cp950', 'replace').rstrip(b'\x00')),
|
lambda x: fix_punct(x.decode('cp950', 'replace').rstrip(b'\x00')),
|
||||||
fields[2:])
|
fields[2:]))
|
||||||
|
|
||||||
|
|
||||||
class UnicodeHeaderRecord(object):
|
class UnicodeHeaderRecord(object):
|
||||||
@ -74,9 +75,9 @@ class UnicodeHeaderRecord(object):
|
|||||||
b'\x1b\x00').split(b'\x1b\x00')
|
b'\x1b\x00').split(b'\x1b\x00')
|
||||||
self.title = fix_punct(fields[0].decode('utf_16_le', 'ignore'))
|
self.title = fix_punct(fields[0].decode('utf_16_le', 'ignore'))
|
||||||
self.num_records = int(fields[1])
|
self.num_records = int(fields[1])
|
||||||
self.chapter_titles = map(
|
self.chapter_titles = list(map(
|
||||||
lambda x: fix_punct(x.decode('utf_16_le', 'replace').rstrip(b'\x00')),
|
lambda x: fix_punct(x.decode('utf_16_le', 'replace').rstrip(b'\x00')),
|
||||||
fields[2].split(b'\r\x00\n\x00'))
|
fields[2].split(b'\r\x00\n\x00')))
|
||||||
|
|
||||||
|
|
||||||
class Reader(FormatReader):
|
class Reader(FormatReader):
|
||||||
|
@ -35,7 +35,7 @@ class PdbHeaderReader(object):
|
|||||||
return re.sub(b'[^-A-Za-z0-9 ]+', b'_', self.stream.read(32).replace(b'\x00', b''))
|
return re.sub(b'[^-A-Za-z0-9 ]+', b'_', self.stream.read(32).replace(b'\x00', b''))
|
||||||
|
|
||||||
def full_section_info(self, number):
|
def full_section_info(self, number):
|
||||||
if number not in range(0, self.num_sections):
|
if not (0 <= number < self.num_sections):
|
||||||
raise ValueError('Not a valid section number %i' % number)
|
raise ValueError('Not a valid section number %i' % number)
|
||||||
|
|
||||||
self.stream.seek(78 + number * 8)
|
self.stream.seek(78 + number * 8)
|
||||||
@ -44,14 +44,14 @@ class PdbHeaderReader(object):
|
|||||||
return (offset, flags, val)
|
return (offset, flags, val)
|
||||||
|
|
||||||
def section_offset(self, number):
|
def section_offset(self, number):
|
||||||
if number not in range(0, self.num_sections):
|
if not (0 <= number < self.num_sections):
|
||||||
raise ValueError('Not a valid section number %i' % number)
|
raise ValueError('Not a valid section number %i' % number)
|
||||||
|
|
||||||
self.stream.seek(78 + number * 8)
|
self.stream.seek(78 + number * 8)
|
||||||
return struct.unpack('>LBBBB', self.stream.read(8))[0]
|
return struct.unpack('>LBBBB', self.stream.read(8))[0]
|
||||||
|
|
||||||
def section_data(self, number):
|
def section_data(self, number):
|
||||||
if number not in range(0, self.num_sections):
|
if not (0 <= number < self.num_sections):
|
||||||
raise ValueError('Not a valid section number %i' % number)
|
raise ValueError('Not a valid section number %i' % number)
|
||||||
|
|
||||||
start = self.section_offset(number)
|
start = self.section_offset(number)
|
||||||
|
@ -11,7 +11,7 @@ from itertools import count
|
|||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range, map
|
||||||
|
|
||||||
|
|
||||||
class Font(object):
|
class Font(object):
|
||||||
|
@ -16,7 +16,7 @@ import os, re
|
|||||||
from calibre.ebooks.rtf2xml import copy
|
from calibre.ebooks.rtf2xml import copy
|
||||||
from calibre.utils.mreplace import MReplace
|
from calibre.utils.mreplace import MReplace
|
||||||
from calibre.ptempfile import better_mktemp
|
from calibre.ptempfile import better_mktemp
|
||||||
from polyglot.builtins import codepoint_to_chr, range, filter
|
from polyglot.builtins import codepoint_to_chr, range, filter, map
|
||||||
from . import open_for_read, open_for_write
|
from . import open_for_read, open_for_write
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ from calibre.utils.date import UNDEFINED_DATE
|
|||||||
from calibre.utils.file_type_icons import EXT_MAP
|
from calibre.utils.file_type_icons import EXT_MAP
|
||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang
|
||||||
from polyglot.builtins import (iteritems, itervalues, unicode_type,
|
from polyglot.builtins import (iteritems, itervalues, unicode_type,
|
||||||
string_or_bytes, range)
|
string_or_bytes, range, map)
|
||||||
from polyglot import queue
|
from polyglot import queue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -321,7 +321,7 @@ def default_author_link():
|
|||||||
|
|
||||||
def available_heights():
|
def available_heights():
|
||||||
desktop = QCoreApplication.instance().desktop()
|
desktop = QCoreApplication.instance().desktop()
|
||||||
return map(lambda x: x.height(), map(desktop.availableGeometry, range(desktop.screenCount())))
|
return list(map(lambda x: x.height(), map(desktop.availableGeometry, range(desktop.screenCount()))))
|
||||||
|
|
||||||
|
|
||||||
def available_height():
|
def available_height():
|
||||||
|
@ -12,7 +12,7 @@ from calibre.gui2 import error_dialog
|
|||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
from calibre.devices.usbms.device import Device
|
from calibre.devices.usbms.device import Device
|
||||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||||
from polyglot.builtins import iteritems, range
|
from polyglot.builtins import iteritems, range, map
|
||||||
|
|
||||||
|
|
||||||
class Updater(QThread): # {{{
|
class Updater(QThread): # {{{
|
||||||
@ -76,7 +76,7 @@ class FetchAnnotationsAction(InterfaceAction):
|
|||||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||||
if not rows or len(rows) < 2:
|
if not rows or len(rows) < 2:
|
||||||
rows = range(self.gui.library_view.model().rowCount(QModelIndex()))
|
rows = range(self.gui.library_view.model().rowCount(QModelIndex()))
|
||||||
ids = map(self.gui.library_view.model().id, rows)
|
ids = list(map(self.gui.library_view.model().id, rows))
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
def get_formats(id):
|
def get_formats(id):
|
||||||
|
@ -12,7 +12,7 @@ from calibre.gui2.actions import InterfaceAction
|
|||||||
from calibre.gui2.dialogs.smartdevice import SmartdeviceDialog
|
from calibre.gui2.dialogs.smartdevice import SmartdeviceDialog
|
||||||
from calibre.utils.icu import primary_sort_key
|
from calibre.utils.icu import primary_sort_key
|
||||||
from calibre.utils.smtp import config as email_config
|
from calibre.utils.smtp import config as email_config
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class ShareConnMenu(QMenu): # {{{
|
class ShareConnMenu(QMenu): # {{{
|
||||||
@ -111,7 +111,7 @@ class ShareConnMenu(QMenu): # {{{
|
|||||||
(alias or account) + ' ' + _('(delete from library)'))
|
(alias or account) + ' ' + _('(delete from library)'))
|
||||||
self.email_to_menu.addAction(action1)
|
self.email_to_menu.addAction(action1)
|
||||||
self.email_to_and_delete_menu.addAction(action2)
|
self.email_to_and_delete_menu.addAction(action2)
|
||||||
map(self.memory.append, (action1, action2))
|
tuple(map(self.memory.append, (action1, action2)))
|
||||||
if default:
|
if default:
|
||||||
ac = DeviceAction(dest, False, False,
|
ac = DeviceAction(dest, False, False,
|
||||||
I('mail.png'), _('Email to') + ' ' +(alias or
|
I('mail.png'), _('Email to') + ' ' +(alias or
|
||||||
@ -127,7 +127,7 @@ class ShareConnMenu(QMenu): # {{{
|
|||||||
_('Select recipients') + ' ' + _('(delete from library)'))
|
_('Select recipients') + ' ' + _('(delete from library)'))
|
||||||
self.email_to_menu.addAction(action1)
|
self.email_to_menu.addAction(action1)
|
||||||
self.email_to_and_delete_menu.addAction(action2)
|
self.email_to_and_delete_menu.addAction(action2)
|
||||||
map(self.memory.append, (action1, action2))
|
tuple(map(self.memory.append, (action1, action2)))
|
||||||
tac1 = DeviceAction('choosemail:', False, False, I('mail.png'),
|
tac1 = DeviceAction('choosemail:', False, False, I('mail.png'),
|
||||||
_('Email to selected recipients...'))
|
_('Email to selected recipients...'))
|
||||||
self.addAction(tac1)
|
self.addAction(tac1)
|
||||||
|
@ -26,7 +26,7 @@ from calibre.db.errors import NoSuchFormat
|
|||||||
from calibre.library.comments import merge_comments
|
from calibre.library.comments import merge_comments
|
||||||
from calibre.ebooks.metadata.sources.prefs import msprefs
|
from calibre.ebooks.metadata.sources.prefs import msprefs
|
||||||
from calibre.gui2.actions.show_quickview import get_quickview_action_plugin
|
from calibre.gui2.actions.show_quickview import get_quickview_action_plugin
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class EditMetadataAction(InterfaceAction):
|
class EditMetadataAction(InterfaceAction):
|
||||||
@ -614,7 +614,7 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
|
|
||||||
def formats_for_books(self, rows):
|
def formats_for_books(self, rows):
|
||||||
m = self.gui.library_view.model()
|
m = self.gui.library_view.model()
|
||||||
return self.formats_for_ids(map(m.id, rows))
|
return self.formats_for_ids(list(map(m.id, rows)))
|
||||||
|
|
||||||
def books_to_merge(self, rows):
|
def books_to_merge(self, rows):
|
||||||
src_ids = []
|
src_ids = []
|
||||||
|
@ -19,7 +19,7 @@ except ImportError:
|
|||||||
from calibre.constants import isosx
|
from calibre.constants import isosx
|
||||||
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
||||||
from calibre.gui2.throbber import ThrobbingButton
|
from calibre.gui2.throbber import ThrobbingButton
|
||||||
from polyglot.builtins import itervalues, unicode_type
|
from polyglot.builtins import itervalues, unicode_type, map, range
|
||||||
|
|
||||||
|
|
||||||
class RevealBar(QWidget): # {{{
|
class RevealBar(QWidget): # {{{
|
||||||
@ -578,8 +578,7 @@ class BarsManager(QObject):
|
|||||||
QObject.__init__(self, parent)
|
QObject.__init__(self, parent)
|
||||||
self.location_manager = location_manager
|
self.location_manager = location_manager
|
||||||
|
|
||||||
bars = [ToolBar(donate_action, location_manager, parent) for i in
|
bars = [ToolBar(donate_action, location_manager, parent) for i in range(3)]
|
||||||
range(3)]
|
|
||||||
self.main_bars = tuple(bars[:2])
|
self.main_bars = tuple(bars[:2])
|
||||||
self.child_bars = tuple(bars[2:])
|
self.child_bars = tuple(bars[2:])
|
||||||
self.reveal_bar = RevealBar(parent)
|
self.reveal_bar = RevealBar(parent)
|
||||||
|
@ -12,7 +12,7 @@ from PyQt5.Qt import QDialog, QWidget, Qt, QDialogButtonBox, QVBoxLayout
|
|||||||
from calibre.gui2.convert.xpath_wizard_ui import Ui_Form
|
from calibre.gui2.convert.xpath_wizard_ui import Ui_Form
|
||||||
from calibre.gui2.convert.xexp_edit_ui import Ui_Form as Ui_Edit
|
from calibre.gui2.convert.xexp_edit_ui import Ui_Form as Ui_Edit
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class WizardWidget(QWidget, Ui_Form):
|
class WizardWidget(QWidget, Ui_Form):
|
||||||
|
@ -26,7 +26,7 @@ from calibre.utils.date import utcnow
|
|||||||
from calibre.utils.network import internet_connected
|
from calibre.utils.network import internet_connected
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.utils.localization import get_lang, canonicalize_lang
|
from calibre.utils.localization import get_lang, canonicalize_lang
|
||||||
from polyglot.builtins import iteritems, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range, map
|
||||||
|
|
||||||
|
|
||||||
def convert_day_time_schedule(val):
|
def convert_day_time_schedule(val):
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.icu import sort_key
|
|||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.date import now
|
from calibre.utils.date import now
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range, map
|
||||||
|
|
||||||
box_values = {}
|
box_values = {}
|
||||||
last_matchkind = CONTAINS_MATCH
|
last_matchkind = CONTAINS_MATCH
|
||||||
|
@ -30,7 +30,7 @@ from calibre.constants import filesystem_encoding, DEBUG, config_dir
|
|||||||
from calibre.gui2.library import DEFAULT_SORT
|
from calibre.gui2.library import DEFAULT_SORT
|
||||||
from calibre.utils.localization import calibre_langcode_to_name
|
from calibre.utils.localization import calibre_langcode_to_name
|
||||||
from calibre.library.coloring import color_row_key
|
from calibre.library.coloring import color_row_key
|
||||||
from polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes, range
|
from polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes, range, map
|
||||||
|
|
||||||
Counts = namedtuple('Counts', 'library_total total current')
|
Counts = namedtuple('Counts', 'library_total total current')
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.beginResetModel(), self.endResetModel()
|
self.beginResetModel(), self.endResetModel()
|
||||||
|
|
||||||
def delete_books(self, indices, permanent=False):
|
def delete_books(self, indices, permanent=False):
|
||||||
ids = map(self.id, indices)
|
ids = list(map(self.id, indices))
|
||||||
self.delete_books_by_id(ids, permanent=permanent)
|
self.delete_books_by_id(ids, permanent=permanent)
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import os, weakref
|
import os, weakref
|
||||||
from collections import OrderedDict, namedtuple
|
from collections import OrderedDict, namedtuple
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import iteritems, itervalues, zip, unicode_type, range
|
from polyglot.builtins import iteritems, itervalues, zip, unicode_type, range, map
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QDialog, QWidget, QGridLayout, QLabel, QToolButton, QIcon,
|
QDialog, QWidget, QGridLayout, QLabel, QToolButton, QIcon,
|
||||||
@ -692,7 +692,7 @@ if __name__ == '__main__':
|
|||||||
ids = sorted(db.all_ids(), reverse=True)
|
ids = sorted(db.all_ids(), reverse=True)
|
||||||
ids = tuple(zip(ids[0::2], ids[1::2]))
|
ids = tuple(zip(ids[0::2], ids[1::2]))
|
||||||
gm = partial(db.get_metadata, index_is_id=True, get_cover=True, cover_as_data=True)
|
gm = partial(db.get_metadata, index_is_id=True, get_cover=True, cover_as_data=True)
|
||||||
get_metadata = lambda x:map(gm, ids[x])
|
get_metadata = lambda x:list(map(gm, ids[x]))
|
||||||
d = CompareMany(list(range(len(ids))), get_metadata, db.field_metadata, db=db)
|
d = CompareMany(list(range(len(ids))), get_metadata, db.field_metadata, db=db)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
for changed, mi in itervalues(d.accepted):
|
for changed, mi in itervalues(d.accepted):
|
||||||
|
@ -18,7 +18,7 @@ from calibre.ebooks import BOOK_EXTENSIONS
|
|||||||
from calibre.ebooks.oeb.iterator import is_supported
|
from calibre.ebooks.oeb.iterator import is_supported
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
class OutputFormatSetting(Setting):
|
class OutputFormatSetting(Setting):
|
||||||
|
@ -14,7 +14,7 @@ from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
|||||||
from calibre.gui2.preferences.columns_ui import Ui_Form
|
from calibre.gui2.preferences.columns_ui import Ui_Form
|
||||||
from calibre.gui2.preferences.create_custom_column import CreateCustomColumn
|
from calibre.gui2.preferences.create_custom_column import CreateCustomColumn
|
||||||
from calibre.gui2 import error_dialog, question_dialog, ALL_COLUMNS
|
from calibre.gui2 import error_dialog, question_dialog, ALL_COLUMNS
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range, map
|
||||||
|
|
||||||
|
|
||||||
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||||
|
@ -16,7 +16,7 @@ from PyQt5.Qt import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, range, map
|
||||||
|
|
||||||
|
|
||||||
class CreateCustomColumn(QDialog):
|
class CreateCustomColumn(QDialog):
|
||||||
|
@ -36,7 +36,7 @@ from calibre.gui2.preferences.coloring import EditRules
|
|||||||
from calibre.gui2.library.alternate_views import auto_height, CM_TO_INCH
|
from calibre.gui2.library.alternate_views import auto_height, CM_TO_INCH
|
||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
from calibre.gui2.actions.show_quickview import get_quickview_action_plugin
|
from calibre.gui2.actions.show_quickview import get_quickview_action_plugin
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class BusyCursor(object):
|
class BusyCursor(object):
|
||||||
|
@ -20,7 +20,7 @@ from calibre.gui2.dialogs.confirm_delete import confirm
|
|||||||
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
||||||
from calibre.gui2.dialogs.search import SearchDialog
|
from calibre.gui2.dialogs.search import SearchDialog
|
||||||
from calibre.utils.icu import primary_sort_key
|
from calibre.utils.icu import primary_sort_key
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes, map, range
|
||||||
|
|
||||||
QT_HIDDEN_CLEAR_ACTION = '_q_qlineeditclearaction'
|
QT_HIDDEN_CLEAR_ACTION = '_q_qlineeditclearaction'
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from PyQt5.Qt import (QDialog, QDialogButtonBox)
|
|||||||
from calibre.gui2.store.config.chooser.adv_search_builder_ui import Ui_Dialog
|
from calibre.gui2.store.config.chooser.adv_search_builder_ui import Ui_Dialog
|
||||||
from calibre.library.caches import CONTAINS_MATCH, EQUALS_MATCH
|
from calibre.library.caches import CONTAINS_MATCH, EQUALS_MATCH
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
||||||
|
@ -78,9 +78,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
|||||||
self.mc = '='
|
self.mc = '='
|
||||||
else:
|
else:
|
||||||
self.mc = '~'
|
self.mc = '~'
|
||||||
all, any, phrase, none = map(lambda x: unicode_type(x.text()),
|
all, any, phrase, none = list(map(lambda x: unicode_type(x.text()),
|
||||||
(self.all, self.any, self.phrase, self.none))
|
(self.all, self.any, self.phrase, self.none)))
|
||||||
all, any, none = map(self.tokens, (all, any, none))
|
all, any, none = list(map(self.tokens, (all, any, none)))
|
||||||
phrase = phrase.strip()
|
phrase = phrase.strip()
|
||||||
all = ' and '.join(all)
|
all = ' and '.join(all)
|
||||||
any = ' or '.join(any)
|
any = ' or '.join(any)
|
||||||
|
@ -67,9 +67,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
|||||||
self.mc = '='
|
self.mc = '='
|
||||||
else:
|
else:
|
||||||
self.mc = '~'
|
self.mc = '~'
|
||||||
all, any, phrase, none = map(lambda x: type(u'')(x.text()),
|
all, any, phrase, none = list(map(lambda x: type(u'')(x.text()),
|
||||||
(self.all, self.any, self.phrase, self.none))
|
(self.all, self.any, self.phrase, self.none)))
|
||||||
all, any, none = map(self.tokens, (all, any, none))
|
all, any, none = list(map(self.tokens, (all, any, none)))
|
||||||
phrase = phrase.strip()
|
phrase = phrase.strip()
|
||||||
all = ' and '.join(all)
|
all = ' and '.join(all)
|
||||||
any = ' or '.join(any)
|
any = ' or '.join(any)
|
||||||
|
@ -69,7 +69,7 @@ from calibre.utils.config import JSONConfig
|
|||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from calibre.utils.imghdr import identify
|
from calibre.utils.imghdr import identify
|
||||||
from calibre.utils.tdir_in_cache import tdir_in_cache
|
from calibre.utils.tdir_in_cache import tdir_in_cache
|
||||||
from polyglot.builtins import iteritems, itervalues, string_or_bytes
|
from polyglot.builtins import iteritems, itervalues, string_or_bytes, map
|
||||||
from polyglot.urllib import urlparse
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
_diff_dialogs = []
|
_diff_dialogs = []
|
||||||
@ -378,7 +378,7 @@ class Boss(QObject):
|
|||||||
if ef:
|
if ef:
|
||||||
if isinstance(ef, type('')):
|
if isinstance(ef, type('')):
|
||||||
ef = [ef]
|
ef = [ef]
|
||||||
map(self.gui.file_list.request_edit, ef)
|
tuple(map(self.gui.file_list.request_edit, ef))
|
||||||
else:
|
else:
|
||||||
if tprefs['restore_book_state']:
|
if tprefs['restore_book_state']:
|
||||||
self.restore_book_edit_state()
|
self.restore_book_edit_state()
|
||||||
|
@ -22,7 +22,7 @@ from calibre.gui2.tweak_book import tprefs
|
|||||||
from calibre.gui2.tweak_book.widgets import Dialog, BusyCursor
|
from calibre.gui2.tweak_book.widgets import Dialog, BusyCursor
|
||||||
from calibre.utils.icu import safe_chr as chr
|
from calibre.utils.icu import safe_chr as chr
|
||||||
from calibre.utils.unicode_names import character_name_from_code, points_for_word
|
from calibre.utils.unicode_names import character_name_from_code, points_for_word
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range, map
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
|
|
||||||
@ -529,7 +529,7 @@ class CharModel(QAbstractListModel):
|
|||||||
def dropMimeData(self, md, action, row, column, parent):
|
def dropMimeData(self, md, action, row, column, parent):
|
||||||
if action != Qt.MoveAction or not md.hasFormat('application/calibre_charcode_indices') or row < 0 or column != 0:
|
if action != Qt.MoveAction or not md.hasFormat('application/calibre_charcode_indices') or row < 0 or column != 0:
|
||||||
return False
|
return False
|
||||||
indices = map(int, bytes(md.data('application/calibre_charcode_indices')).decode('ascii').split(','))
|
indices = list(map(int, bytes(md.data('application/calibre_charcode_indices')).decode('ascii').split(',')))
|
||||||
codes = [self.chars[x] for x in indices]
|
codes = [self.chars[x] for x in indices]
|
||||||
for x in indices:
|
for x in indices:
|
||||||
self.chars[x] = None
|
self.chars[x] = None
|
||||||
|
@ -24,7 +24,7 @@ from calibre.gui2.tweak_book.widgets import Dialog
|
|||||||
from calibre.gui2.widgets2 import HistoryLineEdit2
|
from calibre.gui2.widgets2 import HistoryLineEdit2
|
||||||
from calibre.utils.filenames import samefile
|
from calibre.utils.filenames import samefile
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, map
|
||||||
|
|
||||||
|
|
||||||
class BusyWidget(QWidget): # {{{
|
class BusyWidget(QWidget): # {{{
|
||||||
|
@ -12,7 +12,7 @@ from math import ceil
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import namedtuple, OrderedDict
|
from collections import namedtuple, OrderedDict
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from polyglot.builtins import iteritems, unicode_type, zip, range, as_bytes
|
from polyglot.builtins import iteritems, unicode_type, zip, range, as_bytes, map
|
||||||
|
|
||||||
import regex
|
import regex
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
|
@ -18,7 +18,7 @@ from calibre.gui2 import error_dialog
|
|||||||
from calibre.gui2.tweak_book import tprefs
|
from calibre.gui2.tweak_book import tprefs
|
||||||
from calibre.gui2.tweak_book.editor import syntax_text_char_format
|
from calibre.gui2.tweak_book.editor import syntax_text_char_format
|
||||||
from calibre.gui2.tweak_book.widgets import Dialog
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
from polyglot.builtins import iteritems, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range, map
|
||||||
|
|
||||||
underline_styles = {'single', 'dash', 'dot', 'dash_dot', 'dash_dot_dot', 'wave', 'spell'}
|
underline_styles = {'single', 'dash', 'dot', 'dash_dot', 'dash_dot_dot', 'wave', 'spell'}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ from calibre.gui2.tweak_book import (
|
|||||||
from calibre.gui2.tweak_book.editor import syntax_from_mime
|
from calibre.gui2.tweak_book.editor import syntax_from_mime
|
||||||
from calibre.gui2.tweak_book.templates import template_for
|
from calibre.gui2.tweak_book.templates import template_for
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from polyglot.builtins import iteritems, itervalues, unicode_type, range, filter
|
from polyglot.builtins import iteritems, itervalues, unicode_type, range, filter, map
|
||||||
from polyglot.binary import as_hex_unicode
|
from polyglot.binary import as_hex_unicode
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -990,7 +990,7 @@ class MergeDialog(QDialog): # {{{
|
|||||||
|
|
||||||
buttons = self.buttons = [QRadioButton(n) for n in names]
|
buttons = self.buttons = [QRadioButton(n) for n in names]
|
||||||
buttons[0].setChecked(True)
|
buttons[0].setChecked(True)
|
||||||
map(w.l.addWidget, buttons)
|
tuple(map(w.l.addWidget, buttons))
|
||||||
sa.setWidget(w)
|
sa.setWidget(w)
|
||||||
|
|
||||||
self.resize(self.sizeHint() + QSize(150, 20))
|
self.resize(self.sizeHint() + QSize(150, 20))
|
||||||
|
@ -34,7 +34,7 @@ from calibre.gui2.tweak_book.widgets import BusyCursor
|
|||||||
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
||||||
from calibre.utils.icu import primary_contains
|
from calibre.utils.icu import primary_contains
|
||||||
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
||||||
from polyglot.builtins import iteritems, unicode_type, range, error_message, filter
|
from polyglot.builtins import iteritems, unicode_type, range, error_message, filter, map
|
||||||
|
|
||||||
|
|
||||||
# The search panel {{{
|
# The search panel {{{
|
||||||
|
@ -27,10 +27,11 @@ from calibre.gui2.widgets2 import Dialog as BaseDialog, HistoryComboBox
|
|||||||
from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key
|
from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key
|
||||||
from calibre.utils.matcher import get_char, Matcher
|
from calibre.utils.matcher import get_char, Matcher
|
||||||
from calibre.gui2.complete2 import EditWithComplete
|
from calibre.gui2.complete2 import EditWithComplete
|
||||||
from polyglot.builtins import iteritems, unicode_type, zip, getcwd
|
from polyglot.builtins import iteritems, unicode_type, zip, getcwd, filter as ignore_me
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
PARAGRAPH_SEPARATOR = '\u2029'
|
PARAGRAPH_SEPARATOR = '\u2029'
|
||||||
|
ignore_me
|
||||||
|
|
||||||
|
|
||||||
class BusyCursor(object):
|
class BusyCursor(object):
|
||||||
|
@ -13,7 +13,7 @@ from PyQt5.Qt import (
|
|||||||
QContextMenuEvent, QDialog, QDialogButtonBox, QLabel, QVBoxLayout)
|
QContextMenuEvent, QDialog, QDialogButtonBox, QLabel, QVBoxLayout)
|
||||||
|
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from polyglot.builtins import itervalues
|
from polyglot.builtins import itervalues, map
|
||||||
|
|
||||||
touch_supported = False
|
touch_supported = False
|
||||||
if iswindows and sys.getwindowsversion()[:2] >= (6, 2): # At least windows 7
|
if iswindows and sys.getwindowsversion()[:2] >= (6, 2): # At least windows 7
|
||||||
|
@ -25,7 +25,7 @@ from calibre.utils.localization import localize_user_manual_link
|
|||||||
|
|
||||||
from calibre.utils.config import dynamic, prefs
|
from calibre.utils.config import dynamic, prefs
|
||||||
from calibre.gui2 import choose_dir, error_dialog
|
from calibre.gui2 import choose_dir, error_dialog
|
||||||
from polyglot.builtins import iteritems, unicode_type
|
from polyglot.builtins import iteritems, unicode_type, map
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
winutil = plugins['winutil'][0]
|
winutil = plugins['winutil'][0]
|
||||||
|
@ -42,7 +42,7 @@ from calibre.utils.icu import capitalize, collation_order, sort_key
|
|||||||
from calibre.utils.img import scale_image
|
from calibre.utils.img import scale_image
|
||||||
from calibre.utils.localization import get_lang, lang_as_iso639_1
|
from calibre.utils.localization import get_lang, lang_as_iso639_1
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
from polyglot.builtins import unicode_type, iteritems
|
from polyglot.builtins import unicode_type, iteritems, map, zip
|
||||||
|
|
||||||
NBSP = u'\u00a0'
|
NBSP = u'\u00a0'
|
||||||
|
|
||||||
@ -602,7 +602,7 @@ class CatalogBuilder(object):
|
|||||||
for rule in self.prefix_rules:
|
for rule in self.prefix_rules:
|
||||||
# Literal comparison for Tags field
|
# Literal comparison for Tags field
|
||||||
if rule['field'].lower() == 'tags' or rule['field'] == _('Tags'):
|
if rule['field'].lower() == 'tags' or rule['field'] == _('Tags'):
|
||||||
if rule['pattern'].lower() in map(unicode_type.lower, record['tags']):
|
if rule['pattern'].lower() in tuple(map(unicode_type.lower, record['tags'])):
|
||||||
if self.DEBUG and self.opts.verbose:
|
if self.DEBUG and self.opts.verbose:
|
||||||
self.opts.log.info(" %s '%s' by %s (%s: Tags includes '%s')" %
|
self.opts.log.info(" %s '%s' by %s (%s: Tags includes '%s')" %
|
||||||
(rule['prefix'], record['title'],
|
(rule['prefix'], record['title'],
|
||||||
|
@ -12,7 +12,7 @@ from calibre.ebooks.metadata import MetaInformation
|
|||||||
from calibre.ebooks.metadata import string_to_authors
|
from calibre.ebooks.metadata import string_to_authors
|
||||||
from calibre.utils.serialize import pickle_loads, pickle_dumps
|
from calibre.utils.serialize import pickle_loads, pickle_dumps
|
||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
from polyglot.builtins import unicode_type, filter
|
from polyglot.builtins import unicode_type, filter, map
|
||||||
|
|
||||||
|
|
||||||
class Concatenate(object):
|
class Concatenate(object):
|
||||||
@ -868,7 +868,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def refresh_ids(self, ids):
|
def refresh_ids(self, ids):
|
||||||
indices = map(self.index, ids)
|
indices = list(map(self.index, ids))
|
||||||
for id, idx in zip(ids, indices):
|
for id, idx in zip(ids, indices):
|
||||||
row = self.conn.get('SELECT * from meta WHERE id=?', (id,), all=False)
|
row = self.conn.get('SELECT * from meta WHERE id=?', (id,), all=False)
|
||||||
self.data[idx] = row
|
self.data[idx] = row
|
||||||
|
@ -47,7 +47,7 @@ from calibre.db.lazy import FormatMetadata, FormatsList
|
|||||||
from calibre.db.categories import Tag, CATEGORY_SORTS
|
from calibre.db.categories import Tag, CATEGORY_SORTS
|
||||||
from calibre.utils.localization import (canonicalize_lang,
|
from calibre.utils.localization import (canonicalize_lang,
|
||||||
calibre_langcode_to_name)
|
calibre_langcode_to_name)
|
||||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, map
|
||||||
|
|
||||||
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
||||||
SPOOL_SIZE = 30*1024*1024
|
SPOOL_SIZE = 30*1024*1024
|
||||||
|
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import iteritems, itervalues, unicode_type, zip, string_or_bytes
|
from polyglot.builtins import iteritems, itervalues, unicode_type, zip, string_or_bytes, map
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
|
@ -22,7 +22,7 @@ from calibre.srv.render_book import RENDER_VERSION
|
|||||||
from calibre.srv.routes import endpoint, json
|
from calibre.srv.routes import endpoint, json
|
||||||
from calibre.srv.utils import get_db, get_library_data
|
from calibre.srv.utils import get_db, get_library_data
|
||||||
from calibre.utils.serialize import json_dumps
|
from calibre.utils.serialize import json_dumps
|
||||||
from polyglot.builtins import as_unicode
|
from polyglot.builtins import as_unicode, map
|
||||||
|
|
||||||
cache_lock = RLock()
|
cache_lock = RLock()
|
||||||
queued_jobs = {}
|
queued_jobs = {}
|
||||||
|
@ -17,7 +17,7 @@ from calibre.ptempfile import TemporaryDirectory
|
|||||||
from calibre.srv.errors import HTTPForbidden
|
from calibre.srv.errors import HTTPForbidden
|
||||||
from calibre.srv.tests.base import BaseTest, TestServer
|
from calibre.srv.tests.base import BaseTest, TestServer
|
||||||
from calibre.srv.routes import endpoint, Router
|
from calibre.srv.routes import endpoint, Router
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues, map
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
from polyglot.http_cookie import CookieJar
|
from polyglot.http_cookie import CookieJar
|
||||||
from polyglot.urllib import (build_opener, HTTPBasicAuthHandler,
|
from polyglot.urllib import (build_opener, HTTPBasicAuthHandler,
|
||||||
|
@ -18,7 +18,7 @@ from calibre.srv.tests.base import BaseTest, TestServer
|
|||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.utils.certgen import create_server_cert
|
from calibre.utils.certgen import create_server_cert
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import range, unicode_type
|
from polyglot.builtins import range, unicode_type, map
|
||||||
from polyglot import http_client
|
from polyglot import http_client
|
||||||
is_ci = os.environ.get('CI', '').lower() == 'true'
|
is_ci = os.environ.get('CI', '').lower() == 'true'
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from polyglot.builtins import itervalues
|
from polyglot.builtins import itervalues, zip
|
||||||
|
|
||||||
__all__ = ('BusName', 'Object', 'PropertiesInterface', 'method', 'dbus_property', 'signal')
|
__all__ = ('BusName', 'Object', 'PropertiesInterface', 'method', 'dbus_property', 'signal')
|
||||||
__docformat__ = 'restructuredtext'
|
__docformat__ = 'restructuredtext'
|
||||||
|
@ -15,7 +15,7 @@ from functools import partial
|
|||||||
from calibre.utils.icu import safe_chr, ord_string
|
from calibre.utils.icu import safe_chr, ord_string
|
||||||
from calibre.utils.fonts.sfnt.container import Sfnt
|
from calibre.utils.fonts.sfnt.container import Sfnt
|
||||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
|
from calibre.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
|
||||||
from polyglot.builtins import unicode_type, range, iteritems, itervalues
|
from polyglot.builtins import unicode_type, range, iteritems, itervalues, map
|
||||||
|
|
||||||
# TrueType outlines {{{
|
# TrueType outlines {{{
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ def main(args):
|
|||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
if opts.codes:
|
if opts.codes:
|
||||||
parts = tuple(map(conv_code, parts))
|
parts = tuple(map(conv_code, parts))
|
||||||
map(not_single, parts)
|
tuple(map(not_single, parts))
|
||||||
ranges.add(tuple(parts))
|
ranges.add(tuple(parts))
|
||||||
else:
|
else:
|
||||||
if opts.codes:
|
if opts.codes:
|
||||||
|
@ -22,7 +22,7 @@ from calibre.utils.filenames import atomic_rename
|
|||||||
from calibre.utils.terminal import ANSIStream
|
from calibre.utils.terminal import ANSIStream
|
||||||
from duktape import Context, JSError, to_python
|
from duktape import Context, JSError, to_python
|
||||||
from lzma.xz import compress, decompress
|
from lzma.xz import compress, decompress
|
||||||
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter, getcwd
|
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter, getcwd, zip
|
||||||
from polyglot.queue import Empty, Queue
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||||
|
@ -11,7 +11,7 @@ from tempfile import SpooledTemporaryFile
|
|||||||
from calibre import sanitize_file_name
|
from calibre import sanitize_file_name
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.ebooks.chardet import detect
|
from calibre.ebooks.chardet import detect
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes, getcwd
|
from polyglot.builtins import unicode_type, string_or_bytes, getcwd, map
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import zlib # We may need its compression method
|
import zlib # We may need its compression method
|
||||||
@ -1061,7 +1061,7 @@ class ZipFile:
|
|||||||
# or the MSB of the file time depending on the header type
|
# or the MSB of the file time depending on the header type
|
||||||
# and is used to check the correctness of the password.
|
# and is used to check the correctness of the password.
|
||||||
bytes = zef_file.read(12)
|
bytes = zef_file.read(12)
|
||||||
h = map(zd, bytes[0:12])
|
h = list(map(zd, bytes[0:12]))
|
||||||
if zinfo.flag_bits & 0x8:
|
if zinfo.flag_bits & 0x8:
|
||||||
# compare against the file type from extended local headers
|
# compare against the file type from extended local headers
|
||||||
check_byte = (zinfo._raw_time >> 8) & 0xff
|
check_byte = (zinfo._raw_time >> 8) & 0xff
|
||||||
|
@ -12,7 +12,7 @@ from calibre.utils.logging import default_log
|
|||||||
from calibre import entity_to_unicode, strftime, force_unicode
|
from calibre import entity_to_unicode, strftime, force_unicode
|
||||||
from calibre.utils.date import dt_factory, utcnow, local_tz
|
from calibre.utils.date import dt_factory, utcnow, local_tz
|
||||||
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes, map
|
||||||
|
|
||||||
|
|
||||||
class Article(object):
|
class Article(object):
|
||||||
@ -296,7 +296,7 @@ class FeedCollection(list):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
print('#feeds', len(self))
|
print('#feeds', len(self))
|
||||||
print(map(len, self))
|
print(list(map(len, self)))
|
||||||
for f in self:
|
for f in self:
|
||||||
dups = []
|
dups = []
|
||||||
for a in f:
|
for a in f:
|
||||||
@ -311,7 +311,7 @@ class FeedCollection(list):
|
|||||||
|
|
||||||
self.duplicates = duplicates
|
self.duplicates = duplicates
|
||||||
print(len(duplicates))
|
print(len(duplicates))
|
||||||
print(map(len, self))
|
print(list(map(len, self)))
|
||||||
# raise
|
# raise
|
||||||
|
|
||||||
def find_article(self, article):
|
def find_article(self, article):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user