This commit is contained in:
Kovid Goyal 2019-03-21 18:15:34 +05:30
commit 9f31662571
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
28 changed files with 109 additions and 113 deletions

View file

@ -58,7 +58,7 @@ def build_images(self):
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)

View file

@ -241,9 +241,9 @@ def run(self, opts):
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)

View file

@ -90,12 +90,12 @@ def do_coffee_compile(self, opts, timestamp=False, ignore_errors=False):
updated = {}
for arcname in todo:
name = arcname.rpartition('.')[0]
print ('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if
print('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if
timestamp else '', name))
src, sig = src_files[arcname]
js, errors = compile_coffeescript(open(src, 'rb').read(), filename=src)
if errors:
print ('\n\tCompilation of %s failed'%name)
print('\n\tCompilation of %s failed'%name)
for line in errors:
print(line, file=sys.stderr)
if ignore_errors:
@ -105,8 +105,8 @@ def do_coffee_compile(self, opts, timestamp=False, ignore_errors=False):
else:
if opts.show_js:
self.show_js(js)
print ('#'*80)
print ('#'*80)
print('#'*80)
print('#'*80)
zi = zipfile.ZipInfo()
zi.filename = arcname
zi.date_time = time.localtime()[:6]
@ -168,7 +168,7 @@ def run(self, opts):
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 @@ def mkitaiji(self, src, dst):
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 @@ def mkkanadict(self, src, dst):
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(' ')

View file

@ -4,9 +4,8 @@
__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 @@ def __init__(self, *args, **kwargs):
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)

View file

@ -9,8 +9,7 @@
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 @@ def set_marked_ids(self, id_dict):
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...

View file

@ -9,7 +9,6 @@
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.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 @@ def upload_books(self, files, names, on_card=None, end_session=True,
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 @@ def add_books_to_metadata(self, mtp_files, metadata, booklists):
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),

View file

@ -9,7 +9,6 @@
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.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 @@ def create_oebbook(self, htmlpath, basedir, opts, log, mi):
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)

View file

@ -8,7 +8,7 @@
__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 @@
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 @@ def _write_content(self):
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 @@ def _build_manifest(self):
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 @@ def _build_dchunks(self):
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

View file

@ -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):

View file

@ -9,7 +9,6 @@
__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.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 @@ def __init__(self, raw):
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']
@ -96,14 +96,14 @@ def __init__(self, mf):
self.read_tbs()
def print_header(self, f=sys.stdout):
print (str(self.mf.palmdb).encode('utf-8'), file=f)
print (file=f)
print ('Record headers:', file=f)
print(str(self.mf.palmdb).encode('utf-8'), file=f)
print(file=f)
print('Record headers:', file=f)
for i, r in enumerate(self.mf.records):
print ('%6d. %s'%(i, r.header), file=f)
print('%6d. %s'%(i, r.header), file=f)
print (file=f)
print (str(self.mf.mobi8_header).encode('utf-8'), file=f)
print(file=f)
print(str(self.mf.mobi8_header).encode('utf-8'), file=f)
def read_fdst(self):
self.fdst = None
@ -202,7 +202,7 @@ def extract_resources(self, records):
resource_index = len(container.resources)
elif sig == b'\xa0\xa0\xa0\xa0' and len(payload) == 4:
if container is None:
print ('Found an end of container record with no container, ignoring')
print('Found an end of container record with no container, ignoring')
else:
container.resources.append(None)
continue
@ -287,7 +287,7 @@ def read_tbs(self):
except:
calculated_bytes = b'failed to calculate tbs bytes'
if calculated_bytes != otbs:
print ('WARNING: TBS mismatch for record %d'%i)
print('WARNING: TBS mismatch for record %d'%i)
desc.append('WARNING: TBS mismatch!')
desc.append('Calculated sequences: %r'%calculated_sequences)
desc.append('')
@ -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'))

View file

@ -9,7 +9,7 @@
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.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 @@ def read_indices(self):
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:

View file

@ -8,8 +8,8 @@
__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()

View file

@ -8,7 +8,6 @@
__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.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 @@ def _toc_from_spine(self, opf):
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)

View file

@ -8,10 +8,10 @@
__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 @@ def write_to_unicode(self, objects):
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():

View file

@ -1288,7 +1288,7 @@ def sub(match):
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 sub(match):
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)

View file

@ -9,7 +9,6 @@
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 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 @@ def get_state(self):
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):

