mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'py3' of https://github.com/eli-schwartz/calibre
This commit is contained in:
commit
9f31662571
@ -58,7 +58,7 @@ class GUI(Command):
|
||||
for s in sources:
|
||||
files.append('<file>%s</file>'%s)
|
||||
manifest = '<RCC>\n<qresource prefix="/">\n%s\n</qresource>\n</RCC>'%'\n'.join(sorted(files))
|
||||
with open('images.qrc', 'wb') as f:
|
||||
with open('images.qrc', 'w') as f:
|
||||
f.write(manifest)
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
@ -241,9 +241,9 @@ class Manual(Command):
|
||||
|
||||
def serve_manual(self, root):
|
||||
os.chdir(root)
|
||||
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler
|
||||
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
|
||||
HandlerClass = SimpleHTTPRequestHandler
|
||||
ServerClass = BaseHTTPServer.HTTPServer
|
||||
ServerClass = HTTPServer
|
||||
Protocol = "HTTP/1.0"
|
||||
server_address = ('127.0.0.1', 8000)
|
||||
|
||||
|
@ -168,7 +168,7 @@ class Kakasi(Command): # {{{
|
||||
def mkitaiji(self, src, dst):
|
||||
dic = {}
|
||||
for line in open(src, "r"):
|
||||
line = line.decode("utf-8").strip()
|
||||
line = line.strip()
|
||||
if line.startswith(';;'): # skip comment
|
||||
continue
|
||||
if re.match(r"^$",line):
|
||||
@ -182,7 +182,7 @@ class Kakasi(Command): # {{{
|
||||
def mkkanadict(self, src, dst):
|
||||
dic = {}
|
||||
for line in open(src, "r"):
|
||||
line = line.decode("utf-8").strip()
|
||||
line = line.strip()
|
||||
if line.startswith(';;'): # skip comment
|
||||
continue
|
||||
if re.match(r"^$",line):
|
||||
@ -194,7 +194,7 @@ class Kakasi(Command): # {{{
|
||||
f.write(msgpack_dumps(dic))
|
||||
|
||||
def parsekdict(self, line):
|
||||
line = line.decode("utf-8").strip()
|
||||
line = line.strip()
|
||||
if line.startswith(';;'): # skip comment
|
||||
return
|
||||
(yomi, kanji) = line.split(' ')
|
||||
|
@ -4,9 +4,8 @@ __license__ = 'GPL 3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from itertools import izip
|
||||
|
||||
from calibre.customize import Plugin as _Plugin
|
||||
from polyglot.builtins import zip
|
||||
|
||||
FONT_SIZES = [('xx-small', 1),
|
||||
('x-small', None),
|
||||
@ -31,7 +30,7 @@ class Plugin(_Plugin):
|
||||
fsizes = list(self.fsizes)
|
||||
self.fkey = list(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.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)
|
||||
|
@ -9,8 +9,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import weakref, operator, numbers
|
||||
from functools import partial
|
||||
from itertools import izip, imap
|
||||
from polyglot.builtins import map, unicode_type, range
|
||||
from polyglot.builtins import map, unicode_type, range, zip
|
||||
|
||||
from calibre.ebooks.metadata import title_sort
|
||||
from calibre.utils.config_base import tweaks, prefs
|
||||
@ -374,7 +373,7 @@ class View(object):
|
||||
self.marked_ids = dict.fromkeys(id_dict, u'true')
|
||||
else:
|
||||
# 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())))
|
||||
# This invalidates all searches in the cache even though the cache may
|
||||
# be shared by multiple views. This is not ideal, but...
|
||||
|
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import json, traceback, posixpath, importlib, os
|
||||
from io import BytesIO
|
||||
from itertools import izip
|
||||
|
||||
from calibre import prints
|
||||
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.ptempfile import SpooledTemporaryFile, PersistentTemporaryDirectory
|
||||
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'%(
|
||||
'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')}
|
||||
|
||||
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)
|
||||
if path and self.is_folder_ignored(storage, path):
|
||||
raise MTPInvalidSendPathError('/'.join(path))
|
||||
@ -456,7 +455,7 @@ class MTP_DEVICE(BASE):
|
||||
|
||||
i, total = 0, len(mtp_files)
|
||||
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
|
||||
bl = booklists[bl_idx]
|
||||
book = Book(mtp_file.storage_id, '/'.join(mtp_file.mtp_relpath),
|
||||
|
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import re, tempfile, os
|
||||
from functools import partial
|
||||
from itertools import izip
|
||||
|
||||
from calibre.constants import islinux, isbsd
|
||||
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.filenames import ascii_filename
|
||||
from calibre.utils.imghdr import what
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, zip
|
||||
|
||||
|
||||
def sanitize_file_name(x):
|
||||
@ -216,7 +215,7 @@ class HTMLInput(InputFormatPlugin):
|
||||
use = titles
|
||||
if len(titles) > len(set(titles)):
|
||||
use = headers
|
||||
for title, item in izip(use, self.oeb.spine):
|
||||
for title, item in zip(use, self.oeb.spine):
|
||||
if not item.linear:
|
||||
continue
|
||||
toc.add(title, item.href)
|
||||
|
@ -8,7 +8,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||
|
||||
from struct import pack
|
||||
from itertools import izip, count, chain
|
||||
from itertools import count, chain
|
||||
import io
|
||||
import time
|
||||
import random
|
||||
@ -30,7 +30,7 @@ import calibre
|
||||
from calibre import plugins
|
||||
msdes, msdeserror = plugins['msdes']
|
||||
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
|
||||
|
||||
__all__ = ['LitWriter']
|
||||
@ -406,7 +406,7 @@ class LitWriter(object):
|
||||
1, CCHUNK_SIZE, 0x20000, ULL_NEG1, 1))
|
||||
cchunk = io.BytesIO()
|
||||
last = 0
|
||||
for i, dcount in izip(count(), dcounts):
|
||||
for i, dcount in zip(count(), dcounts):
|
||||
cchunk.write(decint(last))
|
||||
cchunk.write(decint(dcount))
|
||||
cchunk.write(decint(i))
|
||||
@ -510,8 +510,7 @@ class LitWriter(object):
|
||||
data.write(pack('<Bc', 1, '\\'))
|
||||
offset = 0
|
||||
for state in states:
|
||||
items = manifest[state]
|
||||
items.sort()
|
||||
items = sorted(manifest[state])
|
||||
data.write(pack('<I', len(items)))
|
||||
for item in items:
|
||||
id, media_type = item.id, item.media_type
|
||||
@ -702,7 +701,7 @@ class LitWriter(object):
|
||||
ichunk = None
|
||||
if len(ddata) > 1:
|
||||
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()
|
||||
prev = cid - 1 if cid > 0 else ULL_NEG1
|
||||
next = cid + 1 if cid < cidmax else ULL_NEG1
|
||||
|
@ -135,7 +135,7 @@ def get_title_sort_pat(lang=None):
|
||||
|
||||
|
||||
_ignore_starts = u'\'"'+u''.join(codepoint_to_chr(x) for x in
|
||||
range(0x2018, 0x201e)+[0x2032, 0x2033])
|
||||
list(range(0x2018, 0x201e))+[0x2032, 0x2033])
|
||||
|
||||
|
||||
def title_sort(title, order=None, lang=None):
|
||||
|
@ -9,7 +9,6 @@ __copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys, os, struct, textwrap
|
||||
from itertools import izip
|
||||
|
||||
from calibre import CurrentDir
|
||||
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.reader.headers import NULL_INDEX
|
||||
from calibre.utils.imghdr import what
|
||||
from polyglot.builtins import zip
|
||||
|
||||
|
||||
class FDST(object):
|
||||
@ -36,7 +36,7 @@ class FDST(object):
|
||||
if rest:
|
||||
raise ValueError('FDST record has trailing data: '
|
||||
'%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):
|
||||
ans = ['FDST record']
|
||||
@ -340,5 +340,3 @@ def inspect_mobi(mobi_file, ddir):
|
||||
part.dump(os.path.join(ddir, 'files'))
|
||||
|
||||
f.dump_flows(os.path.join(ddir, 'flows'))
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import struct, re, os
|
||||
from collections import namedtuple
|
||||
from itertools import repeat, izip
|
||||
from itertools import repeat
|
||||
from uuid import uuid4
|
||||
|
||||
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.oeb.parse_utils import parse_html
|
||||
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
|
||||
|
||||
Part = namedtuple('Part',
|
||||
@ -125,7 +125,7 @@ class Mobi8Reader(object):
|
||||
sec_start, num_sections = struct.unpack_from(b'>LL', header, 4)
|
||||
secs = struct.unpack_from(b'>%dL' % (num_sections*2),
|
||||
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 = []
|
||||
if self.header.skelidx != NULL_INDEX:
|
||||
|
@ -8,8 +8,8 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, shutil, tempfile
|
||||
import SocketServer
|
||||
|
||||
from polyglot import socketserver
|
||||
from polyglot.http_server import SimpleHTTPRequestHandler
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ def run_devel_server():
|
||||
js.write(compile_pyj(f.read()).encode('utf-8'))
|
||||
PORT = 8000
|
||||
Handler = SimpleHTTPRequestHandler
|
||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||
print('Serving CFI test at http://localhost:%d' % PORT)
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
|
@ -8,7 +8,6 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||
|
||||
import sys, os, uuid, copy, re, io
|
||||
from itertools import izip
|
||||
from collections import defaultdict
|
||||
|
||||
from lxml import etree
|
||||
@ -28,7 +27,7 @@ from calibre.utils.localization import get_lang
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
from calibre.constants import __appname__, __version__
|
||||
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
|
||||
|
||||
__all__ = ['OEBReader']
|
||||
@ -541,7 +540,7 @@ class OEBReader(object):
|
||||
use = titles
|
||||
if len(titles) > len(set(titles)):
|
||||
use = headers
|
||||
for title, item in izip(use, self.oeb.spine):
|
||||
for title, item in zip(use, self.oeb.spine):
|
||||
if not item.linear:
|
||||
continue
|
||||
toc.add(title, item.href)
|
||||
|
@ -8,10 +8,10 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import re
|
||||
from itertools import izip, groupby
|
||||
from itertools import groupby
|
||||
from operator import itemgetter
|
||||
from collections import Counter, OrderedDict
|
||||
from polyglot.builtins import map
|
||||
from polyglot.builtins import map, zip
|
||||
|
||||
from calibre import as_unicode
|
||||
from calibre.ebooks.pdf.render.common import (Array, String, Stream,
|
||||
@ -194,7 +194,7 @@ class Font(object):
|
||||
|
||||
def write_widths(self, objects):
|
||||
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))}
|
||||
counter = Counter()
|
||||
for g, w in widths.iteritems():
|
||||
|
@ -1288,7 +1288,7 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False):
|
||||
if force_compile or not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime:
|
||||
if not summary:
|
||||
info('\tCompiling form', form)
|
||||
buf = io.BytesIO()
|
||||
buf = io.StringIO()
|
||||
compileUi(form, buf)
|
||||
dat = buf.getvalue()
|
||||
dat = dat.replace('import images_rc', '')
|
||||
@ -1298,7 +1298,7 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False):
|
||||
dat = dat.replace('_("d MMM yyyy")', '"d MMM yyyy"')
|
||||
dat = pat.sub(sub, dat)
|
||||
|
||||
open(compiled_form, 'wb').write(dat)
|
||||
open(compiled_form, 'w').write(dat)
|
||||
num += 1
|
||||
if num:
|
||||
info('Compiled %d forms' % num)
|
||||
|
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, re
|
||||
from functools import partial
|
||||
from itertools import izip
|
||||
|
||||
from PyQt5.Qt import (
|
||||
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.utils.icu import sort_key
|
||||
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): # {{{
|
||||
@ -229,7 +228,7 @@ class TagsView(QTreeView): # {{{
|
||||
expanded_categories.append(category.category_key)
|
||||
states = [c.tag.state 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
|
||||
|
||||
def reread_collapse_parameters(self):
|
||||
|
@ -7,7 +7,6 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os, textwrap, unicodedata
|
||||
from itertools import izip
|
||||
from collections import OrderedDict
|
||||
|
||||
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.matcher import get_char, Matcher
|
||||
from calibre.gui2.complete2 import EditWithComplete
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, zip
|
||||
|
||||
ROOT = QModelIndex()
|
||||
PARAGRAPH_SEPARATOR = '\u2029'
|
||||
@ -348,7 +347,7 @@ class Results(QWidget):
|
||||
[(p.setTextFormat(Qt.RichText), p.setTextOption(self.text_option)) for p in prefixes]
|
||||
self.maxwidth = max([x.size().width() for x in prefixes])
|
||||
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:
|
||||
self.results = ()
|
||||
self.current_result = -1
|
||||
|
@ -6,8 +6,8 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import itertools, time, traceback, locale
|
||||
from itertools import repeat, izip, imap
|
||||
import time, traceback, locale
|
||||
from itertools import repeat
|
||||
from datetime import timedelta
|
||||
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.opf2 import metadata_to_opf
|
||||
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): # {{{
|
||||
@ -863,7 +863,7 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
self.search_restriction_book_count = len(self._map)
|
||||
return list(self._map)
|
||||
matches = self.parse(q)
|
||||
tmap = list(itertools.repeat(False, len(self._data)))
|
||||
tmap = list(repeat(False, len(self._data)))
|
||||
for x in matches:
|
||||
tmap[x] = True
|
||||
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')
|
||||
else:
|
||||
# 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())))
|
||||
|
||||
# Set the values in the cache
|
||||
@ -1039,7 +1039,7 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
db.initialize_template_cache()
|
||||
|
||||
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:
|
||||
self._data[r[0]] = CacheRow(db, self.composites, r,
|
||||
self.series_col, self.series_sort_col)
|
||||
@ -1099,7 +1099,7 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
if only_ids is None:
|
||||
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:
|
||||
tmap[x] = True
|
||||
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
|
||||
from collections import namedtuple
|
||||
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
||||
from itertools import chain, repeat, izip_longest
|
||||
from itertools import chain, repeat
|
||||
from operator import itemgetter
|
||||
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'}
|
||||
if is_py3:
|
||||
import zlib
|
||||
from itertools import zip_longest
|
||||
else:
|
||||
zlib, zlib2_err = plugins['zlib2']
|
||||
if zlib2_err:
|
||||
raise RuntimeError('Failed to load the zlib2 module with error: ' + zlib2_err)
|
||||
del zlib2_err
|
||||
from itertools import izip_longest as zip_longest
|
||||
|
||||
|
||||
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)
|
||||
outheaders.set('Content-Length', '%d' % size, 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
|
||||
return output
|
||||
|
||||
|
@ -7,13 +7,17 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import errno, os, numbers
|
||||
from itertools import izip_longest
|
||||
from collections import namedtuple, OrderedDict
|
||||
from operator import attrgetter
|
||||
from functools import partial
|
||||
|
||||
from calibre.constants import config_dir
|
||||
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')
|
||||
|
||||
@ -193,7 +197,7 @@ options = []
|
||||
def grouper(n, iterable, fillvalue=None):
|
||||
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
||||
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):
|
||||
|
@ -7,13 +7,12 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import httplib, sys, inspect, re, time, numbers, json as jsonlib, textwrap
|
||||
from itertools import izip
|
||||
from operator import attrgetter
|
||||
|
||||
from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError
|
||||
from calibre.srv.utils import http_date
|
||||
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
|
||||
|
||||
default_methods = frozenset(('HEAD', 'GET'))
|
||||
@ -171,7 +170,7 @@ class Route(object):
|
||||
def matches(self, path):
|
||||
args_map = self.defaults.copy()
|
||||
num = 0
|
||||
for component, (name, matched) in izip(path, self.matchers):
|
||||
for component, (name, matched) in zip(path, self.matchers):
|
||||
num += 1
|
||||
if matched is True:
|
||||
args_map[name] = component
|
||||
|
@ -7,11 +7,11 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from itertools import izip
|
||||
from struct import unpack_from, pack, calcsize
|
||||
|
||||
from calibre.utils.fonts.sfnt import UnknownTable, DateTimeProperty, FixedProperty
|
||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from polyglot.builtins import zip
|
||||
|
||||
|
||||
class HeadTable(UnknownTable):
|
||||
@ -47,7 +47,7 @@ class HeadTable(UnknownTable):
|
||||
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
||||
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)
|
||||
|
||||
def update(self):
|
||||
@ -85,7 +85,7 @@ class HorizontalHeader(UnknownTable):
|
||||
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
||||
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)
|
||||
|
||||
raw = hmtx.raw
|
||||
@ -149,7 +149,7 @@ class OS2Table(UnknownTable):
|
||||
self._fmt = ('>%s'%(''.join(field_types[1::2]))).encode('ascii')
|
||||
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)
|
||||
|
||||
def zero_fstype(self):
|
||||
@ -168,4 +168,3 @@ class PostTable(UnknownTable):
|
||||
return
|
||||
(self._version, self._italic_angle, self.underline_position,
|
||||
self.underline_thickness) = unpack_from(b'>llhh', self.raw)
|
||||
|
||||
|
@ -7,11 +7,11 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from itertools import izip
|
||||
from struct import unpack_from, pack
|
||||
|
||||
from calibre.utils.fonts.sfnt import UnknownTable, FixedProperty
|
||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from polyglot.builtins import zip
|
||||
|
||||
|
||||
class MaxpTable(UnknownTable):
|
||||
@ -39,12 +39,9 @@ class MaxpTable(UnknownTable):
|
||||
self._fmt = b'>lH' + b'H'*(len(self.fields)-2)
|
||||
|
||||
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)
|
||||
|
||||
def update(self):
|
||||
vals = [getattr(self, f) for f in self._fields]
|
||||
self.raw = pack(self._fmt, *vals)
|
||||
|
||||
|
||||
|
||||
|
@ -13,8 +13,7 @@ from operator import itemgetter
|
||||
from collections import OrderedDict
|
||||
from itertools import islice
|
||||
|
||||
from itertools import izip
|
||||
from polyglot.builtins import map, unicode_type, range
|
||||
from polyglot.builtins import map, unicode_type, range, zip
|
||||
|
||||
from calibre import detect_ncpus as cpu_count, as_unicode
|
||||
from calibre.constants import plugins, filesystem_encoding
|
||||
@ -270,7 +269,7 @@ class CScorer(object):
|
||||
|
||||
def __call__(self, 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
|
||||
|
||||
|
||||
|
@ -13,14 +13,11 @@ A coffeescript compiler and a simple web server that automatically serves
|
||||
coffeescript files as javascript.
|
||||
'''
|
||||
import sys, traceback, io
|
||||
if sys.version_info.major > 2:
|
||||
print('This script is not Python 3 compatible. Run it with Python 2',
|
||||
file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
|
||||
import time, os, sys, re, SocketServer
|
||||
import time, os, sys, re
|
||||
from threading import Lock, local
|
||||
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler
|
||||
|
||||
from polyglot import socketserver
|
||||
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
|
||||
|
||||
# Compiler {{{
|
||||
|
||||
@ -255,7 +252,7 @@ class Handler(HTTPRequestHandler): # {{{
|
||||
# }}}
|
||||
|
||||
|
||||
class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): # {{{
|
||||
class Server(socketserver.ThreadingMixIn, HTTPServer): # {{{
|
||||
daemon_threads = True
|
||||
|
||||
def handle_error(self, request, client_address):
|
||||
|
@ -8,10 +8,9 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, sys, re
|
||||
from itertools import izip
|
||||
|
||||
from calibre.constants import iswindows
|
||||
from polyglot.builtins import range
|
||||
from polyglot.builtins import range, zip
|
||||
|
||||
if iswindows:
|
||||
import ctypes.wintypes
|
||||
@ -31,7 +30,7 @@ def fmt(code):
|
||||
|
||||
|
||||
RATTRIBUTES = dict(
|
||||
izip(range(1, 9), (
|
||||
zip(range(1, 9), (
|
||||
'bold',
|
||||
'dark',
|
||||
'',
|
||||
@ -46,7 +45,7 @@ ATTRIBUTES = {v:fmt(k) for k, v in RATTRIBUTES.iteritems()}
|
||||
del ATTRIBUTES['']
|
||||
|
||||
RBACKGROUNDS = dict(
|
||||
izip(range(41, 48), (
|
||||
zip(range(41, 48), (
|
||||
'red',
|
||||
'green',
|
||||
'yellow',
|
||||
@ -59,7 +58,7 @@ RBACKGROUNDS = dict(
|
||||
BACKGROUNDS = {v:fmt(k) for k, v in RBACKGROUNDS.iteritems()}
|
||||
|
||||
RCOLORS = dict(
|
||||
izip(range(31, 38), (
|
||||
zip(range(31, 38), (
|
||||
'red',
|
||||
'green',
|
||||
'yellow',
|
||||
|
@ -7,7 +7,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
from polyglot.builtins import is_py3
|
||||
|
||||
if is_py3:
|
||||
from http.server import BaseHTTPServer, SimpleHTTPRequestHandler
|
||||
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
||||
else:
|
||||
import BaseHTTPServer # noqa
|
||||
from BaseHTTPServer import HTTPServer # noqa
|
||||
from SimpleHTTPServer import SimpleHTTPRequestHandler # noqa
|
||||
|
10
src/polyglot/socketserver.py
Executable file
10
src/polyglot/socketserver.py
Executable file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
|
||||
|
||||
from polyglot.builtins import is_py3
|
||||
|
||||
if is_py3:
|
||||
from socketserver import TCPServer, ThreadingMixIn # noqa
|
||||
else:
|
||||
from SocketServer import TCPServer, ThreadingMixIn # noqa
|
Loading…
x
Reference in New Issue
Block a user