mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
python3: fix various uses of itertools.i(map|zip)
Use the existing polyglot.builtins / future_builtins versions. Also smooth over izip_longest, but don't bother with another polyglot module for one function used in two places.
This commit is contained in:
parent
45f68f552b
commit
cb85e778d8
@ -4,9 +4,8 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from calibre.customize import Plugin as _Plugin
|
from calibre.customize import Plugin as _Plugin
|
||||||
|
from polyglot.builtins import zip
|
||||||
|
|
||||||
FONT_SIZES = [('xx-small', 1),
|
FONT_SIZES = [('xx-small', 1),
|
||||||
('x-small', None),
|
('x-small', None),
|
||||||
@ -31,7 +30,7 @@ class Plugin(_Plugin):
|
|||||||
fsizes = list(self.fsizes)
|
fsizes = list(self.fsizes)
|
||||||
self.fkey = list(self.fsizes)
|
self.fkey = list(self.fsizes)
|
||||||
self.fsizes = []
|
self.fsizes = []
|
||||||
for (name, num), size in izip(FONT_SIZES, fsizes):
|
for (name, num), size in zip(FONT_SIZES, fsizes):
|
||||||
self.fsizes.append((name, num, float(size)))
|
self.fsizes.append((name, num, float(size)))
|
||||||
self.fnames = dict((name, sz) for name, _, sz in self.fsizes if name)
|
self.fnames = dict((name, sz) for name, _, sz in self.fsizes if name)
|
||||||
self.fnums = dict((num, sz) for _, num, sz in self.fsizes if num)
|
self.fnums = dict((num, sz) for _, num, sz in self.fsizes if num)
|
||||||
|
@ -9,8 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import weakref, operator, numbers
|
import weakref, operator, numbers
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import izip, imap
|
from polyglot.builtins import map, unicode_type, range, zip
|
||||||
from polyglot.builtins import map, unicode_type, range
|
|
||||||
|
|
||||||
from calibre.ebooks.metadata import title_sort
|
from calibre.ebooks.metadata import title_sort
|
||||||
from calibre.utils.config_base import tweaks, prefs
|
from calibre.utils.config_base import tweaks, prefs
|
||||||
@ -374,7 +373,7 @@ class View(object):
|
|||||||
self.marked_ids = dict.fromkeys(id_dict, u'true')
|
self.marked_ids = dict.fromkeys(id_dict, u'true')
|
||||||
else:
|
else:
|
||||||
# Ensure that all the items in the dict are text
|
# Ensure that all the items in the dict are text
|
||||||
self.marked_ids = dict(izip(id_dict.iterkeys(), imap(unicode_type,
|
self.marked_ids = dict(zip(id_dict.iterkeys(), map(unicode_type,
|
||||||
id_dict.itervalues())))
|
id_dict.itervalues())))
|
||||||
# This invalidates all searches in the cache even though the cache may
|
# This invalidates all searches in the cache even though the cache may
|
||||||
# be shared by multiple views. This is not ideal, but...
|
# be shared by multiple views. This is not ideal, but...
|
||||||
|
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import json, traceback, posixpath, importlib, os
|
import json, traceback, posixpath, importlib, os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.constants import iswindows, numeric_version
|
from calibre.constants import iswindows, numeric_version
|
||||||
@ -18,7 +17,7 @@ from calibre.devices.mtp.base import debug
|
|||||||
from calibre.devices.mtp.defaults import DeviceDefaults
|
from calibre.devices.mtp.defaults import DeviceDefaults
|
||||||
from calibre.ptempfile import SpooledTemporaryFile, PersistentTemporaryDirectory
|
from calibre.ptempfile import SpooledTemporaryFile, PersistentTemporaryDirectory
|
||||||
from calibre.utils.filenames import shorten_components_to
|
from calibre.utils.filenames import shorten_components_to
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, zip
|
||||||
|
|
||||||
BASE = importlib.import_module('calibre.devices.mtp.%s.driver'%(
|
BASE = importlib.import_module('calibre.devices.mtp.%s.driver'%(
|
||||||
'windows' if iswindows else 'unix')).MTP_DEVICE
|
'windows' if iswindows else 'unix')).MTP_DEVICE
|
||||||
@ -421,7 +420,7 @@ class MTP_DEVICE(BASE):
|
|||||||
|
|
||||||
routing = {fmt:dest for fmt,dest in self.get_pref('rules')}
|
routing = {fmt:dest for fmt,dest in self.get_pref('rules')}
|
||||||
|
|
||||||
for infile, fname, mi in izip(files, names, metadata):
|
for infile, fname, mi in zip(files, names, metadata):
|
||||||
path = self.create_upload_path(prefix, mi, fname, routing)
|
path = self.create_upload_path(prefix, mi, fname, routing)
|
||||||
if path and self.is_folder_ignored(storage, path):
|
if path and self.is_folder_ignored(storage, path):
|
||||||
raise MTPInvalidSendPathError('/'.join(path))
|
raise MTPInvalidSendPathError('/'.join(path))
|
||||||
@ -456,7 +455,7 @@ class MTP_DEVICE(BASE):
|
|||||||
|
|
||||||
i, total = 0, len(mtp_files)
|
i, total = 0, len(mtp_files)
|
||||||
self.report_progress(0, _('Adding books to device metadata listing...'))
|
self.report_progress(0, _('Adding books to device metadata listing...'))
|
||||||
for x, mi in izip(mtp_files, metadata):
|
for x, mi in zip(mtp_files, metadata):
|
||||||
mtp_file, bl_idx = x
|
mtp_file, bl_idx = x
|
||||||
bl = booklists[bl_idx]
|
bl = booklists[bl_idx]
|
||||||
book = Book(mtp_file.storage_id, '/'.join(mtp_file.mtp_relpath),
|
book = Book(mtp_file.storage_id, '/'.join(mtp_file.mtp_relpath),
|
||||||
|
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import re, tempfile, os
|
import re, tempfile, os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from calibre.constants import islinux, isbsd
|
from calibre.constants import islinux, isbsd
|
||||||
from calibre.customize.conversion import (InputFormatPlugin,
|
from calibre.customize.conversion import (InputFormatPlugin,
|
||||||
@ -17,7 +16,7 @@ from calibre.customize.conversion import (InputFormatPlugin,
|
|||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang
|
||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, zip
|
||||||
|
|
||||||
|
|
||||||
def sanitize_file_name(x):
|
def sanitize_file_name(x):
|
||||||
@ -216,7 +215,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
use = titles
|
use = titles
|
||||||
if len(titles) > len(set(titles)):
|
if len(titles) > len(set(titles)):
|
||||||
use = headers
|
use = headers
|
||||||
for title, item in izip(use, self.oeb.spine):
|
for title, item in zip(use, self.oeb.spine):
|
||||||
if not item.linear:
|
if not item.linear:
|
||||||
continue
|
continue
|
||||||
toc.add(title, item.href)
|
toc.add(title, item.href)
|
||||||
|
@ -8,7 +8,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
|
|
||||||
from struct import pack
|
from struct import pack
|
||||||
from itertools import izip, count, chain
|
from itertools import count, chain
|
||||||
import io
|
import io
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
@ -30,7 +30,7 @@ import calibre
|
|||||||
from calibre import plugins
|
from calibre import plugins
|
||||||
msdes, msdeserror = plugins['msdes']
|
msdes, msdeserror = plugins['msdes']
|
||||||
import calibre.ebooks.lit.mssha1 as mssha1
|
import calibre.ebooks.lit.mssha1 as mssha1
|
||||||
from polyglot.builtins import codepoint_to_chr, unicode_type, string_or_bytes, range
|
from polyglot.builtins import codepoint_to_chr, unicode_type, string_or_bytes, range, zip
|
||||||
from polyglot.urllib import urldefrag, unquote
|
from polyglot.urllib import urldefrag, unquote
|
||||||
|
|
||||||
__all__ = ['LitWriter']
|
__all__ = ['LitWriter']
|
||||||
@ -406,7 +406,7 @@ class LitWriter(object):
|
|||||||
1, CCHUNK_SIZE, 0x20000, ULL_NEG1, 1))
|
1, CCHUNK_SIZE, 0x20000, ULL_NEG1, 1))
|
||||||
cchunk = io.BytesIO()
|
cchunk = io.BytesIO()
|
||||||
last = 0
|
last = 0
|
||||||
for i, dcount in izip(count(), dcounts):
|
for i, dcount in zip(count(), dcounts):
|
||||||
cchunk.write(decint(last))
|
cchunk.write(decint(last))
|
||||||
cchunk.write(decint(dcount))
|
cchunk.write(decint(dcount))
|
||||||
cchunk.write(decint(i))
|
cchunk.write(decint(i))
|
||||||
@ -702,7 +702,7 @@ class LitWriter(object):
|
|||||||
ichunk = None
|
ichunk = None
|
||||||
if len(ddata) > 1:
|
if len(ddata) > 1:
|
||||||
ichunk = io.BytesIO()
|
ichunk = io.BytesIO()
|
||||||
for cid, (content, quickref, dcount, name) in izip(count(), ddata):
|
for cid, (content, quickref, dcount, name) in zip(count(), ddata):
|
||||||
dchunk = io.BytesIO()
|
dchunk = io.BytesIO()
|
||||||
prev = cid - 1 if cid > 0 else ULL_NEG1
|
prev = cid - 1 if cid > 0 else ULL_NEG1
|
||||||
next = cid + 1 if cid < cidmax else ULL_NEG1
|
next = cid + 1 if cid < cidmax else ULL_NEG1
|
||||||
|
@ -9,7 +9,6 @@ __copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import sys, os, struct, textwrap
|
import sys, os, struct, textwrap
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
from calibre.ebooks.mobi.debug.containers import ContainerHeader
|
from calibre.ebooks.mobi.debug.containers import ContainerHeader
|
||||||
@ -20,6 +19,7 @@ from calibre.ebooks.mobi.utils import read_font_record, decode_tbs, RECORD_SIZE
|
|||||||
from calibre.ebooks.mobi.debug import format_bytes
|
from calibre.ebooks.mobi.debug import format_bytes
|
||||||
from calibre.ebooks.mobi.reader.headers import NULL_INDEX
|
from calibre.ebooks.mobi.reader.headers import NULL_INDEX
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
|
from polyglot.builtins import zip
|
||||||
|
|
||||||
|
|
||||||
class FDST(object):
|
class FDST(object):
|
||||||
@ -36,7 +36,7 @@ class FDST(object):
|
|||||||
if rest:
|
if rest:
|
||||||
raise ValueError('FDST record has trailing data: '
|
raise ValueError('FDST record has trailing data: '
|
||||||
'%s'%format_bytes(rest))
|
'%s'%format_bytes(rest))
|
||||||
self.sections = tuple(izip(secs[::2], secs[1::2]))
|
self.sections = tuple(zip(secs[::2], secs[1::2]))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
ans = ['FDST record']
|
ans = ['FDST record']
|
||||||
@ -340,5 +340,3 @@ def inspect_mobi(mobi_file, ddir):
|
|||||||
part.dump(os.path.join(ddir, 'files'))
|
part.dump(os.path.join(ddir, 'files'))
|
||||||
|
|
||||||
f.dump_flows(os.path.join(ddir, 'flows'))
|
f.dump_flows(os.path.join(ddir, 'flows'))
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import struct, re, os
|
import struct, re, os
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from itertools import repeat, izip
|
from itertools import repeat
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -24,7 +24,7 @@ from calibre.ebooks.metadata.toc import TOC
|
|||||||
from calibre.ebooks.mobi.utils import read_font_record
|
from calibre.ebooks.mobi.utils import read_font_record
|
||||||
from calibre.ebooks.oeb.parse_utils import parse_html
|
from calibre.ebooks.oeb.parse_utils import parse_html
|
||||||
from calibre.ebooks.oeb.base import XPath, XHTML, xml2text
|
from calibre.ebooks.oeb.base import XPath, XHTML, xml2text
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range, zip
|
||||||
from polyglot.urllib import urldefrag
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
Part = namedtuple('Part',
|
Part = namedtuple('Part',
|
||||||
@ -125,7 +125,7 @@ class Mobi8Reader(object):
|
|||||||
sec_start, num_sections = struct.unpack_from(b'>LL', header, 4)
|
sec_start, num_sections = struct.unpack_from(b'>LL', header, 4)
|
||||||
secs = struct.unpack_from(b'>%dL' % (num_sections*2),
|
secs = struct.unpack_from(b'>%dL' % (num_sections*2),
|
||||||
header, sec_start)
|
header, sec_start)
|
||||||
self.flow_table = tuple(izip(secs[::2], secs[1::2]))
|
self.flow_table = tuple(zip(secs[::2], secs[1::2]))
|
||||||
|
|
||||||
self.files = []
|
self.files = []
|
||||||
if self.header.skelidx != NULL_INDEX:
|
if self.header.skelidx != NULL_INDEX:
|
||||||
|
@ -8,7 +8,6 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
|
|
||||||
import sys, os, uuid, copy, re, io
|
import sys, os, uuid, copy, re, io
|
||||||
from itertools import izip
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -28,7 +27,7 @@ from calibre.utils.localization import get_lang
|
|||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
from calibre import guess_type, xml_replace_entities
|
from calibre import guess_type, xml_replace_entities
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, zip
|
||||||
from polyglot.urllib import unquote, urldefrag, urlparse
|
from polyglot.urllib import unquote, urldefrag, urlparse
|
||||||
|
|
||||||
__all__ = ['OEBReader']
|
__all__ = ['OEBReader']
|
||||||
@ -541,7 +540,7 @@ class OEBReader(object):
|
|||||||
use = titles
|
use = titles
|
||||||
if len(titles) > len(set(titles)):
|
if len(titles) > len(set(titles)):
|
||||||
use = headers
|
use = headers
|
||||||
for title, item in izip(use, self.oeb.spine):
|
for title, item in zip(use, self.oeb.spine):
|
||||||
if not item.linear:
|
if not item.linear:
|
||||||
continue
|
continue
|
||||||
toc.add(title, item.href)
|
toc.add(title, item.href)
|
||||||
|
@ -8,10 +8,10 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from itertools import izip, groupby
|
from itertools import groupby
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from collections import Counter, OrderedDict
|
from collections import Counter, OrderedDict
|
||||||
from polyglot.builtins import map
|
from polyglot.builtins import map, zip
|
||||||
|
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
from calibre.ebooks.pdf.render.common import (Array, String, Stream,
|
from calibre.ebooks.pdf.render.common import (Array, String, Stream,
|
||||||
@ -194,7 +194,7 @@ class Font(object):
|
|||||||
|
|
||||||
def write_widths(self, objects):
|
def write_widths(self, objects):
|
||||||
glyphs = sorted(self.used_glyphs|{0})
|
glyphs = sorted(self.used_glyphs|{0})
|
||||||
widths = {g:self.metrics.pdf_scale(w) for g, w in izip(glyphs,
|
widths = {g:self.metrics.pdf_scale(w) for g, w in zip(glyphs,
|
||||||
self.metrics.glyph_widths(glyphs))}
|
self.metrics.glyph_widths(glyphs))}
|
||||||
counter = Counter()
|
counter = Counter()
|
||||||
for g, w in widths.iteritems():
|
for g, w in widths.iteritems():
|
||||||
|
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os, re
|
import os, re
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize, QIcon, QApplication,
|
QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize, QIcon, QApplication,
|
||||||
@ -25,7 +24,7 @@ from calibre.gui2.tag_browser.model import (TagTreeItem, TAG_SEARCH_STATES,
|
|||||||
from calibre.gui2 import config, gprefs, choose_files, pixmap_to_data, rating_font, empty_index
|
from calibre.gui2 import config, gprefs, choose_files, pixmap_to_data, rating_font, empty_index
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.serialize import json_loads
|
from calibre.utils.serialize import json_loads
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range, zip
|
||||||
|
|
||||||
|
|
||||||
class TagDelegate(QStyledItemDelegate): # {{{
|
class TagDelegate(QStyledItemDelegate): # {{{
|
||||||
@ -229,7 +228,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
expanded_categories.append(category.category_key)
|
expanded_categories.append(category.category_key)
|
||||||
states = [c.tag.state for c in category.child_tags()]
|
states = [c.tag.state for c in category.child_tags()]
|
||||||
names = [(c.tag.name, c.tag.category) for c in category.child_tags()]
|
names = [(c.tag.name, c.tag.category) for c in category.child_tags()]
|
||||||
state_map[category.category_key] = dict(izip(names, states))
|
state_map[category.category_key] = dict(zip(names, states))
|
||||||
return expanded_categories, state_map
|
return expanded_categories, state_map
|
||||||
|
|
||||||
def reread_collapse_parameters(self):
|
def reread_collapse_parameters(self):
|
||||||
|
@ -7,7 +7,6 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, textwrap, unicodedata
|
import os, textwrap, unicodedata
|
||||||
from itertools import izip
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
@ -28,7 +27,7 @@ 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 unicode_type
|
from polyglot.builtins import unicode_type, zip
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
PARAGRAPH_SEPARATOR = '\u2029'
|
PARAGRAPH_SEPARATOR = '\u2029'
|
||||||
@ -348,7 +347,7 @@ class Results(QWidget):
|
|||||||
[(p.setTextFormat(Qt.RichText), p.setTextOption(self.text_option)) for p in prefixes]
|
[(p.setTextFormat(Qt.RichText), p.setTextOption(self.text_option)) for p in prefixes]
|
||||||
self.maxwidth = max([x.size().width() for x in prefixes])
|
self.maxwidth = max([x.size().width() for x in prefixes])
|
||||||
self.results = tuple((prefix, self.make_text(text, positions), text)
|
self.results = tuple((prefix, self.make_text(text, positions), text)
|
||||||
for prefix, (text, positions) in izip(prefixes, results.iteritems()))
|
for prefix, (text, positions) in zip(prefixes, results.iteritems()))
|
||||||
else:
|
else:
|
||||||
self.results = ()
|
self.results = ()
|
||||||
self.current_result = -1
|
self.current_result = -1
|
||||||
|
@ -6,8 +6,8 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import itertools, time, traceback, locale
|
import time, traceback, locale
|
||||||
from itertools import repeat, izip, imap
|
from itertools import repeat
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ from calibre.db.search import CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH, _match
|
|||||||
from calibre.ebooks.metadata import title_sort, author_to_author_sort
|
from calibre.ebooks.metadata import title_sort, author_to_author_sort
|
||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
from calibre import prints, force_unicode
|
from calibre import prints, force_unicode
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import map, unicode_type, string_or_bytes, zip
|
||||||
|
|
||||||
|
|
||||||
class MetadataBackup(Thread): # {{{
|
class MetadataBackup(Thread): # {{{
|
||||||
@ -863,7 +863,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
self.search_restriction_book_count = len(self._map)
|
self.search_restriction_book_count = len(self._map)
|
||||||
return list(self._map)
|
return list(self._map)
|
||||||
matches = self.parse(q)
|
matches = self.parse(q)
|
||||||
tmap = list(itertools.repeat(False, len(self._data)))
|
tmap = list(repeat(False, len(self._data)))
|
||||||
for x in matches:
|
for x in matches:
|
||||||
tmap[x] = True
|
tmap[x] = True
|
||||||
rv = [x for x in self._map if tmap[x]]
|
rv = [x for x in self._map if tmap[x]]
|
||||||
@ -917,7 +917,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
self.marked_ids_dict = dict.fromkeys(id_dict, u'true')
|
self.marked_ids_dict = dict.fromkeys(id_dict, u'true')
|
||||||
else:
|
else:
|
||||||
# Ensure that all the items in the dict are text
|
# Ensure that all the items in the dict are text
|
||||||
self.marked_ids_dict = dict(izip(id_dict.iterkeys(), imap(unicode_type,
|
self.marked_ids_dict = dict(zip(id_dict.iterkeys(), map(unicode_type,
|
||||||
id_dict.itervalues())))
|
id_dict.itervalues())))
|
||||||
|
|
||||||
# Set the values in the cache
|
# Set the values in the cache
|
||||||
@ -1039,7 +1039,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
db.initialize_template_cache()
|
db.initialize_template_cache()
|
||||||
|
|
||||||
temp = db.conn.get('SELECT * FROM meta2')
|
temp = db.conn.get('SELECT * FROM meta2')
|
||||||
self._data = list(itertools.repeat(None, temp[-1][0]+2)) if temp else []
|
self._data = list(repeat(None, temp[-1][0]+2)) if temp else []
|
||||||
for r in temp:
|
for r in temp:
|
||||||
self._data[r[0]] = CacheRow(db, self.composites, r,
|
self._data[r[0]] = CacheRow(db, self.composites, r,
|
||||||
self.series_col, self.series_sort_col)
|
self.series_col, self.series_sort_col)
|
||||||
@ -1099,7 +1099,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if only_ids is None:
|
if only_ids is None:
|
||||||
self._map.sort(key=keyg)
|
self._map.sort(key=keyg)
|
||||||
|
|
||||||
tmap = list(itertools.repeat(False, len(self._data)))
|
tmap = list(repeat(False, len(self._data)))
|
||||||
for x in self._map_filtered:
|
for x in self._map_filtered:
|
||||||
tmap[x] = True
|
tmap[x] = True
|
||||||
self._map_filtered = [x for x in self._map if tmap[x]]
|
self._map_filtered = [x for x in self._map if tmap[x]]
|
||||||
|
@ -9,7 +9,7 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import os, httplib, hashlib, uuid, struct, repr as reprlib
|
import os, httplib, hashlib, uuid, struct, repr as reprlib
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
||||||
from itertools import chain, repeat, izip_longest
|
from itertools import chain, repeat
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -32,11 +32,13 @@ MULTIPART_SEPARATOR = uuid.uuid4().hex.decode('ascii')
|
|||||||
COMPRESSIBLE_TYPES = {'application/json', 'application/javascript', 'application/xml', 'application/oebps-package+xml'}
|
COMPRESSIBLE_TYPES = {'application/json', 'application/javascript', 'application/xml', 'application/oebps-package+xml'}
|
||||||
if is_py3:
|
if is_py3:
|
||||||
import zlib
|
import zlib
|
||||||
|
from itertools import zip_longest
|
||||||
else:
|
else:
|
||||||
zlib, zlib2_err = plugins['zlib2']
|
zlib, zlib2_err = plugins['zlib2']
|
||||||
if zlib2_err:
|
if zlib2_err:
|
||||||
raise RuntimeError('Failed to load the zlib2 module with error: ' + zlib2_err)
|
raise RuntimeError('Failed to load the zlib2 module with error: ' + zlib2_err)
|
||||||
del zlib2_err
|
del zlib2_err
|
||||||
|
from itertools import izip_longest as zip_longest
|
||||||
|
|
||||||
|
|
||||||
def header_list_to_file(buf): # {{{
|
def header_list_to_file(buf): # {{{
|
||||||
@ -709,7 +711,7 @@ class HTTPConnection(HTTPRequest):
|
|||||||
size = sum(map(len, range_parts)) + sum(r.size + 4 for r in ranges)
|
size = sum(map(len, range_parts)) + sum(r.size + 4 for r in ranges)
|
||||||
outheaders.set('Content-Length', '%d' % size, replace_all=True)
|
outheaders.set('Content-Length', '%d' % size, replace_all=True)
|
||||||
outheaders.set('Content-Type', 'multipart/byteranges; boundary=' + MULTIPART_SEPARATOR, replace_all=True)
|
outheaders.set('Content-Type', 'multipart/byteranges; boundary=' + MULTIPART_SEPARATOR, replace_all=True)
|
||||||
output.ranges = izip_longest(ranges, range_parts)
|
output.ranges = zip_longest(ranges, range_parts)
|
||||||
request.status_code = httplib.PARTIAL_CONTENT
|
request.status_code = httplib.PARTIAL_CONTENT
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@ -7,13 +7,17 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import errno, os, numbers
|
import errno, os, numbers
|
||||||
from itertools import izip_longest
|
|
||||||
from collections import namedtuple, OrderedDict
|
from collections import namedtuple, OrderedDict
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.utils.lock import ExclusiveFile
|
from calibre.utils.lock import ExclusiveFile
|
||||||
|
from polyglot.builtins import is_py3
|
||||||
|
if is_py3:
|
||||||
|
from itertools import zip_longest
|
||||||
|
else:
|
||||||
|
from itertools import izip_longest as zip_longest
|
||||||
|
|
||||||
Option = namedtuple('Option', 'name default longdoc shortdoc choices')
|
Option = namedtuple('Option', 'name default longdoc shortdoc choices')
|
||||||
|
|
||||||
@ -193,7 +197,7 @@ options = []
|
|||||||
def grouper(n, iterable, fillvalue=None):
|
def grouper(n, iterable, fillvalue=None):
|
||||||
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
||||||
args = [iter(iterable)] * n
|
args = [iter(iterable)] * n
|
||||||
return izip_longest(*args, fillvalue=fillvalue)
|
return zip_longest(*args, fillvalue=fillvalue)
|
||||||
|
|
||||||
|
|
||||||
for shortdoc, name, default, doc in grouper(4, raw_options):
|
for shortdoc, name, default, doc in grouper(4, raw_options):
|
||||||
|
@ -7,13 +7,12 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import httplib, sys, inspect, re, time, numbers, json as jsonlib, textwrap
|
import httplib, sys, inspect, re, time, numbers, json as jsonlib, textwrap
|
||||||
from itertools import izip
|
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError
|
from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError
|
||||||
from calibre.srv.utils import http_date
|
from calibre.srv.utils import http_date
|
||||||
from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME
|
from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range, zip
|
||||||
from polyglot.urllib import quote as urlquote
|
from polyglot.urllib import quote as urlquote
|
||||||
|
|
||||||
default_methods = frozenset(('HEAD', 'GET'))
|
default_methods = frozenset(('HEAD', 'GET'))
|
||||||
@ -171,7 +170,7 @@ class Route(object):
|
|||||||
def matches(self, path):
|
def matches(self, path):
|
||||||
args_map = self.defaults.copy()
|
args_map = self.defaults.copy()
|
||||||
num = 0
|
num = 0
|
||||||
for component, (name, matched) in izip(path, self.matchers):
|
for component, (name, matched) in zip(path, self.matchers):
|
||||||
num += 1
|
num += 1
|
||||||
if matched is True:
|
if matched is True:
|
||||||
args_map[name] = component
|
args_map[name] = component
|
||||||
|
@ -7,11 +7,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from itertools import izip
|
|
||||||
from struct import unpack_from, pack, calcsize
|
from struct import unpack_from, pack, calcsize
|
||||||
|
|
||||||
from calibre.utils.fonts.sfnt import UnknownTable, DateTimeProperty, FixedProperty
|
from calibre.utils.fonts.sfnt import UnknownTable, DateTimeProperty, FixedProperty
|
||||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
||||||
|
from polyglot.builtins import zip
|
||||||
|
|
||||||
|
|
||||||
class HeadTable(UnknownTable):
|
class HeadTable(UnknownTable):
|
||||||
@ -47,7 +47,7 @@ class HeadTable(UnknownTable):
|
|||||||
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
||||||
self._fields = field_types[0::2]
|
self._fields = field_types[0::2]
|
||||||
|
|
||||||
for f, val in izip(self._fields, unpack_from(self._fmt, self.raw)):
|
for f, val in zip(self._fields, unpack_from(self._fmt, self.raw)):
|
||||||
setattr(self, f, val)
|
setattr(self, f, val)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -85,7 +85,7 @@ class HorizontalHeader(UnknownTable):
|
|||||||
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
||||||
self._fields = field_types[0::2]
|
self._fields = field_types[0::2]
|
||||||
|
|
||||||
for f, val in izip(self._fields, unpack_from(self._fmt, self.raw)):
|
for f, val in zip(self._fields, unpack_from(self._fmt, self.raw)):
|
||||||
setattr(self, f, val)
|
setattr(self, f, val)
|
||||||
|
|
||||||
raw = hmtx.raw
|
raw = hmtx.raw
|
||||||
@ -149,7 +149,7 @@ class OS2Table(UnknownTable):
|
|||||||
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
||||||
self._fields = field_types[0::2]
|
self._fields = field_types[0::2]
|
||||||
|
|
||||||
for f, val in izip(self._fields, unpack_from(self._fmt, self.raw)):
|
for f, val in zip(self._fields, unpack_from(self._fmt, self.raw)):
|
||||||
setattr(self, f, val)
|
setattr(self, f, val)
|
||||||
|
|
||||||
def zero_fstype(self):
|
def zero_fstype(self):
|
||||||
@ -168,4 +168,3 @@ class PostTable(UnknownTable):
|
|||||||
return
|
return
|
||||||
(self._version, self._italic_angle, self.underline_position,
|
(self._version, self._italic_angle, self.underline_position,
|
||||||
self.underline_thickness) = unpack_from(b'>llhh', self.raw)
|
self.underline_thickness) = unpack_from(b'>llhh', self.raw)
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from itertools import izip
|
|
||||||
from struct import unpack_from, pack
|
from struct import unpack_from, pack
|
||||||
|
|
||||||
from calibre.utils.fonts.sfnt import UnknownTable, FixedProperty
|
from calibre.utils.fonts.sfnt import UnknownTable, FixedProperty
|
||||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
||||||
|
from polyglot.builtins import zip
|
||||||
|
|
||||||
|
|
||||||
class MaxpTable(UnknownTable):
|
class MaxpTable(UnknownTable):
|
||||||
@ -39,12 +39,9 @@ class MaxpTable(UnknownTable):
|
|||||||
self._fmt = b'>lH' + b'H'*(len(self.fields)-2)
|
self._fmt = b'>lH' + b'H'*(len(self.fields)-2)
|
||||||
|
|
||||||
vals = unpack_from(self._fmt, self.raw)
|
vals = unpack_from(self._fmt, self.raw)
|
||||||
for f, val in izip(self.fields, vals):
|
for f, val in zip(self.fields, vals):
|
||||||
setattr(self, f, val)
|
setattr(self, f, val)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
vals = [getattr(self, f) for f in self._fields]
|
vals = [getattr(self, f) for f in self._fields]
|
||||||
self.raw = pack(self._fmt, *vals)
|
self.raw = pack(self._fmt, *vals)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,8 +13,7 @@ from operator import itemgetter
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
|
|
||||||
from itertools import izip
|
from polyglot.builtins import map, unicode_type, range, zip
|
||||||
from polyglot.builtins import map, unicode_type, range
|
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count, as_unicode
|
from calibre import detect_ncpus as cpu_count, as_unicode
|
||||||
from calibre.constants import plugins, filesystem_encoding
|
from calibre.constants import plugins, filesystem_encoding
|
||||||
@ -270,7 +269,7 @@ class CScorer(object):
|
|||||||
|
|
||||||
def __call__(self, query):
|
def __call__(self, query):
|
||||||
scores, positions = self.m.calculate_scores(query)
|
scores, positions = self.m.calculate_scores(query)
|
||||||
for score, pos in izip(scores, positions):
|
for score, pos in zip(scores, positions):
|
||||||
yield score, pos
|
yield score, pos
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,10 +8,9 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, sys, re
|
import os, sys, re
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range, zip
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
import ctypes.wintypes
|
import ctypes.wintypes
|
||||||
@ -31,7 +30,7 @@ def fmt(code):
|
|||||||
|
|
||||||
|
|
||||||
RATTRIBUTES = dict(
|
RATTRIBUTES = dict(
|
||||||
izip(range(1, 9), (
|
zip(range(1, 9), (
|
||||||
'bold',
|
'bold',
|
||||||
'dark',
|
'dark',
|
||||||
'',
|
'',
|
||||||
@ -46,7 +45,7 @@ ATTRIBUTES = {v:fmt(k) for k, v in RATTRIBUTES.iteritems()}
|
|||||||
del ATTRIBUTES['']
|
del ATTRIBUTES['']
|
||||||
|
|
||||||
RBACKGROUNDS = dict(
|
RBACKGROUNDS = dict(
|
||||||
izip(range(41, 48), (
|
zip(range(41, 48), (
|
||||||
'red',
|
'red',
|
||||||
'green',
|
'green',
|
||||||
'yellow',
|
'yellow',
|
||||||
@ -59,7 +58,7 @@ RBACKGROUNDS = dict(
|
|||||||
BACKGROUNDS = {v:fmt(k) for k, v in RBACKGROUNDS.iteritems()}
|
BACKGROUNDS = {v:fmt(k) for k, v in RBACKGROUNDS.iteritems()}
|
||||||
|
|
||||||
RCOLORS = dict(
|
RCOLORS = dict(
|
||||||
izip(range(31, 38), (
|
zip(range(31, 38), (
|
||||||
'red',
|
'red',
|
||||||
'green',
|
'green',
|
||||||
'yellow',
|
'yellow',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user