View file

@ -7,7 +7,6 @@
__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.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'
@ -78,7 +77,7 @@ def tag(self):
def test(cls):
d = cls()
if d.exec_() == d.Accepted:
print (d.tag)
print(d.tag)
# }}}
@ -348,7 +347,7 @@ def __call__(self, results):
[(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
@ -476,7 +475,7 @@ def test(cls):
items = get_items_from_dir(os.getcwdu(), lambda x:not x.endswith('.pyc'))
d = cls(items)
d.exec_()
print (d.selected_result)
print(d.selected_result)
# }}}
@ -1038,7 +1037,7 @@ def filtered_properties(self):
def test(cls):
d = cls()
if d.exec_() == d.Accepted:
print (d.filtered_properties)
print(d.filtered_properties)
# }}}

View file

@ -6,8 +6,8 @@
__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.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 @@ def search_getting_ids(self, query, search_restriction,
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 @@ def set_marked_ids(self, id_dict):
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 @@ def refresh(self, db, field=None, ascending=True):
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 @@ def multisort(self, fields=[], subsort=False, only_ids=None):
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]]

View file

@ -9,7 +9,7 @@
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 @@
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 @@ def finalize_output(self, output, request, is_http1):
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

View file

@ -7,13 +7,17 @@
__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 @@ def __new__(cls, *args):
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):

View file

@ -7,13 +7,12 @@
__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 @@ def route_error(msg):
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

View file

@ -7,11 +7,11 @@
__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 @@ def __init__(self, *args, **kwargs):
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 @@ def read_data(self, hmtx):
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 @@ def read_data(self):
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 @@ def read_data(self):
return
(self._version, self._italic_angle, self.underline_position,
self.underline_thickness) = unpack_from(b'>llhh', self.raw)

View file

@ -7,11 +7,11 @@
__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 @@ def __init__(self, *args, **kwargs):
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)

View file

@ -13,8 +13,7 @@
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 @@ def __init__(
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

View file

@ -13,14 +13,11 @@
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 @@ def compile_coffeescript(self, src):
# }}}
class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): # {{{
class Server(socketserver.ThreadingMixIn, HTTPServer): # {{{
daemon_threads = True
def handle_error(self, request, client_address):
@ -264,10 +261,10 @@ def handle_error(self, request, client_address):
The default is to print a traceback and continue.
"""
print ('-'*40)
print ('Exception happened during processing of request', request)
print('-'*40)
print('Exception happened during processing of request', request)
traceback.print_exc() # XXX But this goes to stderr!
print ('-'*40)
print('-'*40)
# }}}
@ -323,9 +320,9 @@ def main():
from pygments.lexers import JavascriptLexer
from pygments.formatters import TerminalFormatter
from pygments import highlight
print (highlight(ans, JavascriptLexer(), TerminalFormatter()))
print(highlight(ans, JavascriptLexer(), TerminalFormatter()))
else:
print (ans.encode(sys.stdout.encoding or 'utf-8'))
print(ans.encode(sys.stdout.encoding or 'utf-8'))
else:
serve(port=args.port, host=args.host)

View file

@ -8,10 +8,9 @@
__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 @@ def fmt(code):
del ATTRIBUTES['']
RBACKGROUNDS = dict(
izip(range(41, 48), (
zip(range(41, 48), (
'red',
'green',
'yellow',
@ -59,7 +58,7 @@ def fmt(code):
BACKGROUNDS = {v:fmt(k) for k, v in RBACKGROUNDS.iteritems()}
RCOLORS = dict(
izip(range(31, 38), (
zip(range(31, 38), (
'red',
'green',
'yellow',
@ -170,10 +169,10 @@ def write_unicode_text(self, text, ignore_errors=False):
# to use raster fonts (the default). In this case
# rather than failing, write an informative error
# message and the asciized version of the text.
print ('Non-ASCII text detected. You must set your Console\'s font to'
print('Non-ASCII text detected. You must set your Console\'s font to'
' Lucida Console or Consolas or some other TrueType font to see this text', file=self.stream, end=' -- ')
from calibre.utils.filenames import ascii_text
print (ascii_text(t + text), file=self.stream, end='')
print(ascii_text(t + text), file=self.stream, end='')
continue
if not ignore_errors:
raise ctypes.WinError(err)

View file

@ -7,7 +7,7 @@
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
View 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