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:
|
for s in sources:
|
||||||
files.append('<file>%s</file>'%s)
|
files.append('<file>%s</file>'%s)
|
||||||
manifest = '<RCC>\n<qresource prefix="/">\n%s\n</qresource>\n</RCC>'%'\n'.join(sorted(files))
|
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)
|
f.write(manifest)
|
||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
@ -241,9 +241,9 @@ class Manual(Command):
|
|||||||
|
|
||||||
def serve_manual(self, root):
|
def serve_manual(self, root):
|
||||||
os.chdir(root)
|
os.chdir(root)
|
||||||
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler
|
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
|
||||||
HandlerClass = SimpleHTTPRequestHandler
|
HandlerClass = SimpleHTTPRequestHandler
|
||||||
ServerClass = BaseHTTPServer.HTTPServer
|
ServerClass = HTTPServer
|
||||||
Protocol = "HTTP/1.0"
|
Protocol = "HTTP/1.0"
|
||||||
server_address = ('127.0.0.1', 8000)
|
server_address = ('127.0.0.1', 8000)
|
||||||
|
|
||||||
|
@ -90,12 +90,12 @@ class Coffee(Command): # {{{
|
|||||||
updated = {}
|
updated = {}
|
||||||
for arcname in todo:
|
for arcname in todo:
|
||||||
name = arcname.rpartition('.')[0]
|
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))
|
timestamp else '', name))
|
||||||
src, sig = src_files[arcname]
|
src, sig = src_files[arcname]
|
||||||
js, errors = compile_coffeescript(open(src, 'rb').read(), filename=src)
|
js, errors = compile_coffeescript(open(src, 'rb').read(), filename=src)
|
||||||
if errors:
|
if errors:
|
||||||
print ('\n\tCompilation of %s failed'%name)
|
print('\n\tCompilation of %s failed'%name)
|
||||||
for line in errors:
|
for line in errors:
|
||||||
print(line, file=sys.stderr)
|
print(line, file=sys.stderr)
|
||||||
if ignore_errors:
|
if ignore_errors:
|
||||||
@ -105,8 +105,8 @@ class Coffee(Command): # {{{
|
|||||||
else:
|
else:
|
||||||
if opts.show_js:
|
if opts.show_js:
|
||||||
self.show_js(js)
|
self.show_js(js)
|
||||||
print ('#'*80)
|
print('#'*80)
|
||||||
print ('#'*80)
|
print('#'*80)
|
||||||
zi = zipfile.ZipInfo()
|
zi = zipfile.ZipInfo()
|
||||||
zi.filename = arcname
|
zi.filename = arcname
|
||||||
zi.date_time = time.localtime()[:6]
|
zi.date_time = time.localtime()[:6]
|
||||||
@ -168,7 +168,7 @@ class Kakasi(Command): # {{{
|
|||||||
def mkitaiji(self, src, dst):
|
def mkitaiji(self, src, dst):
|
||||||
dic = {}
|
dic = {}
|
||||||
for line in open(src, "r"):
|
for line in open(src, "r"):
|
||||||
line = line.decode("utf-8").strip()
|
line = line.strip()
|
||||||
if line.startswith(';;'): # skip comment
|
if line.startswith(';;'): # skip comment
|
||||||
continue
|
continue
|
||||||
if re.match(r"^$",line):
|
if re.match(r"^$",line):
|
||||||
@ -182,7 +182,7 @@ class Kakasi(Command): # {{{
|
|||||||
def mkkanadict(self, src, dst):
|
def mkkanadict(self, src, dst):
|
||||||
dic = {}
|
dic = {}
|
||||||
for line in open(src, "r"):
|
for line in open(src, "r"):
|
||||||
line = line.decode("utf-8").strip()
|
line = line.strip()
|
||||||
if line.startswith(';;'): # skip comment
|
if line.startswith(';;'): # skip comment
|
||||||
continue
|
continue
|
||||||
if re.match(r"^$",line):
|
if re.match(r"^$",line):
|
||||||
@ -194,7 +194,7 @@ class Kakasi(Command): # {{{
|
|||||||
f.write(msgpack_dumps(dic))
|
f.write(msgpack_dumps(dic))
|
||||||
|
|
||||||
def parsekdict(self, line):
|
def parsekdict(self, line):
|
||||||
line = line.decode("utf-8").strip()
|
line = line.strip()
|
||||||
if line.startswith(';;'): # skip comment
|
if line.startswith(';;'): # skip comment
|
||||||
return
|
return
|
||||||
(yomi, kanji) = line.split(' ')
|
(yomi, kanji) = line.split(' ')
|
||||||
|
@ -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))
|
||||||
@ -510,8 +510,7 @@ class LitWriter(object):
|
|||||||
data.write(pack('<Bc', 1, '\\'))
|
data.write(pack('<Bc', 1, '\\'))
|
||||||
offset = 0
|
offset = 0
|
||||||
for state in states:
|
for state in states:
|
||||||
items = manifest[state]
|
items = sorted(manifest[state])
|
||||||
items.sort()
|
|
||||||
data.write(pack('<I', len(items)))
|
data.write(pack('<I', len(items)))
|
||||||
for item in items:
|
for item in items:
|
||||||
id, media_type = item.id, item.media_type
|
id, media_type = item.id, item.media_type
|
||||||
@ -702,7 +701,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
|
||||||
|
@ -135,7 +135,7 @@ def get_title_sort_pat(lang=None):
|
|||||||
|
|
||||||
|
|
||||||
_ignore_starts = u'\'"'+u''.join(codepoint_to_chr(x) for x in
|
_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):
|
def title_sort(title, order=None, lang=None):
|
||||||
|
@ -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']
|
||||||
@ -96,14 +96,14 @@ class MOBIFile(object):
|
|||||||
self.read_tbs()
|
self.read_tbs()
|
||||||
|
|
||||||
def print_header(self, f=sys.stdout):
|
def print_header(self, f=sys.stdout):
|
||||||
print (str(self.mf.palmdb).encode('utf-8'), file=f)
|
print(str(self.mf.palmdb).encode('utf-8'), file=f)
|
||||||
print (file=f)
|
print(file=f)
|
||||||
print ('Record headers:', file=f)
|
print('Record headers:', file=f)
|
||||||
for i, r in enumerate(self.mf.records):
|
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(file=f)
|
||||||
print (str(self.mf.mobi8_header).encode('utf-8'), file=f)
|
print(str(self.mf.mobi8_header).encode('utf-8'), file=f)
|
||||||
|
|
||||||
def read_fdst(self):
|
def read_fdst(self):
|
||||||
self.fdst = None
|
self.fdst = None
|
||||||
@ -202,7 +202,7 @@ class MOBIFile(object):
|
|||||||
resource_index = len(container.resources)
|
resource_index = len(container.resources)
|
||||||
elif sig == b'\xa0\xa0\xa0\xa0' and len(payload) == 4:
|
elif sig == b'\xa0\xa0\xa0\xa0' and len(payload) == 4:
|
||||||
if container is None:
|
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:
|
else:
|
||||||
container.resources.append(None)
|
container.resources.append(None)
|
||||||
continue
|
continue
|
||||||
@ -287,7 +287,7 @@ class MOBIFile(object):
|
|||||||
except:
|
except:
|
||||||
calculated_bytes = b'failed to calculate tbs bytes'
|
calculated_bytes = b'failed to calculate tbs bytes'
|
||||||
if calculated_bytes != otbs:
|
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('WARNING: TBS mismatch!')
|
||||||
desc.append('Calculated sequences: %r'%calculated_sequences)
|
desc.append('Calculated sequences: %r'%calculated_sequences)
|
||||||
desc.append('')
|
desc.append('')
|
||||||
@ -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,8 +8,8 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, shutil, tempfile
|
import os, shutil, tempfile
|
||||||
import SocketServer
|
|
||||||
|
|
||||||
|
from polyglot import socketserver
|
||||||
from polyglot.http_server import SimpleHTTPRequestHandler
|
from polyglot.http_server import SimpleHTTPRequestHandler
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ def run_devel_server():
|
|||||||
js.write(compile_pyj(f.read()).encode('utf-8'))
|
js.write(compile_pyj(f.read()).encode('utf-8'))
|
||||||
PORT = 8000
|
PORT = 8000
|
||||||
Handler = SimpleHTTPRequestHandler
|
Handler = SimpleHTTPRequestHandler
|
||||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||||
print('Serving CFI test at http://localhost:%d' % PORT)
|
print('Serving CFI test at http://localhost:%d' % PORT)
|
||||||
try:
|
try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
@ -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():
|
||||||
|
@ -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 force_compile or not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime:
|
||||||
if not summary:
|
if not summary:
|
||||||
info('\tCompiling form', form)
|
info('\tCompiling form', form)
|
||||||
buf = io.BytesIO()
|
buf = io.StringIO()
|
||||||
compileUi(form, buf)
|
compileUi(form, buf)
|
||||||
dat = buf.getvalue()
|
dat = buf.getvalue()
|
||||||
dat = dat.replace('import images_rc', '')
|
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 = dat.replace('_("d MMM yyyy")', '"d MMM yyyy"')
|
||||||
dat = pat.sub(sub, dat)
|
dat = pat.sub(sub, dat)
|
||||||
|
|
||||||
open(compiled_form, 'wb').write(dat)
|
open(compiled_form, 'w').write(dat)
|
||||||
num += 1
|
num += 1
|
||||||
if num:
|
if num:
|
||||||
info('Compiled %d forms' % num)
|
info('Compiled %d forms' % num)
|
||||||
|
@ -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'
|
||||||
@ -78,7 +77,7 @@ class InsertTag(Dialog): # {{{
|
|||||||
def test(cls):
|
def test(cls):
|
||||||
d = cls()
|
d = cls()
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
print (d.tag)
|
print(d.tag)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
@ -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
|
||||||
@ -476,7 +475,7 @@ class QuickOpen(Dialog):
|
|||||||
items = get_items_from_dir(os.getcwdu(), lambda x:not x.endswith('.pyc'))
|
items = get_items_from_dir(os.getcwdu(), lambda x:not x.endswith('.pyc'))
|
||||||
d = cls(items)
|
d = cls(items)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
print (d.selected_result)
|
print(d.selected_result)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
@ -1038,7 +1037,7 @@ class FilterCSS(Dialog): # {{{
|
|||||||
def test(cls):
|
def test(cls):
|
||||||
d = cls()
|
d = cls()
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
print (d.filtered_properties)
|
print(d.filtered_properties)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,14 +13,11 @@ A coffeescript compiler and a simple web server that automatically serves
|
|||||||
coffeescript files as javascript.
|
coffeescript files as javascript.
|
||||||
'''
|
'''
|
||||||
import sys, traceback, io
|
import sys, traceback, io
|
||||||
if sys.version_info.major > 2:
|
import time, os, sys, re
|
||||||
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
|
|
||||||
from threading import Lock, local
|
from threading import Lock, local
|
||||||
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler
|
|
||||||
|
from polyglot import socketserver
|
||||||
|
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
|
||||||
|
|
||||||
# Compiler {{{
|
# Compiler {{{
|
||||||
|
|
||||||
@ -255,7 +252,7 @@ class Handler(HTTPRequestHandler): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): # {{{
|
class Server(socketserver.ThreadingMixIn, HTTPServer): # {{{
|
||||||
daemon_threads = True
|
daemon_threads = True
|
||||||
|
|
||||||
def handle_error(self, request, client_address):
|
def handle_error(self, request, client_address):
|
||||||
@ -264,10 +261,10 @@ class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): # {{{
|
|||||||
The default is to print a traceback and continue.
|
The default is to print a traceback and continue.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
print ('-'*40)
|
print('-'*40)
|
||||||
print ('Exception happened during processing of request', request)
|
print('Exception happened during processing of request', request)
|
||||||
traceback.print_exc() # XXX But this goes to stderr!
|
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.lexers import JavascriptLexer
|
||||||
from pygments.formatters import TerminalFormatter
|
from pygments.formatters import TerminalFormatter
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
print (highlight(ans, JavascriptLexer(), TerminalFormatter()))
|
print(highlight(ans, JavascriptLexer(), TerminalFormatter()))
|
||||||
else:
|
else:
|
||||||
print (ans.encode(sys.stdout.encoding or 'utf-8'))
|
print(ans.encode(sys.stdout.encoding or 'utf-8'))
|
||||||
else:
|
else:
|
||||||
serve(port=args.port, host=args.host)
|
serve(port=args.port, host=args.host)
|
||||||
|
|
||||||
|
@ -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',
|
||||||
@ -170,10 +169,10 @@ class Detect(object):
|
|||||||
# to use raster fonts (the default). In this case
|
# to use raster fonts (the default). In this case
|
||||||
# rather than failing, write an informative error
|
# rather than failing, write an informative error
|
||||||
# message and the asciized version of the text.
|
# 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=' -- ')
|
' Lucida Console or Consolas or some other TrueType font to see this text', file=self.stream, end=' -- ')
|
||||||
from calibre.utils.filenames import ascii_text
|
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
|
continue
|
||||||
if not ignore_errors:
|
if not ignore_errors:
|
||||||
raise ctypes.WinError(err)
|
raise ctypes.WinError(err)
|
||||||
|
@ -7,7 +7,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
from polyglot.builtins import is_py3
|
from polyglot.builtins import is_py3
|
||||||
|
|
||||||
if is_py3:
|
if is_py3:
|
||||||
from http.server import BaseHTTPServer, SimpleHTTPRequestHandler
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
||||||
else:
|
else:
|
||||||
import BaseHTTPServer # noqa
|
from BaseHTTPServer import HTTPServer # noqa
|
||||||
from SimpleHTTPServer import SimpleHTTPRequestHandler # 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