mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Get rid of some xrange
This commit is contained in:
parent
55151a3cdd
commit
d1e30dfcac
@ -54,10 +54,10 @@ def build_manual(language, base):
|
|||||||
return p.wait()
|
return p.wait()
|
||||||
try:
|
try:
|
||||||
if not skip_pdf:
|
if not skip_pdf:
|
||||||
for i in xrange(3):
|
for i in range(3):
|
||||||
run_cmd(['pdflatex', '-interaction=nonstopmode', 'calibre.tex'])
|
run_cmd(['pdflatex', '-interaction=nonstopmode', 'calibre.tex'])
|
||||||
run_cmd(['makeindex', '-s', 'python.ist', 'calibre.idx'])
|
run_cmd(['makeindex', '-s', 'python.ist', 'calibre.idx'])
|
||||||
for i in xrange(2):
|
for i in range(2):
|
||||||
run_cmd(['pdflatex', '-interaction=nonstopmode', 'calibre.tex'])
|
run_cmd(['pdflatex', '-interaction=nonstopmode', 'calibre.tex'])
|
||||||
if not os.path.exists('calibre.pdf'):
|
if not os.path.exists('calibre.pdf'):
|
||||||
print('Failed to build pdf file, see calibre.log in the latex directory', file=sys.stderr)
|
print('Failed to build pdf file, see calibre.log in the latex directory', file=sys.stderr)
|
||||||
|
@ -76,7 +76,7 @@ class ElDiplo_Recipe(BasicNewsRecipe):
|
|||||||
summaryurl = re.sub(r'\?.*', '', a['href'])
|
summaryurl = re.sub(r'\?.*', '', a['href'])
|
||||||
summaryurl = 'http://www.eldiplo.org' + summaryurl
|
summaryurl = 'http://www.eldiplo.org' + summaryurl
|
||||||
|
|
||||||
for pagenum in xrange(1, 10):
|
for pagenum in range(1, 10):
|
||||||
soup = self.index_to_soup(
|
soup = self.index_to_soup(
|
||||||
'{0}/?cms1_paging_p_b32={1}'.format(summaryurl, pagenum))
|
'{0}/?cms1_paging_p_b32={1}'.format(summaryurl, pagenum))
|
||||||
thedivs = soup.findAll(True, attrs={'class': ['interna']})
|
thedivs = soup.findAll(True, attrs={'class': ['interna']})
|
||||||
|
@ -13,7 +13,7 @@ from functools import partial
|
|||||||
|
|
||||||
from setup import Command, __appname__, __version__, require_git_master, build_cache_dir, edit_file
|
from setup import Command, __appname__, __version__, require_git_master, build_cache_dir, edit_file
|
||||||
from setup.parallel_build import parallel_check_output
|
from setup.parallel_build import parallel_check_output
|
||||||
from polyglot.builtins import codepoint_to_chr, iteritems
|
from polyglot.builtins import codepoint_to_chr, iteritems, range
|
||||||
is_ci = os.environ.get('CI', '').lower() == 'true'
|
is_ci = os.environ.get('CI', '').lower() == 'true'
|
||||||
|
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class POT(Command): # {{{
|
|||||||
self.tx(['set', '-r', 'calibre.' + slug, '--source', '-l', 'en', '-t', 'PO', dest])
|
self.tx(['set', '-r', 'calibre.' + slug, '--source', '-l', 'en', '-t', 'PO', dest])
|
||||||
with open(self.j(self.d(tbase), '.tx/config'), 'r+b') as f:
|
with open(self.j(self.d(tbase), '.tx/config'), 'r+b') as f:
|
||||||
lines = f.read().splitlines()
|
lines = f.read().splitlines()
|
||||||
for i in xrange(len(lines)):
|
for i in range(len(lines)):
|
||||||
line = lines[i]
|
line = lines[i]
|
||||||
if line == '[calibre.%s]' % slug:
|
if line == '[calibre.%s]' % slug:
|
||||||
lines.insert(i+1, 'file_filter = manual/<lang>/%s.po' % bname)
|
lines.insert(i+1, 'file_filter = manual/<lang>/%s.po' % bname)
|
||||||
|
@ -4,7 +4,7 @@ __copyright__ = '2008, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import sys, os, re, time, random, warnings
|
import sys, os, re, time, random, warnings
|
||||||
from polyglot.builtins import builtins, codepoint_to_chr, unicode_type
|
from polyglot.builtins import builtins, codepoint_to_chr, unicode_type, range
|
||||||
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
||||||
from math import floor
|
from math import floor
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@ -113,7 +113,7 @@ def confirm_config_name(name):
|
|||||||
|
|
||||||
_filename_sanitize = re.compile(r'[\xae\0\\|\?\*<":>\+/]')
|
_filename_sanitize = re.compile(r'[\xae\0\\|\?\*<":>\+/]')
|
||||||
_filename_sanitize_unicode = frozenset([u'\\', u'|', u'?', u'*', u'<',
|
_filename_sanitize_unicode = frozenset([u'\\', u'|', u'?', u'*', u'<',
|
||||||
u'"', u':', u'>', u'+', u'/'] + list(map(codepoint_to_chr, xrange(32))))
|
u'"', u':', u'>', u'+', u'/'] + list(map(codepoint_to_chr, range(32))))
|
||||||
|
|
||||||
|
|
||||||
def sanitize_file_name(name, substitute='_', as_unicode=False):
|
def sanitize_file_name(name, substitute='_', as_unicode=False):
|
||||||
|
@ -9,6 +9,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
SPOOL_SIZE = 30*1024*1024
|
SPOOL_SIZE = 30*1024*1024
|
||||||
|
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
def _get_next_series_num_for_list(series_indices, unwrap=True):
|
def _get_next_series_num_for_list(series_indices, unwrap=True):
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
@ -22,17 +24,17 @@ def _get_next_series_num_for_list(series_indices, unwrap=True):
|
|||||||
if tweaks['series_index_auto_increment'] == 'next':
|
if tweaks['series_index_auto_increment'] == 'next':
|
||||||
return floor(series_indices[-1]) + 1
|
return floor(series_indices[-1]) + 1
|
||||||
if tweaks['series_index_auto_increment'] == 'first_free':
|
if tweaks['series_index_auto_increment'] == 'first_free':
|
||||||
for i in xrange(1, 10000):
|
for i in range(1, 10000):
|
||||||
if i not in series_indices:
|
if i not in series_indices:
|
||||||
return i
|
return i
|
||||||
# really shouldn't get here.
|
# really shouldn't get here.
|
||||||
if tweaks['series_index_auto_increment'] == 'next_free':
|
if tweaks['series_index_auto_increment'] == 'next_free':
|
||||||
for i in xrange(int(ceil(series_indices[0])), 10000):
|
for i in range(int(ceil(series_indices[0])), 10000):
|
||||||
if i not in series_indices:
|
if i not in series_indices:
|
||||||
return i
|
return i
|
||||||
# really shouldn't get here.
|
# really shouldn't get here.
|
||||||
if tweaks['series_index_auto_increment'] == 'last_free':
|
if tweaks['series_index_auto_increment'] == 'last_free':
|
||||||
for i in xrange(int(ceil(series_indices[-1])), 0, -1):
|
for i in range(int(ceil(series_indices[-1])), 0, -1):
|
||||||
if i not in series_indices:
|
if i not in series_indices:
|
||||||
return i
|
return i
|
||||||
return series_indices[-1] + 1
|
return series_indices[-1] + 1
|
||||||
|
@ -13,6 +13,7 @@ from collections import defaultdict
|
|||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
from calibre.utils.date import parse_date, UNDEFINED_DATE, utc_tz
|
from calibre.utils.date import parse_date, UNDEFINED_DATE, utc_tz
|
||||||
from calibre.ebooks.metadata import author_to_author_sort
|
from calibre.ebooks.metadata import author_to_author_sort
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
_c_speedup = plugins['speedup'][0].parse_date
|
_c_speedup = plugins['speedup'][0].parse_date
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ def c_parse(val):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
ans = datetime(year, month, day, hour, minutes, seconds, tzinfo=utc_tz)
|
ans = datetime(year, month, day, hour, minutes, seconds, tzinfo=utc_tz)
|
||||||
if tzsecs is not 0:
|
if tzsecs != 0:
|
||||||
ans -= timedelta(seconds=tzsecs)
|
ans -= timedelta(seconds=tzsecs)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
ans = UNDEFINED_DATE
|
ans = UNDEFINED_DATE
|
||||||
@ -43,7 +44,7 @@ def c_parse(val):
|
|||||||
return UNDEFINED_DATE
|
return UNDEFINED_DATE
|
||||||
|
|
||||||
|
|
||||||
ONE_ONE, MANY_ONE, MANY_MANY = xrange(3)
|
ONE_ONE, MANY_ONE, MANY_MANY = range(3)
|
||||||
|
|
||||||
null = object()
|
null = object()
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import time, random
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
from calibre.db.locking import SHLock, RWLockWrapper, LockingError
|
from calibre.db.locking import SHLock, RWLockWrapper, LockingError
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
class TestLock(BaseTest):
|
class TestLock(BaseTest):
|
||||||
@ -155,7 +156,7 @@ class TestLock(BaseTest):
|
|||||||
done = []
|
done = []
|
||||||
|
|
||||||
def lots_of_acquires():
|
def lots_of_acquires():
|
||||||
for _ in xrange(1000):
|
for _ in range(1000):
|
||||||
shared = random.choice([True,False])
|
shared = random.choice([True,False])
|
||||||
lock.acquire(shared=shared)
|
lock.acquire(shared=shared)
|
||||||
lock.acquire(shared=shared)
|
lock.acquire(shared=shared)
|
||||||
@ -167,7 +168,7 @@ class TestLock(BaseTest):
|
|||||||
lock.release()
|
lock.release()
|
||||||
lock.release()
|
lock.release()
|
||||||
done.append(True)
|
done.append(True)
|
||||||
threads = [Thread(target=lots_of_acquires) for _ in xrange(10)]
|
threads = [Thread(target=lots_of_acquires) for _ in range(10)]
|
||||||
for t in threads:
|
for t in threads:
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import weakref, operator
|
import weakref, operator
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import izip, imap
|
from itertools import izip, imap
|
||||||
from polyglot.builtins import map, unicode_type
|
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
|
||||||
@ -49,7 +49,7 @@ class TableRow(object):
|
|||||||
view = self.view()
|
view = self.view()
|
||||||
if isinstance(obj, slice):
|
if isinstance(obj, slice):
|
||||||
return [view._field_getters[c](self.book_id)
|
return [view._field_getters[c](self.book_id)
|
||||||
for c in xrange(*obj.indices(len(view._field_getters)))]
|
for c in range(*obj.indices(len(view._field_getters)))]
|
||||||
else:
|
else:
|
||||||
return view._field_getters[obj](self.book_id)
|
return view._field_getters[obj](self.book_id)
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class TableRow(object):
|
|||||||
return self.column_count
|
return self.column_count
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for i in xrange(self.column_count):
|
for i in range(self.column_count):
|
||||||
yield self[i]
|
yield self[i]
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from threading import Lock
|
|||||||
from calibre import prints, as_unicode
|
from calibre import prints, as_unicode
|
||||||
from calibre.constants import (iswindows, isosx, plugins, islinux, isfreebsd,
|
from calibre.constants import (iswindows, isosx, plugins, islinux, isfreebsd,
|
||||||
isnetbsd)
|
isnetbsd)
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
osx_scanner = linux_scanner = freebsd_scanner = netbsd_scanner = None
|
osx_scanner = linux_scanner = freebsd_scanner = netbsd_scanner = None
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ if iswindows:
|
|||||||
def drive_is_ok(letter, max_tries=10, debug=False):
|
def drive_is_ok(letter, max_tries=10, debug=False):
|
||||||
import win32file
|
import win32file
|
||||||
with drive_ok_lock:
|
with drive_ok_lock:
|
||||||
for i in xrange(max_tries):
|
for i in range(max_tries):
|
||||||
try:
|
try:
|
||||||
win32file.GetDiskFreeSpaceEx(letter+':\\')
|
win32file.GetDiskFreeSpaceEx(letter+':\\')
|
||||||
return True
|
return True
|
||||||
@ -87,9 +88,9 @@ class LibUSBScanner(object):
|
|||||||
memory()
|
memory()
|
||||||
for num in (1, 10, 100):
|
for num in (1, 10, 100):
|
||||||
start = memory()
|
start = memory()
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
self()
|
self()
|
||||||
for i in xrange(3):
|
for i in range(3):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
print('Mem consumption increased by:', memory() - start, 'MB', end=' ')
|
print('Mem consumption increased by:', memory() - start, 'MB', end=' ')
|
||||||
print('after', num, 'repeats')
|
print('after', num, 'repeats')
|
||||||
@ -219,17 +220,17 @@ def test_for_mem_leak():
|
|||||||
scanner = DeviceScanner()
|
scanner = DeviceScanner()
|
||||||
scanner.scan()
|
scanner.scan()
|
||||||
memory() # load the psutil library
|
memory() # load the psutil library
|
||||||
for i in xrange(3):
|
for i in range(3):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
for reps in (1, 10, 100, 1000):
|
for reps in (1, 10, 100, 1000):
|
||||||
for i in xrange(3):
|
for i in range(3):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
h1 = gc_histogram()
|
h1 = gc_histogram()
|
||||||
startmem = memory()
|
startmem = memory()
|
||||||
for i in xrange(reps):
|
for i in range(reps):
|
||||||
scanner.scan()
|
scanner.scan()
|
||||||
for i in xrange(3):
|
for i in range(3):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
usedmem = memory(startmem)
|
usedmem = memory(startmem)
|
||||||
prints('Memory used in %d repetitions of scan(): %.5f KB'%(reps,
|
prints('Memory used in %d repetitions of scan(): %.5f KB'%(reps,
|
||||||
|
@ -35,7 +35,7 @@ from calibre.utils.config import Config, ConfigProxy, JSONConfig, dynamic
|
|||||||
from calibre.utils.date import UNDEFINED_DATE
|
from calibre.utils.date import UNDEFINED_DATE
|
||||||
from calibre.utils.file_type_icons import EXT_MAP
|
from calibre.utils.file_type_icons import EXT_MAP
|
||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes, range
|
||||||
|
|
||||||
try:
|
try:
|
||||||
NO_URL_FORMATTING = QUrl.None_
|
NO_URL_FORMATTING = QUrl.None_
|
||||||
@ -1025,11 +1025,11 @@ class Application(QApplication):
|
|||||||
|
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return [col.getRgb() for col in
|
return [col.getRgb() for col in
|
||||||
(QColorDialog.customColor(i) for i in xrange(QColorDialog.customCount()))]
|
(QColorDialog.customColor(i) for i in range(QColorDialog.customCount()))]
|
||||||
|
|
||||||
def fset(self, colors):
|
def fset(self, colors):
|
||||||
num = min(len(colors), QColorDialog.customCount())
|
num = min(len(colors), QColorDialog.customCount())
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
QColorDialog.setCustomColor(i, QColor(*colors[i]))
|
QColorDialog.setCustomColor(i, QColor(*colors[i]))
|
||||||
return property(fget=fget, fset=fset)
|
return property(fget=fget, fset=fset)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from PyQt5.Qt import (QFontInfo, QFontMetrics, Qt, QFont, QFontDatabase, QPen,
|
|||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.gui2 import choose_files, error_dialog, info_dialog, empty_index
|
from calibre.gui2 import choose_files, error_dialog, info_dialog, empty_index
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
def add_fonts(parent):
|
def add_fonts(parent):
|
||||||
@ -268,7 +268,7 @@ class FontFamilyDialog(QDialog):
|
|||||||
q = icu_lower(unicode_type(self.search.text())).strip()
|
q = icu_lower(unicode_type(self.search.text())).strip()
|
||||||
if not q:
|
if not q:
|
||||||
return
|
return
|
||||||
r = (xrange(i-1, -1, -1) if backwards else xrange(i+1,
|
r = (range(i-1, -1, -1) if backwards else range(i+1,
|
||||||
len(self.families)))
|
len(self.families)))
|
||||||
for j in r:
|
for j in r:
|
||||||
f = self.families[j]
|
f = self.families[j]
|
||||||
|
@ -14,7 +14,7 @@ from Queue import Queue, Empty
|
|||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
|
|
||||||
from polyglot.builtins import reraise
|
from polyglot.builtins import reraise, range
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QImageReader, QFormLayout, QVBoxLayout, QSplitter, QGroupBox, QListWidget,
|
QImageReader, QFormLayout, QVBoxLayout, QSplitter, QGroupBox, QListWidget,
|
||||||
@ -496,7 +496,7 @@ def get_covers(themes, callback, num_of_workers=8):
|
|||||||
else:
|
else:
|
||||||
callback(metadata, cdata)
|
callback(metadata, cdata)
|
||||||
|
|
||||||
for w in xrange(num_of_workers):
|
for w in range(num_of_workers):
|
||||||
t = Thread(name='IconThemeCover', target=run)
|
t = Thread(name='IconThemeCover', target=run)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
@ -703,7 +703,7 @@ class ChooseTheme(Dialog):
|
|||||||
get_covers(self.themes, self.cover_downloaded.emit)
|
get_covers(self.themes, self.cover_downloaded.emit)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for i in xrange(self.theme_list.count()):
|
for i in range(self.theme_list.count()):
|
||||||
yield self.theme_list.item(i)
|
yield self.theme_list.item(i)
|
||||||
|
|
||||||
def item_from_name(self, name):
|
def item_from_name(self, name):
|
||||||
|
@ -12,6 +12,7 @@ from PyQt5.Qt import (QPainter, Qt, QWidget, QPropertyAnimation, QRect, QPoint,
|
|||||||
QPalette)
|
QPalette)
|
||||||
|
|
||||||
from calibre.gui2 import config
|
from calibre.gui2 import config
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
class Pointer(QWidget):
|
class Pointer(QWidget):
|
||||||
@ -79,7 +80,7 @@ class Pointer(QWidget):
|
|||||||
self.animation.setEndValue(self.rect_at(1.0))
|
self.animation.setEndValue(self.rect_at(1.0))
|
||||||
self.animation.setDirection(self.animation.Backward)
|
self.animation.setDirection(self.animation.Backward)
|
||||||
num_keys = 100
|
num_keys = 100
|
||||||
for i in xrange(1, num_keys):
|
for i in range(1, num_keys):
|
||||||
i /= num_keys
|
i /= num_keys
|
||||||
self.animation.setKeyValueAt(i, self.rect_at(i))
|
self.animation.setKeyValueAt(i, self.rect_at(i))
|
||||||
self.animation.start()
|
self.animation.start()
|
||||||
@ -91,4 +92,3 @@ class Pointer(QWidget):
|
|||||||
p.setPen(Qt.NoPen)
|
p.setPen(Qt.NoPen)
|
||||||
p.drawPath(self.arrow_path)
|
p.drawPath(self.arrow_path)
|
||||||
p.end()
|
p.end()
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ from calibre.gui2.threaded_jobs import ThreadedJobServer, ThreadedJob
|
|||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
class AdaptSQP(SearchQueryParser):
|
class AdaptSQP(SearchQueryParser):
|
||||||
@ -301,7 +301,7 @@ class JobManager(QAbstractTableModel, AdaptSQP): # {{{
|
|||||||
def show_hidden_jobs(self):
|
def show_hidden_jobs(self):
|
||||||
for j in self.jobs:
|
for j in self.jobs:
|
||||||
j.hidden_in_gui = False
|
j.hidden_in_gui = False
|
||||||
for r in xrange(len(self.jobs)):
|
for r in range(len(self.jobs)):
|
||||||
self.dataChanged.emit(self.index(r, 0), self.index(r, 0))
|
self.dataChanged.emit(self.index(r, 0), self.index(r, 0))
|
||||||
|
|
||||||
def kill_job(self, job, view):
|
def kill_job(self, job, view):
|
||||||
@ -710,7 +710,7 @@ class JobsDialog(QDialog, Ui_JobsDialog):
|
|||||||
self.proxy_model.beginResetModel(), self.proxy_model.endResetModel()
|
self.proxy_model.beginResetModel(), self.proxy_model.endResetModel()
|
||||||
|
|
||||||
def hide_all(self, *args):
|
def hide_all(self, *args):
|
||||||
self.model.hide_jobs(list(xrange(0,
|
self.model.hide_jobs(list(range(0,
|
||||||
self.model.rowCount(QModelIndex()))))
|
self.model.rowCount(QModelIndex()))))
|
||||||
self.proxy_model.beginResetModel(), self.proxy_model.endResetModel()
|
self.proxy_model.beginResetModel(), self.proxy_model.endResetModel()
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ from calibre.utils.icu import sort_key, lower
|
|||||||
from calibre.gui2 import error_dialog, info_dialog
|
from calibre.gui2 import error_dialog, info_dialog
|
||||||
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
||||||
from calibre.gui2.search_box import SearchBox2
|
from calibre.gui2.search_box import SearchBox2
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ class ConfigModel(SearchQueryParser, QAbstractItemModel):
|
|||||||
for node in self.all_shortcuts:
|
for node in self.all_shortcuts:
|
||||||
s = node.data
|
s = node.data
|
||||||
s['keys'] = tuple(keys_map[s['unique_name']])
|
s['keys'] = tuple(keys_map[s['unique_name']])
|
||||||
for r in xrange(self.rowCount()):
|
for r in range(self.rowCount()):
|
||||||
group = self.index(r, 0)
|
group = self.index(r, 0)
|
||||||
num = self.rowCount(group)
|
num = self.rowCount(group)
|
||||||
if num > 0:
|
if num > 0:
|
||||||
|
@ -28,7 +28,7 @@ from calibre.utils.config import dynamic, prefs
|
|||||||
from calibre.utils.ipc import RC, gui_socket_address
|
from calibre.utils.ipc import RC, gui_socket_address
|
||||||
from calibre.utils.lock import singleinstance
|
from calibre.utils.lock import singleinstance
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
winutil = plugins['winutil'][0]
|
winutil = plugins['winutil'][0]
|
||||||
@ -478,7 +478,7 @@ def shutdown_other(rc=None):
|
|||||||
return # No running instance found
|
return # No running instance found
|
||||||
rc.conn.send('shutdown:')
|
rc.conn.send('shutdown:')
|
||||||
prints(_('Shutdown command sent, waiting for shutdown...'))
|
prints(_('Shutdown command sent, waiting for shutdown...'))
|
||||||
for i in xrange(50):
|
for i in range(50):
|
||||||
if singleinstance(singleinstance_name):
|
if singleinstance(singleinstance_name):
|
||||||
return
|
return
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
@ -22,7 +22,7 @@ from calibre.gui2.widgets2 import Dialog
|
|||||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.icu import numeric_sort_key as sort_key
|
from calibre.utils.icu import numeric_sort_key as sort_key
|
||||||
from polyglot.builtins import string_or_bytes
|
from polyglot.builtins import string_or_bytes, range
|
||||||
|
|
||||||
ENTRY_ROLE = Qt.UserRole
|
ENTRY_ROLE = Qt.UserRole
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ class EditPrograms(Dialog): # {{{
|
|||||||
register_keyboard_shortcuts(finalize=True)
|
register_keyboard_shortcuts(finalize=True)
|
||||||
|
|
||||||
def update_stored_config(self):
|
def update_stored_config(self):
|
||||||
entries = [self.plist.item(i).data(ENTRY_ROLE) for i in xrange(self.plist.count())]
|
entries = [self.plist.item(i).data(ENTRY_ROLE) for i in range(self.plist.count())]
|
||||||
oprefs['entries'][self.file_type] = entries
|
oprefs['entries'][self.file_type] = entries
|
||||||
oprefs['entries'] = oprefs['entries']
|
oprefs['entries'] = oprefs['entries']
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from PyQt5.Qt import QSplitter, QTableView
|
|||||||
|
|
||||||
from calibre.gui2.library import DEFAULT_SORT
|
from calibre.gui2.library import DEFAULT_SORT
|
||||||
from calibre.gui2 import gprefs
|
from calibre.gui2 import gprefs
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
class PinTableView(QTableView):
|
class PinTableView(QTableView):
|
||||||
@ -74,7 +75,7 @@ class PinTableView(QTableView):
|
|||||||
# Because of a bug in Qt 5 we have to ensure that the header is actually
|
# Because of a bug in Qt 5 we have to ensure that the header is actually
|
||||||
# relaid out by changing this value, without this sometimes ghost
|
# relaid out by changing this value, without this sometimes ghost
|
||||||
# columns remain visible when changing libraries
|
# columns remain visible when changing libraries
|
||||||
for i in xrange(h.count()):
|
for i in range(h.count()):
|
||||||
val = h.isSectionHidden(i)
|
val = h.isSectionHidden(i)
|
||||||
h.setSectionHidden(i, not val)
|
h.setSectionHidden(i, not val)
|
||||||
h.setSectionHidden(i, val)
|
h.setSectionHidden(i, val)
|
||||||
|
@ -20,7 +20,7 @@ from calibre.gui2.ui import get_gui
|
|||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
tag_maps = JSONConfig('tag-map-rules')
|
tag_maps = JSONConfig('tag-map-rules')
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ class Rules(QWidget):
|
|||||||
@property
|
@property
|
||||||
def rules(self):
|
def rules(self):
|
||||||
ans = []
|
ans = []
|
||||||
for r in xrange(self.rule_list.count()):
|
for r in range(self.rule_list.count()):
|
||||||
ans.append(self.rule_list.item(r).data(DATA_ROLE))
|
ans.append(self.rule_list.item(r).data(DATA_ROLE))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from calibre.gui2.progress_indicator import ProgressIndicator as _ProgressIndica
|
|||||||
from calibre.gui2.dnd import (dnd_has_image, dnd_get_image, dnd_get_files,
|
from calibre.gui2.dnd import (dnd_has_image, dnd_get_image, dnd_get_files,
|
||||||
image_extensions, dnd_has_extension, DownloadDialog)
|
image_extensions, dnd_has_extension, DownloadDialog)
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
history = XMLConfig('history')
|
history = XMLConfig('history')
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{
|
|||||||
# Get all items in the combobox. If we are reseting
|
# Get all items in the combobox. If we are reseting
|
||||||
# to defaults we don't want to lose what the user
|
# to defaults we don't want to lose what the user
|
||||||
# has added.
|
# has added.
|
||||||
val_hist = [unicode_type(self.re.lineEdit().text())] + [unicode_type(self.re.itemText(i)) for i in xrange(self.re.count())]
|
val_hist = [unicode_type(self.re.lineEdit().text())] + [unicode_type(self.re.itemText(i)) for i in range(self.re.count())]
|
||||||
self.re.clear()
|
self.re.clear()
|
||||||
|
|
||||||
if defaults:
|
if defaults:
|
||||||
@ -163,7 +163,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{
|
|||||||
prefs['filename_pattern'] = pat
|
prefs['filename_pattern'] = pat
|
||||||
|
|
||||||
history = []
|
history = []
|
||||||
history_pats = [unicode_type(self.re.lineEdit().text())] + [unicode_type(self.re.itemText(i)) for i in xrange(self.re.count())]
|
history_pats = [unicode_type(self.re.lineEdit().text())] + [unicode_type(self.re.itemText(i)) for i in range(self.re.count())]
|
||||||
for p in history_pats[:24]:
|
for p in history_pats[:24]:
|
||||||
# Ensure we don't have duplicate items.
|
# Ensure we don't have duplicate items.
|
||||||
if p and p not in history:
|
if p and p not in history:
|
||||||
|
@ -4,6 +4,9 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
''' Code to manage ebook library'''
|
''' Code to manage ebook library'''
|
||||||
|
|
||||||
|
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
def db(path=None, read_only=False):
|
def db(path=None, read_only=False):
|
||||||
from calibre.db.legacy import LibraryDatabase
|
from calibre.db.legacy import LibraryDatabase
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
@ -32,13 +35,13 @@ def generate_test_db(library_path, # {{{
|
|||||||
|
|
||||||
def randstr(length):
|
def randstr(length):
|
||||||
return ''.join(random.choice(letters) for i in
|
return ''.join(random.choice(letters) for i in
|
||||||
xrange(length))
|
range(length))
|
||||||
|
|
||||||
all_tags = [randstr(tag_length) for j in xrange(num_of_tags)]
|
all_tags = [randstr(tag_length) for j in range(num_of_tags)]
|
||||||
print('Generated', num_of_tags, 'tags')
|
print('Generated', num_of_tags, 'tags')
|
||||||
all_authors = [randstr(author_length) for j in xrange(num_of_authors)]
|
all_authors = [randstr(author_length) for j in range(num_of_authors)]
|
||||||
print('Generated', num_of_authors, 'authors')
|
print('Generated', num_of_authors, 'authors')
|
||||||
all_titles = [randstr(title_length) for j in xrange(num_of_records)]
|
all_titles = [randstr(title_length) for j in range(num_of_records)]
|
||||||
print('Generated', num_of_records, 'titles')
|
print('Generated', num_of_records, 'titles')
|
||||||
|
|
||||||
testdb = db(library_path)
|
testdb = db(library_path)
|
||||||
@ -51,9 +54,9 @@ def generate_test_db(library_path, # {{{
|
|||||||
print(i+1, end=' ')
|
print(i+1, end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
authors = random.randint(1, max_authors)
|
authors = random.randint(1, max_authors)
|
||||||
authors = [random.choice(all_authors) for i in xrange(authors)]
|
authors = [random.choice(all_authors) for i in range(authors)]
|
||||||
tags = random.randint(0, max_tags)
|
tags = random.randint(0, max_tags)
|
||||||
tags = [random.choice(all_tags) for i in xrange(tags)]
|
tags = [random.choice(all_tags) for i in range(tags)]
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
mi = Metadata(title, authors)
|
mi = Metadata(title, authors)
|
||||||
mi.tags = tags
|
mi.tags = tags
|
||||||
@ -80,5 +83,3 @@ def current_library_name():
|
|||||||
path = current_library_path()
|
path = current_library_path()
|
||||||
if path:
|
if path:
|
||||||
return posixpath.basename(path)
|
return posixpath.basename(path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import pdb, socket, inspect, sys, select, os, atexit, time
|
|||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.constants import cache_dir
|
from calibre.constants import cache_dir
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
PROMPT = b'(debug) '
|
PROMPT = b'(debug) '
|
||||||
QUESTION = b'\x00\x01\x02'
|
QUESTION = b'\x00\x01\x02'
|
||||||
@ -96,7 +97,7 @@ def set_trace(port=4444, skip=None):
|
|||||||
def cli(port=4444):
|
def cli(port=4444):
|
||||||
prints('Connecting to remote debugger on port %d...' % port)
|
prints('Connecting to remote debugger on port %d...' % port)
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
for i in xrange(20):
|
for i in range(20):
|
||||||
try:
|
try:
|
||||||
sock.connect(('127.0.0.1', port))
|
sock.connect(('127.0.0.1', port))
|
||||||
break
|
break
|
||||||
@ -147,5 +148,6 @@ def cli(port=4444):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cli()
|
cli()
|
||||||
|
@ -25,9 +25,10 @@ from calibre.utils.socket_inheritance import set_socket_inherit
|
|||||||
from calibre.utils.logging import ThreadSafeLog
|
from calibre.utils.logging import ThreadSafeLog
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from calibre.utils.mdns import get_external_ip
|
from calibre.utils.mdns import get_external_ip
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
READ, WRITE, RDWR, WAIT = 'READ', 'WRITE', 'RDWR', 'WAIT'
|
READ, WRITE, RDWR, WAIT = 'READ', 'WRITE', 'RDWR', 'WAIT'
|
||||||
WAKEUP, JOB_DONE = bytes(bytearray(xrange(2)))
|
WAKEUP, JOB_DONE = bytes(bytearray(range(2)))
|
||||||
IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41)
|
IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41)
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ from calibre.utils.icu import collation_order
|
|||||||
from calibre.utils.localization import calibre_langcode_to_name
|
from calibre.utils.localization import calibre_langcode_to_name
|
||||||
from calibre.library.comments import comments_to_html, markdown
|
from calibre.library.comments import comments_to_html, markdown
|
||||||
from calibre.library.field_metadata import category_icon_map
|
from calibre.library.field_metadata import category_icon_map
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split())
|
IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split())
|
||||||
|
|
||||||
@ -573,7 +574,7 @@ def dump_tags_model(m):
|
|||||||
def dump_node(index, level=-1):
|
def dump_node(index, level=-1):
|
||||||
if level > -1:
|
if level > -1:
|
||||||
ans.append(indent*level + index.data(Qt.UserRole).dump_data())
|
ans.append(indent*level + index.data(Qt.UserRole).dump_data())
|
||||||
for i in xrange(m.rowCount(index)):
|
for i in range(m.rowCount(index)):
|
||||||
dump_node(m.index(i, 0, index), level + 1)
|
dump_node(m.index(i, 0, index), level + 1)
|
||||||
if level == 0:
|
if level == 0:
|
||||||
ans.append('')
|
ans.append('')
|
||||||
|
@ -11,6 +11,7 @@ from Queue import Queue, Full
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
class Worker(Thread):
|
class Worker(Thread):
|
||||||
@ -52,7 +53,7 @@ class ThreadPool(object):
|
|||||||
|
|
||||||
def __init__(self, log, notify_server, count=10, queue_size=1000):
|
def __init__(self, log, notify_server, count=10, queue_size=1000):
|
||||||
self.request_queue, self.result_queue = Queue(queue_size), Queue(queue_size)
|
self.request_queue, self.result_queue = Queue(queue_size), Queue(queue_size)
|
||||||
self.workers = [Worker(log, notify_server, i, self.request_queue, self.result_queue) for i in xrange(count)]
|
self.workers = [Worker(log, notify_server, i, self.request_queue, self.result_queue) for i in range(count)]
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
for w in self.workers:
|
for w in self.workers:
|
||||||
|
@ -14,7 +14,7 @@ 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
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
default_methods = frozenset(('HEAD', 'GET'))
|
default_methods = frozenset(('HEAD', 'GET'))
|
||||||
|
|
||||||
@ -259,8 +259,8 @@ class Router(object):
|
|||||||
lsz = max(len(r.matchers) for r in self)
|
lsz = max(len(r.matchers) for r in self)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
lsz = 0
|
lsz = 0
|
||||||
self.min_size_map = {sz:frozenset(r for r in self if r.min_size <= sz) for sz in xrange(lsz + 1)}
|
self.min_size_map = {sz:frozenset(r for r in self if r.min_size <= sz) for sz in range(lsz + 1)}
|
||||||
self.max_size_map = {sz:frozenset(r for r in self if r.max_size >= sz) for sz in xrange(lsz + 1)}
|
self.max_size_map = {sz:frozenset(r for r in self if r.max_size >= sz) for sz in range(lsz + 1)}
|
||||||
self.soak_routes = sorted(frozenset(r for r in self if r.soak_up_extra), key=attrgetter('min_size'), reverse=True)
|
self.soak_routes = sorted(frozenset(r for r in self if r.soak_up_extra), key=attrgetter('min_size'), reverse=True)
|
||||||
|
|
||||||
def find_route(self, path):
|
def find_route(self, path):
|
||||||
|
@ -13,7 +13,7 @@ from urlparse import parse_qs
|
|||||||
import repr as reprlib
|
import repr as reprlib
|
||||||
from email.utils import formatdate
|
from email.utils import formatdate
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from polyglot.builtins import map, unicode_type
|
from polyglot.builtins import map, unicode_type, range
|
||||||
from urllib import quote as urlquote
|
from urllib import quote as urlquote
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ class RotatingStream(object):
|
|||||||
if not self.max_size or self.current_pos <= self.max_size or self.filename in ('/dev/stdout', '/dev/stderr'):
|
if not self.max_size or self.current_pos <= self.max_size or self.filename in ('/dev/stdout', '/dev/stderr'):
|
||||||
return
|
return
|
||||||
self.stream.close()
|
self.stream.close()
|
||||||
for i in xrange(self.history - 1, 0, -1):
|
for i in range(self.history - 1, 0, -1):
|
||||||
src, dest = '%s.%d' % (self.filename, i), '%s.%d' % (self.filename, i+1)
|
src, dest = '%s.%d' % (self.filename, i), '%s.%d' % (self.filename, i+1)
|
||||||
self.rename(src, dest)
|
self.rename(src, dest)
|
||||||
self.rename(self.filename, '%s.%d' % (self.filename, 1))
|
self.rename(self.filename, '%s.%d' % (self.filename, 1))
|
||||||
|
@ -3,7 +3,7 @@ __copyright__ = '2010, sengian <sengian1@gmail.com>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re, htmlentitydefs
|
import re, htmlentitydefs
|
||||||
from polyglot.builtins import codepoint_to_chr, map
|
from polyglot.builtins import codepoint_to_chr, map, range
|
||||||
from calibre.constants import plugins, preferred_encoding
|
from calibre.constants import plugins, preferred_encoding
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -28,7 +28,7 @@ def clean_ascii_chars(txt, charlist=None):
|
|||||||
return ''
|
return ''
|
||||||
global _ascii_pat
|
global _ascii_pat
|
||||||
if _ascii_pat is None:
|
if _ascii_pat is None:
|
||||||
chars = set(xrange(32))
|
chars = set(range(32))
|
||||||
chars.add(127)
|
chars.add(127)
|
||||||
for x in (9, 10, 13):
|
for x in (9, 10, 13):
|
||||||
chars.remove(x)
|
chars.remove(x)
|
||||||
|
@ -14,7 +14,7 @@ from calibre.constants import (
|
|||||||
filesystem_encoding, iswindows, plugins, preferred_encoding, isosx
|
filesystem_encoding, iswindows, plugins, preferred_encoding, isosx
|
||||||
)
|
)
|
||||||
from calibre.utils.localization import get_udc
|
from calibre.utils.localization import get_udc
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
def ascii_text(orig):
|
def ascii_text(orig):
|
||||||
@ -501,7 +501,7 @@ def atomic_rename(oldpath, newpath):
|
|||||||
are on different volumes. If succeeds, guaranteed to be atomic. newpath may
|
are on different volumes. If succeeds, guaranteed to be atomic. newpath may
|
||||||
or may not exist. If it exists, it is replaced. '''
|
or may not exist. If it exists, it is replaced. '''
|
||||||
if iswindows:
|
if iswindows:
|
||||||
for i in xrange(10):
|
for i in range(10):
|
||||||
try:
|
try:
|
||||||
rename_file(oldpath, newpath)
|
rename_file(oldpath, newpath)
|
||||||
break
|
break
|
||||||
|
@ -15,7 +15,7 @@ from collections import OrderedDict
|
|||||||
from itertools import islice
|
from itertools import islice
|
||||||
|
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
from polyglot.builtins import map, unicode_type
|
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
|
||||||
@ -194,7 +194,7 @@ def process_item(ctx, haystack, needle):
|
|||||||
key = (hidx, nidx, last_idx)
|
key = (hidx, nidx, last_idx)
|
||||||
mem = ctx.memory.get(key, None)
|
mem = ctx.memory.get(key, None)
|
||||||
if mem is None:
|
if mem is None:
|
||||||
for i in xrange(nidx, len(needle)):
|
for i in range(nidx, len(needle)):
|
||||||
n = needle[i]
|
n = needle[i]
|
||||||
if (len(haystack) - hidx < len(needle) - i):
|
if (len(haystack) - hidx < len(needle) - i):
|
||||||
score = 0
|
score = 0
|
||||||
@ -295,12 +295,12 @@ def test(return_tests=False):
|
|||||||
m('one')
|
m('one')
|
||||||
|
|
||||||
start = memory()
|
start = memory()
|
||||||
for i in xrange(10):
|
for i in range(10):
|
||||||
doit(str(i))
|
doit(str(i))
|
||||||
gc.collect()
|
gc.collect()
|
||||||
used10 = memory() - start
|
used10 = memory() - start
|
||||||
start = memory()
|
start = memory()
|
||||||
for i in xrange(100):
|
for i in range(100):
|
||||||
doit(str(i))
|
doit(str(i))
|
||||||
gc.collect()
|
gc.collect()
|
||||||
used100 = memory() - start
|
used100 = memory() - start
|
||||||
|
@ -23,7 +23,7 @@ from calibre.utils.filenames import atomic_rename
|
|||||||
from calibre.utils.terminal import ANSIStream
|
from calibre.utils.terminal import ANSIStream
|
||||||
from duktape import Context, JSError, to_python
|
from duktape import Context, JSError, to_python
|
||||||
from lzma.xz import compress, decompress
|
from lzma.xz import compress, decompress
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||||
|
|
||||||
@ -372,12 +372,12 @@ class Repl(Thread):
|
|||||||
self.from_repl.put(val[0])
|
self.from_repl.put(val[0])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, JSError):
|
if isinstance(e, JSError):
|
||||||
print (e.stack or e.message, file=sys.stderr)
|
print(e.stack or e.message, file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
for i in xrange(100):
|
for i in range(100):
|
||||||
# Do this many times to ensure we dont deadlock
|
# Do this many times to ensure we dont deadlock
|
||||||
self.from_repl.put(None)
|
self.from_repl.put(None)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
print_function)
|
print_function)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlyFileBuffer(object):
|
class ReadOnlyFileBuffer(object):
|
||||||
@ -90,7 +91,7 @@ def svg_path_to_painter_path(d):
|
|||||||
return float(b''.join(chars))
|
return float(b''.join(chars))
|
||||||
|
|
||||||
def parse_floats(num, x_offset=0, y_offset=0):
|
def parse_floats(num, x_offset=0, y_offset=0):
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
val = parse_float()
|
val = parse_float()
|
||||||
yield val + (x_offset if i % 2 == 0 else y_offset)
|
yield val + (x_offset if i % 2 == 0 else y_offset)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import os, sys, re
|
|||||||
from itertools import izip
|
from itertools import izip
|
||||||
|
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
import ctypes.wintypes
|
import ctypes.wintypes
|
||||||
@ -30,7 +31,7 @@ def fmt(code):
|
|||||||
|
|
||||||
|
|
||||||
RATTRIBUTES = dict(
|
RATTRIBUTES = dict(
|
||||||
izip(xrange(1, 9), (
|
izip(range(1, 9), (
|
||||||
'bold',
|
'bold',
|
||||||
'dark',
|
'dark',
|
||||||
'',
|
'',
|
||||||
@ -45,7 +46,7 @@ ATTRIBUTES = {v:fmt(k) for k, v in RATTRIBUTES.iteritems()}
|
|||||||
del ATTRIBUTES['']
|
del ATTRIBUTES['']
|
||||||
|
|
||||||
RBACKGROUNDS = dict(
|
RBACKGROUNDS = dict(
|
||||||
izip(xrange(41, 48), (
|
izip(range(41, 48), (
|
||||||
'red',
|
'red',
|
||||||
'green',
|
'green',
|
||||||
'yellow',
|
'yellow',
|
||||||
@ -58,7 +59,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(xrange(31, 38), (
|
izip(range(31, 38), (
|
||||||
'red',
|
'red',
|
||||||
'green',
|
'green',
|
||||||
'yellow',
|
'yellow',
|
||||||
|
@ -9,7 +9,7 @@ from calibre.web.feeds.news import (BasicNewsRecipe, CustomIndexRecipe,
|
|||||||
AutomaticNewsRecipe, CalibrePeriodical)
|
AutomaticNewsRecipe, CalibrePeriodical)
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from polyglot.builtins import unicode_type, codepoint_to_chr
|
from polyglot.builtins import unicode_type, codepoint_to_chr, range
|
||||||
|
|
||||||
basic_recipes = (BasicNewsRecipe, AutomaticNewsRecipe, CustomIndexRecipe,
|
basic_recipes = (BasicNewsRecipe, AutomaticNewsRecipe, CustomIndexRecipe,
|
||||||
CalibrePeriodical)
|
CalibrePeriodical)
|
||||||
@ -47,6 +47,7 @@ def compile_recipe(src):
|
|||||||
'BeautifulSoup':BeautifulSoup,
|
'BeautifulSoup':BeautifulSoup,
|
||||||
'unicode': unicode_type,
|
'unicode': unicode_type,
|
||||||
'unichr': codepoint_to_chr,
|
'unichr': codepoint_to_chr,
|
||||||
|
'xrange': range,
|
||||||
}
|
}
|
||||||
exec(src, namespace)
|
exec(src, namespace)
|
||||||
|
|
||||||
|
@ -1194,7 +1194,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
|
|||||||
htmlattrs = {}
|
htmlattrs = {}
|
||||||
if c:
|
if c:
|
||||||
htmlattrs['class'] = "TC-%s" % c.replace(".","_")
|
htmlattrs['class'] = "TC-%s" % c.replace(".","_")
|
||||||
for x in xrange(repeated):
|
for x in range(repeated):
|
||||||
self.emptytag('col', htmlattrs)
|
self.emptytag('col', htmlattrs)
|
||||||
self.purgedata()
|
self.purgedata()
|
||||||
|
|
||||||
@ -1580,8 +1580,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
|
|||||||
"""
|
"""
|
||||||
self.lines = []
|
self.lines = []
|
||||||
self._wfunc = self._wlines
|
self._wfunc = self._wlines
|
||||||
if isinstance(odffile, (bytes, type(u'')) \
|
if isinstance(odffile, (bytes, type(u''))) or hasattr(odffile, 'read'): # Added by Kovid
|
||||||
or hasattr(odffile, 'read'): # Added by Kovid
|
|
||||||
self.document = load(odffile)
|
self.document = load(odffile)
|
||||||
else:
|
else:
|
||||||
self.document = odffile
|
self.document = odffile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user