mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get rid of iterkeys
dict.__iter__() is the same as iterkeys on both py2 and py3
This commit is contained in:
parent
7fd70a28e8
commit
5d46f5fbeb
@ -14,8 +14,8 @@ from functools import partial
|
|||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
from calibre.customize import (Plugin, numeric_version, platform,
|
from calibre.customize import (Plugin, numeric_version, platform,
|
||||||
InvalidPlugin, PluginNotFound)
|
InvalidPlugin, PluginNotFound)
|
||||||
from polyglot.builtins import (itervalues, iterkeys, map,
|
from polyglot.builtins import (itervalues, map, string_or_bytes,
|
||||||
string_or_bytes, unicode_type)
|
unicode_type)
|
||||||
|
|
||||||
# PEP 302 based plugin loading mechanism, works around the bug in zipimport in
|
# PEP 302 based plugin loading mechanism, works around the bug in zipimport in
|
||||||
# python 2.x that prevents importing from zip files in locations whose paths
|
# python 2.x that prevents importing from zip files in locations whose paths
|
||||||
@ -281,7 +281,7 @@ class PluginLoader(object):
|
|||||||
|
|
||||||
# Legacy plugins
|
# Legacy plugins
|
||||||
if '__init__' not in names:
|
if '__init__' not in names:
|
||||||
for name in list(iterkeys(names)):
|
for name in tuple(names):
|
||||||
if '.' not in name and name.endswith('plugin'):
|
if '.' not in name and name.endswith('plugin'):
|
||||||
names['__init__'] = names[name]
|
names['__init__'] = names[name]
|
||||||
break
|
break
|
||||||
|
@ -12,7 +12,7 @@ import os, shutil, uuid, json, glob, time, hashlib, errno, sys
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import apsw
|
import apsw
|
||||||
from polyglot.builtins import (iteritems, iterkeys, itervalues,
|
from polyglot.builtins import (iteritems, itervalues,
|
||||||
unicode_type, reraise, string_or_bytes)
|
unicode_type, reraise, string_or_bytes)
|
||||||
|
|
||||||
from calibre import isbytestring, force_unicode, prints, as_unicode
|
from calibre import isbytestring, force_unicode, prints, as_unicode
|
||||||
@ -223,7 +223,7 @@ def SortedConcatenate(sep=','):
|
|||||||
def finalize(ctxt):
|
def finalize(ctxt):
|
||||||
if len(ctxt) == 0:
|
if len(ctxt) == 0:
|
||||||
return None
|
return None
|
||||||
return sep.join(map(ctxt.get, sorted(iterkeys(ctxt))))
|
return sep.join(map(ctxt.get, sorted(ctxt)))
|
||||||
|
|
||||||
return ({}, step, finalize)
|
return ({}, step, finalize)
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ def AumSortedConcatenate():
|
|||||||
ctxt[ndx] = ':::'.join((author, sort, link))
|
ctxt[ndx] = ':::'.join((author, sort, link))
|
||||||
|
|
||||||
def finalize(ctxt):
|
def finalize(ctxt):
|
||||||
keys = list(iterkeys(ctxt))
|
keys = list(ctxt)
|
||||||
l = len(keys)
|
l = len(keys)
|
||||||
if l == 0:
|
if l == 0:
|
||||||
return None
|
return None
|
||||||
@ -734,7 +734,7 @@ class DB(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Create Tag Browser categories for custom columns
|
# Create Tag Browser categories for custom columns
|
||||||
for k in sorted(iterkeys(self.custom_column_label_map)):
|
for k in sorted(self.custom_column_label_map):
|
||||||
v = self.custom_column_label_map[k]
|
v = self.custom_column_label_map[k]
|
||||||
if v['normalized']:
|
if v['normalized']:
|
||||||
is_category = True
|
is_category = True
|
||||||
|
@ -11,7 +11,7 @@ import os, traceback, random, shutil, operator
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from collections import defaultdict, Set, MutableSet
|
from collections import defaultdict, Set, MutableSet
|
||||||
from functools import wraps, partial
|
from functools import wraps, partial
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues, unicode_type, zip, string_or_bytes
|
from polyglot.builtins import iteritems, itervalues, unicode_type, zip, string_or_bytes
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from calibre import isbytestring, as_unicode
|
from calibre import isbytestring, as_unicode
|
||||||
@ -170,7 +170,7 @@ class Cache(object):
|
|||||||
# Reconstruct the user categories, putting them into field_metadata
|
# Reconstruct the user categories, putting them into field_metadata
|
||||||
fm = self.field_metadata
|
fm = self.field_metadata
|
||||||
fm.remove_dynamic_categories()
|
fm.remove_dynamic_categories()
|
||||||
for user_cat in sorted(iterkeys(self._pref('user_categories', {})), key=sort_key):
|
for user_cat in sorted(self._pref('user_categories', {}), key=sort_key):
|
||||||
cat_name = '@' + user_cat # add the '@' to avoid name collision
|
cat_name = '@' + user_cat # add the '@' to avoid name collision
|
||||||
while cat_name:
|
while cat_name:
|
||||||
try:
|
try:
|
||||||
@ -181,7 +181,7 @@ class Cache(object):
|
|||||||
|
|
||||||
# add grouped search term user categories
|
# add grouped search term user categories
|
||||||
muc = frozenset(self._pref('grouped_search_make_user_categories', []))
|
muc = frozenset(self._pref('grouped_search_make_user_categories', []))
|
||||||
for cat in sorted(iterkeys(self._pref('grouped_search_terms', {})), key=sort_key):
|
for cat in sorted(self._pref('grouped_search_terms', {}), key=sort_key):
|
||||||
if cat in muc:
|
if cat in muc:
|
||||||
# There is a chance that these can be duplicates of an existing
|
# There is a chance that these can be duplicates of an existing
|
||||||
# user category. Print the exception and continue.
|
# user category. Print the exception and continue.
|
||||||
@ -1117,7 +1117,7 @@ class Cache(object):
|
|||||||
@read_api
|
@read_api
|
||||||
def get_a_dirtied_book(self):
|
def get_a_dirtied_book(self):
|
||||||
if self.dirtied_cache:
|
if self.dirtied_cache:
|
||||||
return random.choice(tuple(iterkeys(self.dirtied_cache)))
|
return random.choice(tuple(self.dirtied_cache))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
@ -1339,7 +1339,7 @@ class Cache(object):
|
|||||||
|
|
||||||
user_mi = mi.get_all_user_metadata(make_copy=False)
|
user_mi = mi.get_all_user_metadata(make_copy=False)
|
||||||
fm = self.field_metadata
|
fm = self.field_metadata
|
||||||
for key in iterkeys(user_mi):
|
for key in user_mi:
|
||||||
if (key in fm and user_mi[key]['datatype'] == fm[key]['datatype'] and (
|
if (key in fm and user_mi[key]['datatype'] == fm[key]['datatype'] and (
|
||||||
user_mi[key]['datatype'] != 'text' or (
|
user_mi[key]['datatype'] != 'text' or (
|
||||||
user_mi[key]['is_multiple'] == fm[key]['is_multiple']))):
|
user_mi[key]['is_multiple'] == fm[key]['is_multiple']))):
|
||||||
@ -1458,7 +1458,7 @@ class Cache(object):
|
|||||||
|
|
||||||
size_map = table.remove_formats(formats_map, self.backend)
|
size_map = table.remove_formats(formats_map, self.backend)
|
||||||
self.fields['size'].table.update_sizes(size_map)
|
self.fields['size'].table.update_sizes(size_map)
|
||||||
self._update_last_modified(tuple(iterkeys(formats_map)))
|
self._update_last_modified(tuple(formats_map))
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def get_next_series_num_for(self, series, field='series', current_indices=False):
|
def get_next_series_num_for(self, series, field='series', current_indices=False):
|
||||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, map
|
from polyglot.builtins import iteritems, unicode_type, map
|
||||||
|
|
||||||
from calibre.constants import ispy3
|
from calibre.constants import ispy3
|
||||||
from calibre.ebooks.metadata import author_to_author_sort
|
from calibre.ebooks.metadata import author_to_author_sort
|
||||||
@ -219,7 +219,7 @@ def get_categories(dbcache, sort='name', book_ids=None, first_letter_sort=False)
|
|||||||
taglist[c] = dict(map(lambda t:(icu_lower(t.name), t), items))
|
taglist[c] = dict(map(lambda t:(icu_lower(t.name), t), items))
|
||||||
|
|
||||||
# Add the category values to the user categories
|
# Add the category values to the user categories
|
||||||
for user_cat in sorted(iterkeys(user_categories), key=sort_key):
|
for user_cat in sorted(user_categories, key=sort_key):
|
||||||
items = []
|
items = []
|
||||||
names_seen = {}
|
names_seen = {}
|
||||||
user_cat_is_gst = user_cat in gst
|
user_cat_is_gst = user_cat in gst
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.config_base import tweaks
|
|||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.date import UNDEFINED_DATE, clean_date_for_sort, parse_date
|
from calibre.utils.date import UNDEFINED_DATE, clean_date_for_sort, parse_date
|
||||||
from calibre.utils.localization import calibre_langcode_to_name
|
from calibre.utils.localization import calibre_langcode_to_name
|
||||||
from polyglot.builtins import iteritems, iterkeys
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
|
||||||
def bool_sort_key(bools_are_tristate):
|
def bool_sort_key(bools_are_tristate):
|
||||||
@ -184,7 +184,7 @@ class OneToOneField(Field):
|
|||||||
return {item_id}
|
return {item_id}
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iterkeys(self.table.book_col_map)
|
return iter(self.table.book_col_map)
|
||||||
|
|
||||||
def sort_keys_for_books(self, get_metadata, lang_map):
|
def sort_keys_for_books(self, get_metadata, lang_map):
|
||||||
bcmg = self.table.book_col_map.get
|
bcmg = self.table.book_col_map.get
|
||||||
@ -456,7 +456,7 @@ class ManyToOneField(Field):
|
|||||||
return self.table.col_book_map.get(item_id, set())
|
return self.table.col_book_map.get(item_id, set())
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iterkeys(self.table.id_map)
|
return iter(self.table.id_map)
|
||||||
|
|
||||||
def sort_keys_for_books(self, get_metadata, lang_map):
|
def sort_keys_for_books(self, get_metadata, lang_map):
|
||||||
sk_map = LazySortMap(self._default_sort_key, self._sort_key, self.table.id_map)
|
sk_map = LazySortMap(self._default_sort_key, self._sort_key, self.table.id_map)
|
||||||
@ -507,7 +507,7 @@ class ManyToManyField(Field):
|
|||||||
return self.table.col_book_map.get(item_id, set())
|
return self.table.col_book_map.get(item_id, set())
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iterkeys(self.table.id_map)
|
return iter(self.table.id_map)
|
||||||
|
|
||||||
def sort_keys_for_books(self, get_metadata, lang_map):
|
def sort_keys_for_books(self, get_metadata, lang_map):
|
||||||
sk_map = LazySortMap(self._default_sort_key, self._sort_key, self.table.id_map)
|
sk_map = LazySortMap(self._default_sort_key, self._sort_key, self.table.id_map)
|
||||||
@ -561,7 +561,7 @@ class IdentifiersField(ManyToManyField):
|
|||||||
'Sort by identifier keys'
|
'Sort by identifier keys'
|
||||||
bcmg = self.table.book_col_map.get
|
bcmg = self.table.book_col_map.get
|
||||||
dv = {self._default_sort_key:None}
|
dv = {self._default_sort_key:None}
|
||||||
return lambda book_id: tuple(sorted(iterkeys(bcmg(book_id, dv))))
|
return lambda book_id: tuple(sorted(bcmg(book_id, dv)))
|
||||||
|
|
||||||
def iter_searchable_values(self, get_metadata, candidates, default_value=()):
|
def iter_searchable_values(self, get_metadata, candidates, default_value=()):
|
||||||
bcm = self.table.book_col_map
|
bcm = self.table.book_col_map
|
||||||
|
@ -15,7 +15,7 @@ from copy import deepcopy
|
|||||||
from calibre.ebooks.metadata.book.base import Metadata, SIMPLE_GET, TOP_LEVEL_IDENTIFIERS, NULL_VALUES, ALL_METADATA_FIELDS
|
from calibre.ebooks.metadata.book.base import Metadata, SIMPLE_GET, TOP_LEVEL_IDENTIFIERS, NULL_VALUES, ALL_METADATA_FIELDS
|
||||||
from calibre.ebooks.metadata.book.formatter import SafeFormat
|
from calibre.ebooks.metadata.book.formatter import SafeFormat
|
||||||
from calibre.utils.date import utcnow
|
from calibre.utils.date import utcnow
|
||||||
from polyglot.builtins import iterkeys, unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
# Lazy format metadata retrieval {{{
|
# Lazy format metadata retrieval {{{
|
||||||
'''
|
'''
|
||||||
@ -393,7 +393,7 @@ class ProxyMetadata(Metadata):
|
|||||||
|
|
||||||
def all_field_keys(self):
|
def all_field_keys(self):
|
||||||
um = ga(self, '_user_metadata')
|
um = ga(self, '_user_metadata')
|
||||||
return frozenset(ALL_METADATA_FIELDS.union(iterkeys(um)))
|
return frozenset(ALL_METADATA_FIELDS.union(frozenset(um)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _proxy_metadata(self):
|
def _proxy_metadata(self):
|
||||||
|
@ -11,7 +11,7 @@ import os
|
|||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.utils.date import isoformat, DEFAULT_DATE
|
from calibre.utils.date import isoformat, DEFAULT_DATE
|
||||||
from polyglot.builtins import iterkeys, itervalues, unicode_type
|
from polyglot.builtins import itervalues, unicode_type
|
||||||
|
|
||||||
|
|
||||||
class SchemaUpgrade(object):
|
class SchemaUpgrade(object):
|
||||||
@ -596,7 +596,7 @@ class SchemaUpgrade(object):
|
|||||||
custom_recipe_filename)
|
custom_recipe_filename)
|
||||||
bdir = os.path.dirname(custom_recipes.file_path)
|
bdir = os.path.dirname(custom_recipes.file_path)
|
||||||
for id_, title, script in recipes:
|
for id_, title, script in recipes:
|
||||||
existing = frozenset(map(int, iterkeys(custom_recipes)))
|
existing = frozenset(map(int, custom_recipes))
|
||||||
if id_ in existing:
|
if id_ in existing:
|
||||||
id_ = max(existing) + 1000
|
id_ = max(existing) + 1000
|
||||||
id_ = str(id_)
|
id_ = str(id_)
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.date import parse_date, UNDEFINED_DATE, now, dt_as_local
|
|||||||
from calibre.utils.icu import primary_contains, sort_key
|
from calibre.utils.icu import primary_contains, sort_key
|
||||||
from calibre.utils.localization import lang_map, canonicalize_lang
|
from calibre.utils.localization import lang_map, canonicalize_lang
|
||||||
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, string_or_bytes
|
from polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
||||||
|
|
||||||
CONTAINS_MATCH = 0
|
CONTAINS_MATCH = 0
|
||||||
EQUALS_MATCH = 1
|
EQUALS_MATCH = 1
|
||||||
@ -445,7 +445,7 @@ class SavedSearchQueries(object): # {{{
|
|||||||
db._set_pref(self.opt_name, smap)
|
db._set_pref(self.opt_name, smap)
|
||||||
|
|
||||||
def names(self):
|
def names(self):
|
||||||
return sorted(iterkeys(self.queries), key=sort_key)
|
return sorted(self.queries, key=sort_key)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ from io import BytesIO
|
|||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from polyglot.builtins import iterkeys
|
|
||||||
|
|
||||||
|
|
||||||
class FilesystemTest(BaseTest):
|
class FilesystemTest(BaseTest):
|
||||||
@ -56,7 +55,7 @@ class FilesystemTest(BaseTest):
|
|||||||
cache2 = self.init_cache(cl)
|
cache2 = self.init_cache(cl)
|
||||||
for c in (cache, cache2):
|
for c in (cache, cache2):
|
||||||
data = self.get_filesystem_data(c, 1)
|
data = self.get_filesystem_data(c, 1)
|
||||||
ae(set(iterkeys(orig_data)), set(iterkeys(data)))
|
ae(set(orig_data), set(data))
|
||||||
ae(orig_data, data, 'Filesystem data does not match')
|
ae(orig_data, data, 'Filesystem data does not match')
|
||||||
ae(c.field_for('path', 1), 'Moved/Moved (1)')
|
ae(c.field_for('path', 1), 'Moved/Moved (1)')
|
||||||
ae(c.field_for('path', 3), 'Moved1/Moved1 (3)')
|
ae(c.field_for('path', 3), 'Moved1/Moved1 (3)')
|
||||||
|
@ -14,7 +14,7 @@ from operator import itemgetter
|
|||||||
|
|
||||||
from calibre.library.field_metadata import fm_as_dict
|
from calibre.library.field_metadata import fm_as_dict
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
from polyglot.builtins import iteritems, iterkeys, range
|
from polyglot.builtins import iteritems, range
|
||||||
|
|
||||||
# Utils {{{
|
# Utils {{{
|
||||||
|
|
||||||
@ -316,9 +316,9 @@ class LegacyTest(BaseTest):
|
|||||||
db = self.init_old()
|
db = self.init_old()
|
||||||
cache = ndb.new_api
|
cache = ndb.new_api
|
||||||
tmap = cache.get_id_map('tags')
|
tmap = cache.get_id_map('tags')
|
||||||
t = next(iterkeys(tmap))
|
t = next(iter(tmap))
|
||||||
pmap = cache.get_id_map('publisher')
|
pmap = cache.get_id_map('publisher')
|
||||||
p = next(iterkeys(pmap))
|
p = next(iter(pmap))
|
||||||
run_funcs(self, db, ndb, (
|
run_funcs(self, db, ndb, (
|
||||||
('delete_tag_using_id', t),
|
('delete_tag_using_id', t),
|
||||||
('delete_publisher_using_id', p),
|
('delete_publisher_using_id', p),
|
||||||
|
@ -13,7 +13,7 @@ from time import time
|
|||||||
|
|
||||||
from calibre.utils.date import utc_tz
|
from calibre.utils.date import utc_tz
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues, range
|
from polyglot.builtins import iteritems, itervalues, range
|
||||||
|
|
||||||
|
|
||||||
class ReadingTest(BaseTest):
|
class ReadingTest(BaseTest):
|
||||||
@ -439,7 +439,7 @@ class ReadingTest(BaseTest):
|
|||||||
'Test getting the author sort for authors from the db'
|
'Test getting the author sort for authors from the db'
|
||||||
cache = self.init_cache()
|
cache = self.init_cache()
|
||||||
table = cache.fields['authors'].table
|
table = cache.fields['authors'].table
|
||||||
table.set_sort_names({next(iterkeys(table.id_map)): 'Fake Sort'}, cache.backend)
|
table.set_sort_names({next(iter(table.id_map)): 'Fake Sort'}, cache.backend)
|
||||||
|
|
||||||
authors = tuple(itervalues(table.id_map))
|
authors = tuple(itervalues(table.id_map))
|
||||||
nval = cache.author_sort_from_authors(authors)
|
nval = cache.author_sort_from_authors(authors)
|
||||||
|
@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import weakref, operator, numbers
|
import weakref, operator, numbers
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import (iteritems, iterkeys, itervalues, map,
|
from polyglot.builtins import (iteritems, itervalues, map,
|
||||||
unicode_type, range, zip)
|
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,8 +374,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(zip(iterkeys(id_dict), map(unicode_type,
|
self.marked_ids = {k: unicode_type(v) for k, v in iteritems(id_dict)}
|
||||||
itervalues(id_dict))))
|
|
||||||
# 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...
|
||||||
cmids = set(self.marked_ids)
|
cmids = set(self.marked_ids)
|
||||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import time, threading, traceback
|
import time, threading, traceback
|
||||||
from functools import wraps, partial
|
from functools import wraps, partial
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues, unicode_type, zip
|
from polyglot.builtins import iteritems, itervalues, unicode_type, zip
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from calibre import as_unicode, prints, force_unicode
|
from calibre import as_unicode, prints, force_unicode
|
||||||
@ -107,7 +107,7 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
|
|
||||||
# Get device data for detected devices. If there is an error, we will
|
# Get device data for detected devices. If there is an error, we will
|
||||||
# try again for that device the next time this method is called.
|
# try again for that device the next time this method is called.
|
||||||
for dev in tuple(iterkeys(self.detected_devices)):
|
for dev in tuple(self.detected_devices):
|
||||||
data = self.detected_devices.get(dev, None)
|
data = self.detected_devices.get(dev, None)
|
||||||
if data is None or data is False:
|
if data is None or data is False:
|
||||||
try:
|
try:
|
||||||
|
@ -13,7 +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 iterkeys, range
|
from polyglot.builtins import range
|
||||||
|
|
||||||
osx_scanner = linux_scanner = freebsd_scanner = netbsd_scanner = None
|
osx_scanner = linux_scanner = freebsd_scanner = netbsd_scanner = None
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class LibUSBScanner(object):
|
|||||||
dev = USBDevice(*dev)
|
dev = USBDevice(*dev)
|
||||||
dev.busnum, dev.devnum = fingerprint[:2]
|
dev.busnum, dev.devnum = fingerprint[:2]
|
||||||
ans.add(dev)
|
ans.add(dev)
|
||||||
extra = set(iterkeys(self.libusb.cache)) - seen
|
extra = set(self.libusb.cache) - seen
|
||||||
for x in extra:
|
for x in extra:
|
||||||
self.libusb.cache.pop(x, None)
|
self.libusb.cache.pop(x, None)
|
||||||
return ans
|
return ans
|
||||||
|
@ -1321,7 +1321,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
self._debug('processed cache. count=', len(books_on_device))
|
self._debug('processed cache. count=', len(books_on_device))
|
||||||
count_of_cache_items_deleted = 0
|
count_of_cache_items_deleted = 0
|
||||||
if self.client_cache_uses_lpaths:
|
if self.client_cache_uses_lpaths:
|
||||||
for lpath in tuple(self.known_metadata.iterkeys()):
|
for lpath in tuple(self.known_metadata):
|
||||||
if lpath not in lpaths_on_device:
|
if lpath not in lpaths_on_device:
|
||||||
try:
|
try:
|
||||||
uuid = self.known_metadata[lpath].get('uuid', None)
|
uuid = self.known_metadata[lpath].get('uuid', None)
|
||||||
|
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from polyglot.builtins import iterkeys, itervalues, range
|
from polyglot.builtins import itervalues, range
|
||||||
|
|
||||||
NBSP = '\xa0'
|
NBSP = '\xa0'
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ def merge_run(run):
|
|||||||
def liftable(css):
|
def liftable(css):
|
||||||
# A <span> is liftable if all its styling would work just as well if it is
|
# A <span> is liftable if all its styling would work just as well if it is
|
||||||
# specified on the parent element.
|
# specified on the parent element.
|
||||||
prefixes = {x.partition('-')[0] for x in iterkeys(css)}
|
prefixes = {x.partition('-')[0] for x in css}
|
||||||
return not (prefixes - {'text', 'font', 'letter', 'color', 'background'})
|
return not (prefixes - {'text', 'font', 'letter', 'color', 'background'})
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from lxml import etree
|
|||||||
from calibre.ebooks import parse_css_length
|
from calibre.ebooks import parse_css_length
|
||||||
from calibre.ebooks.docx.writer.utils import convert_color, int_or_zero
|
from calibre.ebooks.docx.writer.utils import convert_color, int_or_zero
|
||||||
from calibre.utils.localization import lang_as_iso639_1
|
from calibre.utils.localization import lang_as_iso639_1
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type
|
from polyglot.builtins import iteritems, unicode_type
|
||||||
from tinycss.css21 import CSS21Parser
|
from tinycss.css21 import CSS21Parser
|
||||||
|
|
||||||
css_parser = CSS21Parser()
|
css_parser = CSS21Parser()
|
||||||
@ -721,7 +721,7 @@ class StylesManager(object):
|
|||||||
heading_styles.append(style)
|
heading_styles.append(style)
|
||||||
style.id = style.name = val
|
style.id = style.name = val
|
||||||
style.seq = i
|
style.seq = i
|
||||||
self.combined_styles = sorted(iterkeys(counts), key=attrgetter('seq'))
|
self.combined_styles = sorted(counts, key=attrgetter('seq'))
|
||||||
[ls.apply() for ls in self.combined_styles]
|
[ls.apply() for ls in self.combined_styles]
|
||||||
|
|
||||||
descendant_style_map = {}
|
descendant_style_map = {}
|
||||||
|
@ -14,7 +14,7 @@ from calibre.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
|||||||
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type
|
from polyglot.builtins import iteritems, unicode_type
|
||||||
|
|
||||||
# Special sets used to optimize the performance of getting and setting
|
# Special sets used to optimize the performance of getting and setting
|
||||||
# attributes on Metadata objects
|
# attributes on Metadata objects
|
||||||
@ -137,7 +137,7 @@ class Metadata(object):
|
|||||||
return object.__getattribute__(self, field)
|
return object.__getattribute__(self, field)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if field in iterkeys(_data['user_metadata']):
|
if field in _data['user_metadata']:
|
||||||
d = _data['user_metadata'][field]
|
d = _data['user_metadata'][field]
|
||||||
val = d['#value#']
|
val = d['#value#']
|
||||||
if d['datatype'] != 'composite':
|
if d['datatype'] != 'composite':
|
||||||
@ -180,7 +180,7 @@ class Metadata(object):
|
|||||||
if val and val.lower() != 'und':
|
if val and val.lower() != 'und':
|
||||||
langs = [val]
|
langs = [val]
|
||||||
_data['languages'] = langs
|
_data['languages'] = langs
|
||||||
elif field in iterkeys(_data['user_metadata']):
|
elif field in _data['user_metadata']:
|
||||||
_data['user_metadata'][field]['#value#'] = val
|
_data['user_metadata'][field]['#value#'] = val
|
||||||
_data['user_metadata'][field]['#extra#'] = extra
|
_data['user_metadata'][field]['#extra#'] = extra
|
||||||
else:
|
else:
|
||||||
@ -190,7 +190,7 @@ class Metadata(object):
|
|||||||
self.__dict__[field] = val
|
self.__dict__[field] = val
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iterkeys(object.__getattribute__(self, '_data'))
|
return iter(object.__getattribute__(self, '_data'))
|
||||||
|
|
||||||
def has_key(self, key):
|
def has_key(self, key):
|
||||||
return key in object.__getattribute__(self, '_data')
|
return key in object.__getattribute__(self, '_data')
|
||||||
@ -219,7 +219,7 @@ class Metadata(object):
|
|||||||
|
|
||||||
def get_extra(self, field, default=None):
|
def get_extra(self, field, default=None):
|
||||||
_data = object.__getattribute__(self, '_data')
|
_data = object.__getattribute__(self, '_data')
|
||||||
if field in iterkeys(_data['user_metadata']):
|
if field in _data['user_metadata']:
|
||||||
try:
|
try:
|
||||||
return _data['user_metadata'][field]['#extra#']
|
return _data['user_metadata'][field]['#extra#']
|
||||||
except:
|
except:
|
||||||
@ -287,14 +287,14 @@ class Metadata(object):
|
|||||||
'''
|
'''
|
||||||
return a list of the custom fields in this book
|
return a list of the custom fields in this book
|
||||||
'''
|
'''
|
||||||
return iterkeys(object.__getattribute__(self, '_data')['user_metadata'])
|
return iter(object.__getattribute__(self, '_data')['user_metadata'])
|
||||||
|
|
||||||
def all_field_keys(self):
|
def all_field_keys(self):
|
||||||
'''
|
'''
|
||||||
All field keys known by this instance, even if their value is None
|
All field keys known by this instance, even if their value is None
|
||||||
'''
|
'''
|
||||||
_data = object.__getattribute__(self, '_data')
|
_data = object.__getattribute__(self, '_data')
|
||||||
return frozenset(ALL_METADATA_FIELDS.union(iterkeys(_data['user_metadata'])))
|
return frozenset(ALL_METADATA_FIELDS.union(frozenset(_data['user_metadata'])))
|
||||||
|
|
||||||
def metadata_for_field(self, key):
|
def metadata_for_field(self, key):
|
||||||
'''
|
'''
|
||||||
@ -320,7 +320,7 @@ class Metadata(object):
|
|||||||
v = self.get(attr, None)
|
v = self.get(attr, None)
|
||||||
if v is not None:
|
if v is not None:
|
||||||
result[attr] = v
|
result[attr] = v
|
||||||
for attr in iterkeys(_data['user_metadata']):
|
for attr in _data['user_metadata']:
|
||||||
v = self.get(attr, None)
|
v = self.get(attr, None)
|
||||||
if v is not None:
|
if v is not None:
|
||||||
result[attr] = v
|
result[attr] = v
|
||||||
|
@ -91,7 +91,7 @@ class GoogleImages(Source):
|
|||||||
continue
|
continue
|
||||||
if 'ou' in data:
|
if 'ou' in data:
|
||||||
ans[data['ou']] = True
|
ans[data['ou']] = True
|
||||||
return list(ans.iterkeys())
|
return list(ans)
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
@ -27,7 +27,7 @@ from calibre.utils.html2text import html2text
|
|||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
from calibre.utils.date import UNDEFINED_DATE
|
from calibre.utils.date import UNDEFINED_DATE
|
||||||
from calibre.utils.formatter import EvalFormatter
|
from calibre.utils.formatter import EvalFormatter
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues, unicode_type
|
from polyglot.builtins import iteritems, itervalues, unicode_type
|
||||||
|
|
||||||
# Download worker {{{
|
# Download worker {{{
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ def identify(log, abort, # {{{
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
sort_kwargs = dict(kwargs)
|
sort_kwargs = dict(kwargs)
|
||||||
for k in list(iterkeys(sort_kwargs)):
|
for k in list(sort_kwargs):
|
||||||
if k not in ('title', 'authors', 'identifiers'):
|
if k not in ('title', 'authors', 'identifiers'):
|
||||||
sort_kwargs.pop(k)
|
sort_kwargs.pop(k)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from calibre.ebooks.mobi.reader.headers import NULL_INDEX
|
|||||||
from calibre.ebooks.mobi.reader.index import (CNCX, parse_indx_header,
|
from calibre.ebooks.mobi.reader.index import (CNCX, parse_indx_header,
|
||||||
parse_tagx_section, parse_index_record, INDEX_HEADER_FIELDS)
|
parse_tagx_section, parse_index_record, INDEX_HEADER_FIELDS)
|
||||||
from calibre.ebooks.mobi.reader.ncx import (tag_fieldname_map, default_entry)
|
from calibre.ebooks.mobi.reader.ncx import (tag_fieldname_map, default_entry)
|
||||||
from polyglot.builtins import iteritems, iterkeys, range
|
from polyglot.builtins import iteritems, range
|
||||||
|
|
||||||
File = namedtuple('File',
|
File = namedtuple('File',
|
||||||
'file_number name divtbl_count start_position length')
|
'file_number name divtbl_count start_position length')
|
||||||
@ -140,11 +140,11 @@ class SKELIndex(Index):
|
|||||||
self.records = []
|
self.records = []
|
||||||
|
|
||||||
if self.table is not None:
|
if self.table is not None:
|
||||||
for i, text in enumerate(iterkeys(self.table)):
|
for i, text in enumerate(self.table):
|
||||||
tag_map = self.table[text]
|
tag_map = self.table[text]
|
||||||
if set(iterkeys(tag_map)) != {1, 6}:
|
if set(tag_map) != {1, 6}:
|
||||||
raise ValueError('SKEL Index has unknown tags: %s'%
|
raise ValueError('SKEL Index has unknown tags: %s'%
|
||||||
(set(iterkeys(tag_map))-{1,6}))
|
(set(tag_map)-{1,6}))
|
||||||
self.records.append(File(
|
self.records.append(File(
|
||||||
i, # file_number
|
i, # file_number
|
||||||
text, # name
|
text, # name
|
||||||
@ -161,11 +161,11 @@ class SECTIndex(Index):
|
|||||||
self.records = []
|
self.records = []
|
||||||
|
|
||||||
if self.table is not None:
|
if self.table is not None:
|
||||||
for i, text in enumerate(iterkeys(self.table)):
|
for i, text in enumerate(self.table):
|
||||||
tag_map = self.table[text]
|
tag_map = self.table[text]
|
||||||
if set(iterkeys(tag_map)) != {2, 3, 4, 6}:
|
if set(tag_map) != {2, 3, 4, 6}:
|
||||||
raise ValueError('Chunk Index has unknown tags: %s'%
|
raise ValueError('Chunk Index has unknown tags: %s'%
|
||||||
(set(iterkeys(tag_map))-{2, 3, 4, 6}))
|
(set(tag_map)-{2, 3, 4, 6}))
|
||||||
|
|
||||||
toc_text = self.cncx[tag_map[2][0]]
|
toc_text = self.cncx[tag_map[2][0]]
|
||||||
self.records.append(Elem(
|
self.records.append(Elem(
|
||||||
@ -186,9 +186,9 @@ class GuideIndex(Index):
|
|||||||
self.records = []
|
self.records = []
|
||||||
|
|
||||||
if self.table is not None:
|
if self.table is not None:
|
||||||
for i, text in enumerate(iterkeys(self.table)):
|
for i, text in enumerate(self.table):
|
||||||
tag_map = self.table[text]
|
tag_map = self.table[text]
|
||||||
if set(iterkeys(tag_map)) not in ({1, 6}, {1, 2, 3}):
|
if set(tag_map) not in ({1, 6}, {1, 2, 3}):
|
||||||
raise ValueError('Guide Index has unknown tags: %s'%
|
raise ValueError('Guide Index has unknown tags: %s'%
|
||||||
tag_map)
|
tag_map)
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ class NCXIndex(Index):
|
|||||||
entry['name'] = text
|
entry['name'] = text
|
||||||
entry['num'] = num
|
entry['num'] = num
|
||||||
|
|
||||||
for tag in iterkeys(tag_fieldname_map):
|
for tag in tag_fieldname_map:
|
||||||
fieldname, i = tag_fieldname_map[tag]
|
fieldname, i = tag_fieldname_map[tag]
|
||||||
if tag in tag_map:
|
if tag in tag_map:
|
||||||
fieldvalue = tag_map[tag][i]
|
fieldvalue = tag_map[tag][i]
|
||||||
|
@ -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 iterkeys, range, zip
|
from polyglot.builtins import range, zip
|
||||||
from polyglot.urllib import urldefrag
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
Part = namedtuple('Part',
|
Part = namedtuple('Part',
|
||||||
@ -134,7 +134,7 @@ class Mobi8Reader(object):
|
|||||||
File = namedtuple('File',
|
File = namedtuple('File',
|
||||||
'file_number name divtbl_count start_position length')
|
'file_number name divtbl_count start_position length')
|
||||||
|
|
||||||
for i, text in enumerate(iterkeys(table)):
|
for i, text in enumerate(table):
|
||||||
tag_map = table[text]
|
tag_map = table[text]
|
||||||
self.files.append(File(i, text, tag_map[1][0],
|
self.files.append(File(i, text, tag_map[1][0],
|
||||||
tag_map[6][0], tag_map[6][1]))
|
tag_map[6][0], tag_map[6][1]))
|
||||||
@ -143,7 +143,7 @@ class Mobi8Reader(object):
|
|||||||
if self.header.dividx != NULL_INDEX:
|
if self.header.dividx != NULL_INDEX:
|
||||||
table, cncx = read_index(self.kf8_sections, self.header.dividx,
|
table, cncx = read_index(self.kf8_sections, self.header.dividx,
|
||||||
self.header.codec)
|
self.header.codec)
|
||||||
for i, text in enumerate(iterkeys(table)):
|
for i, text in enumerate(table):
|
||||||
tag_map = table[text]
|
tag_map = table[text]
|
||||||
toc_text = cncx[tag_map[2][0]]
|
toc_text = cncx[tag_map[2][0]]
|
||||||
self.elems.append(Elem(int(text), toc_text, tag_map[3][0],
|
self.elems.append(Elem(int(text), toc_text, tag_map[3][0],
|
||||||
@ -156,7 +156,7 @@ class Mobi8Reader(object):
|
|||||||
Item = namedtuple('Item',
|
Item = namedtuple('Item',
|
||||||
'type title pos_fid')
|
'type title pos_fid')
|
||||||
|
|
||||||
for i, ref_type in enumerate(iterkeys(table)):
|
for i, ref_type in enumerate(table):
|
||||||
tag_map = table[ref_type]
|
tag_map = table[ref_type]
|
||||||
# ref_type, ref_title, div/frag number
|
# ref_type, ref_title, div/frag number
|
||||||
title = cncx[tag_map[1][0]]
|
title = cncx[tag_map[1][0]]
|
||||||
|
@ -13,7 +13,7 @@ from calibre import replace_entities
|
|||||||
from calibre.ebooks.metadata.toc import TOC
|
from calibre.ebooks.metadata.toc import TOC
|
||||||
from calibre.ebooks.mobi.reader.headers import NULL_INDEX
|
from calibre.ebooks.mobi.reader.headers import NULL_INDEX
|
||||||
from calibre.ebooks.mobi.reader.index import read_index
|
from calibre.ebooks.mobi.reader.index import read_index
|
||||||
from polyglot.builtins import iteritems, iterkeys
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
tag_fieldname_map = {
|
tag_fieldname_map = {
|
||||||
1: ['pos',0],
|
1: ['pos',0],
|
||||||
@ -63,7 +63,7 @@ def read_ncx(sections, index, codec):
|
|||||||
entry['name'] = text
|
entry['name'] = text
|
||||||
entry['num'] = num
|
entry['num'] = num
|
||||||
|
|
||||||
for tag in iterkeys(tag_fieldname_map):
|
for tag in tag_fieldname_map:
|
||||||
fieldname, i = tag_fieldname_map[tag]
|
fieldname, i = tag_fieldname_map[tag]
|
||||||
if tag in tag_map:
|
if tag in tag_map:
|
||||||
fieldvalue = tag_map[tag][i]
|
fieldvalue = tag_map[tag][i]
|
||||||
|
@ -14,7 +14,7 @@ from io import BytesIO
|
|||||||
from calibre.utils.img import save_cover_data_to, scale_image, image_to_data, image_from_data, resize_image
|
from calibre.utils.img import save_cover_data_to, scale_image, image_to_data, image_from_data, resize_image
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from calibre.ebooks import normalize
|
from calibre.ebooks import normalize
|
||||||
from polyglot.builtins import iterkeys, unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
from tinycss.color3 import parse_color_string
|
from tinycss.color3 import parse_color_string
|
||||||
|
|
||||||
IMAGE_MAX_SIZE = 10 * 1024 * 1024
|
IMAGE_MAX_SIZE = 10 * 1024 * 1024
|
||||||
@ -589,7 +589,7 @@ class CNCX(object): # {{{
|
|||||||
offset = 0
|
offset = 0
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
RECORD_LIMIT = 0x10000 - 1024 # kindlegen appears to use 1024, PDB limit is 0x10000
|
RECORD_LIMIT = 0x10000 - 1024 # kindlegen appears to use 1024, PDB limit is 0x10000
|
||||||
for key in iterkeys(self.strings):
|
for key in self.strings:
|
||||||
utf8 = utf8_text(key[:self.MAX_STRING_LENGTH])
|
utf8 = utf8_text(key[:self.MAX_STRING_LENGTH])
|
||||||
l = len(utf8)
|
l = len(utf8)
|
||||||
sz_bytes = encint(l)
|
sz_bytes = encint(l)
|
||||||
|
@ -14,7 +14,7 @@ from collections import OrderedDict, defaultdict
|
|||||||
|
|
||||||
from calibre.ebooks.mobi.utils import (encint, encode_number_as_hex,
|
from calibre.ebooks.mobi.utils import (encint, encode_number_as_hex,
|
||||||
encode_tbs, align_block, RECORD_SIZE, CNCX as CNCX_)
|
encode_tbs, align_block, RECORD_SIZE, CNCX as CNCX_)
|
||||||
from polyglot.builtins import filter, iteritems, iterkeys, itervalues, map, range
|
from polyglot.builtins import filter, iteritems, itervalues, map, range
|
||||||
|
|
||||||
|
|
||||||
class CNCX(CNCX_): # {{{
|
class CNCX(CNCX_): # {{{
|
||||||
@ -317,7 +317,7 @@ class TBS(object): # {{{
|
|||||||
if first_node is not None and first_node.depth > 0:
|
if first_node is not None and first_node.depth > 0:
|
||||||
parent_section_index = (first_node.index if first_node.depth == 1 else first_node.parent_index)
|
parent_section_index = (first_node.index if first_node.depth == 1 else first_node.parent_index)
|
||||||
else:
|
else:
|
||||||
parent_section_index = max(iterkeys(self.section_map))
|
parent_section_index = max(iter(self.section_map))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Non terminal record
|
# Non terminal record
|
||||||
|
@ -23,7 +23,7 @@ from calibre.ebooks.oeb.polish.jacket import (
|
|||||||
replace_jacket, add_or_replace_jacket, find_existing_jacket, remove_jacket)
|
replace_jacket, add_or_replace_jacket, find_existing_jacket, remove_jacket)
|
||||||
from calibre.ebooks.oeb.polish.css import remove_unused_css
|
from calibre.ebooks.oeb.polish.css import remove_unused_css
|
||||||
from calibre.utils.logging import Log
|
from calibre.utils.logging import Log
|
||||||
from polyglot.builtins import iteritems, iterkeys
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
ALL_OPTS = {
|
ALL_OPTS = {
|
||||||
'embed': False,
|
'embed': False,
|
||||||
@ -264,7 +264,7 @@ def gui_polish(data):
|
|||||||
file_map = {x:x for x in files}
|
file_map = {x:x for x in files}
|
||||||
opts = ALL_OPTS.copy()
|
opts = ALL_OPTS.copy()
|
||||||
opts.update(data)
|
opts.update(data)
|
||||||
O = namedtuple('Options', ' '.join(iterkeys(ALL_OPTS)))
|
O = namedtuple('Options', ' '.join(ALL_OPTS))
|
||||||
opts = O(**opts)
|
opts = O(**opts)
|
||||||
log = Log(level=Log.DEBUG)
|
log = Log(level=Log.DEBUG)
|
||||||
report = []
|
report = []
|
||||||
@ -279,7 +279,7 @@ def gui_polish(data):
|
|||||||
def tweak_polish(container, actions, customization=None):
|
def tweak_polish(container, actions, customization=None):
|
||||||
opts = ALL_OPTS.copy()
|
opts = ALL_OPTS.copy()
|
||||||
opts.update(actions)
|
opts.update(actions)
|
||||||
O = namedtuple('Options', ' '.join(iterkeys(ALL_OPTS)))
|
O = namedtuple('Options', ' '.join(ALL_OPTS))
|
||||||
opts = O(**opts)
|
opts = O(**opts)
|
||||||
report = []
|
report = []
|
||||||
changed = polish_one(container, opts, report.append, customization=customization)
|
changed = polish_one(container, opts, report.append, customization=customization)
|
||||||
@ -335,7 +335,7 @@ def main(args=None):
|
|||||||
for k, v in iteritems(popts):
|
for k, v in iteritems(popts):
|
||||||
popts[k] = getattr(opts, k, None)
|
popts[k] = getattr(opts, k, None)
|
||||||
|
|
||||||
O = namedtuple('Options', ' '.join(iterkeys(popts)))
|
O = namedtuple('Options', ' '.join(popts))
|
||||||
popts = O(**popts)
|
popts = O(**popts)
|
||||||
report = []
|
report = []
|
||||||
if not tuple(filter(None, (getattr(popts, name) for name in ALL_OPTS))):
|
if not tuple(filter(None, (getattr(popts, name) for name in ALL_OPTS))):
|
||||||
|
@ -21,7 +21,7 @@ from calibre.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYLES,
|
|||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.utils.filenames import ascii_filename, ascii_text
|
from calibre.utils.filenames import ascii_filename, ascii_text
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, string_or_bytes
|
from polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
||||||
|
|
||||||
COLLAPSE = re.compile(r'[ \t\r\n\v]+')
|
COLLAPSE = re.compile(r'[ \t\r\n\v]+')
|
||||||
STRIPNUM = re.compile(r'[-0-9]+$')
|
STRIPNUM = re.compile(r'[-0-9]+$')
|
||||||
@ -674,7 +674,7 @@ class CSSFlattener(object):
|
|||||||
self.flatten_node(body, stylizer, names, styles, pseudo_styles, fsize, item.id)
|
self.flatten_node(body, stylizer, names, styles, pseudo_styles, fsize, item.id)
|
||||||
items = sorted(((key, val) for (val, key) in iteritems(styles)), key=lambda x:numeric_sort_key(x[0]))
|
items = sorted(((key, val) for (val, key) in iteritems(styles)), key=lambda x:numeric_sort_key(x[0]))
|
||||||
# :hover must come after link and :active must come after :hover
|
# :hover must come after link and :active must come after :hover
|
||||||
psels = sorted(iterkeys(pseudo_styles), key=lambda x :
|
psels = sorted(pseudo_styles, key=lambda x :
|
||||||
{'hover':1, 'active':2}.get(x, 0))
|
{'hover':1, 'active':2}.get(x, 0))
|
||||||
for psel in psels:
|
for psel in psels:
|
||||||
styles = pseudo_styles[psel]
|
styles = pseudo_styles[psel]
|
||||||
|
@ -14,7 +14,7 @@ from binascii import hexlify
|
|||||||
|
|
||||||
from calibre.constants import plugins, ispy3
|
from calibre.constants import plugins, ispy3
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type
|
from polyglot.builtins import iteritems, unicode_type
|
||||||
|
|
||||||
pdf_float = plugins['speedup'][0].pdf_float
|
pdf_float = plugins['speedup'][0].pdf_float
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ class Dictionary(dict):
|
|||||||
|
|
||||||
def pdf_serialize(self, stream):
|
def pdf_serialize(self, stream):
|
||||||
stream.write(b'<<' + EOL)
|
stream.write(b'<<' + EOL)
|
||||||
sorted_keys = sorted(iterkeys(self),
|
sorted_keys = sorted(self,
|
||||||
key=lambda x:({'Type':'1', 'Subtype':'2'}.get(
|
key=lambda x:({'Type':'1', 'Subtype':'2'}.get(
|
||||||
x, x)+x))
|
x, x)+x))
|
||||||
for k in sorted_keys:
|
for k in sorted_keys:
|
||||||
|
@ -11,7 +11,7 @@ import re
|
|||||||
from itertools import 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 iteritems, iterkeys, map, zip
|
from polyglot.builtins import iteritems, 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,
|
||||||
@ -204,7 +204,7 @@ class Font(object):
|
|||||||
widths = {g:w for g, w in iteritems(widths) if w != most_common}
|
widths = {g:w for g, w in iteritems(widths) if w != most_common}
|
||||||
|
|
||||||
groups = Array()
|
groups = Array()
|
||||||
for k, g in groupby(enumerate(iterkeys(widths)), lambda i_x:i_x[0]-i_x[1]):
|
for k, g in groupby(enumerate(widths), lambda i_x:i_x[0]-i_x[1]):
|
||||||
group = list(map(itemgetter(1), g))
|
group = list(map(itemgetter(1), g))
|
||||||
gwidths = [widths[g] for g in group]
|
gwidths = [widths[g] for g in group]
|
||||||
if len(set(gwidths)) == 1 and len(group) > 1:
|
if len(set(gwidths)) == 1 and len(group) > 1:
|
||||||
|
@ -20,7 +20,7 @@ from calibre.utils.icu import sort_key
|
|||||||
from calibre.gui2 import (gprefs, warning_dialog, Dispatcher, error_dialog,
|
from calibre.gui2 import (gprefs, warning_dialog, Dispatcher, error_dialog,
|
||||||
question_dialog, info_dialog, open_local_file, choose_dir)
|
question_dialog, info_dialog, open_local_file, choose_dir)
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
from polyglot.builtins import iterkeys, unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
def db_class():
|
def db_class():
|
||||||
@ -40,7 +40,7 @@ class LibraryUsageStats(object): # {{{
|
|||||||
# Rename the current library. Renaming of other libraries is
|
# Rename the current library. Renaming of other libraries is
|
||||||
# handled by the switch function
|
# handled by the switch function
|
||||||
q = os.path.basename(lp)
|
q = os.path.basename(lp)
|
||||||
for loc in list(iterkeys(self.stats)):
|
for loc in list(self.stats):
|
||||||
bn = posixpath.basename(loc)
|
bn = posixpath.basename(loc)
|
||||||
if bn.lower() == q.lower():
|
if bn.lower() == q.lower():
|
||||||
self.rename(loc, lp)
|
self.rename(loc, lp)
|
||||||
|
@ -17,7 +17,7 @@ from lxml import etree
|
|||||||
|
|
||||||
from calibre.gui2 import choose_files, error_dialog
|
from calibre.gui2 import choose_files, error_dialog
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from polyglot.builtins import iterkeys, unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
Group = namedtuple('Group', 'title feeds')
|
Group = namedtuple('Group', 'title feeds')
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ def import_opml(raw, preserve_groups=True):
|
|||||||
break
|
break
|
||||||
groups[parent].append((title, url))
|
groups[parent].append((title, url))
|
||||||
|
|
||||||
for title in sorted(iterkeys(groups), key=sort_key):
|
for title in sorted(groups, key=sort_key):
|
||||||
yield Group(title, uniq(groups[title], kmap=itemgetter(1)))
|
yield Group(title, uniq(groups[title], kmap=itemgetter(1)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
|||||||
from calibre.utils.filenames import atomic_rename
|
from calibre.utils.filenames import atomic_rename
|
||||||
from lzma.xz import compress, decompress
|
from lzma.xz import compress, decompress
|
||||||
from polyglot.queue import Queue, Empty
|
from polyglot.queue import Queue, Empty
|
||||||
from polyglot.builtins import iteritems, iterkeys, map, range, reraise
|
from polyglot.builtins import iteritems, map, range, reraise
|
||||||
|
|
||||||
IMAGE_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
IMAGE_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
||||||
THEME_COVER = 'icon-theme-cover.jpg'
|
THEME_COVER = 'icon-theme-cover.jpg'
|
||||||
@ -362,7 +362,7 @@ def create_themeball(report, progress=None, abort=None):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return sys.exc_info()
|
return sys.exc_info()
|
||||||
|
|
||||||
errors = tuple(filter(None, pool.map(optimize, tuple(iterkeys(report.name_map)))))
|
errors = tuple(filter(None, pool.map(optimize, tuple(report.name_map))))
|
||||||
pool.close(), pool.join()
|
pool.close(), pool.join()
|
||||||
if abort is not None and abort.is_set():
|
if abort is not None and abort.is_set():
|
||||||
return
|
return
|
||||||
|
@ -12,7 +12,7 @@ from collections import OrderedDict
|
|||||||
from PyQt5.Qt import QImage, QPixmap
|
from PyQt5.Qt import QImage, QPixmap
|
||||||
|
|
||||||
from calibre.db.utils import ThumbnailCache as TC
|
from calibre.db.utils import ThumbnailCache as TC
|
||||||
from polyglot.builtins import interkeys, itervalues
|
from polyglot.builtins import itervalues
|
||||||
|
|
||||||
|
|
||||||
class ThumbnailCache(TC):
|
class ThumbnailCache(TC):
|
||||||
@ -68,7 +68,7 @@ class CoverCache(dict):
|
|||||||
self._pop(key) # pop() so that item is moved to the top
|
self._pop(key) # pop() so that item is moved to the top
|
||||||
self.items[key] = val
|
self.items[key] = val
|
||||||
if len(self.items) > self.limit:
|
if len(self.items) > self.limit:
|
||||||
del self.items[next(iterkeys(self.items))]
|
del self.items[next(iter(self.items))]
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
@ -85,6 +85,6 @@ class CoverCache(dict):
|
|||||||
self.limit = limit
|
self.limit = limit
|
||||||
if len(self.items) > self.limit:
|
if len(self.items) > self.limit:
|
||||||
extra = len(self.items) - self.limit
|
extra = len(self.items) - self.limit
|
||||||
remove = tuple(iterkeys(self))[:extra]
|
remove = tuple(self)[:extra]
|
||||||
for k in remove:
|
for k in remove:
|
||||||
self._pop(k)
|
self._pop(k)
|
||||||
|
@ -18,7 +18,7 @@ from calibre.ebooks import BOOK_EXTENSIONS
|
|||||||
from calibre.ebooks.oeb.iterator import is_supported
|
from calibre.ebooks.oeb.iterator import is_supported
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from polyglot.builtins import iterkeys, unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
|
|
||||||
class OutputFormatSetting(Setting):
|
class OutputFormatSetting(Setting):
|
||||||
@ -50,7 +50,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
choices = [(x.upper(), x) for x in output_formats]
|
choices = [(x.upper(), x) for x in output_formats]
|
||||||
r('output_format', prefs, choices=choices, setting=OutputFormatSetting)
|
r('output_format', prefs, choices=choices, setting=OutputFormatSetting)
|
||||||
|
|
||||||
restrictions = sorted(iterkeys(db.prefs['virtual_libraries']), key=sort_key)
|
restrictions = sorted(db.prefs['virtual_libraries'], key=sort_key)
|
||||||
choices = [('', '')] + [(x, x) for x in restrictions]
|
choices = [('', '')] + [(x, x) for x in restrictions]
|
||||||
# check that the virtual library still exists
|
# check that the virtual library still exists
|
||||||
vls = db.prefs['virtual_lib_on_startup']
|
vls = db.prefs['virtual_lib_on_startup']
|
||||||
|
@ -19,7 +19,7 @@ from calibre import isbytestring
|
|||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
from calibre.utils.search_query_parser import (ParseException,
|
from calibre.utils.search_query_parser import (ParseException,
|
||||||
SearchQueryParser)
|
SearchQueryParser)
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QAbstractListModel, Qt, QStyledItemDelegate, QStyle, QStyleOptionViewItem,
|
QAbstractListModel, Qt, QStyledItemDelegate, QStyle, QStyleOptionViewItem,
|
||||||
@ -188,8 +188,8 @@ class Tweaks(QAbstractListModel, AdaptSQP): # {{{
|
|||||||
pos += 1
|
pos += 1
|
||||||
|
|
||||||
self.tweaks.sort()
|
self.tweaks.sort()
|
||||||
default_keys = set(iterkeys(dl))
|
default_keys = set(dl)
|
||||||
custom_keys = set(iterkeys(l))
|
custom_keys = set(l)
|
||||||
|
|
||||||
self.plugin_tweaks = {}
|
self.plugin_tweaks = {}
|
||||||
for key in custom_keys - default_keys:
|
for key in custom_keys - default_keys:
|
||||||
|
@ -18,7 +18,7 @@ from calibre.gui2 import error_dialog
|
|||||||
from calibre.gui2.tweak_book import tprefs
|
from calibre.gui2.tweak_book import tprefs
|
||||||
from calibre.gui2.tweak_book.editor import syntax_text_char_format
|
from calibre.gui2.tweak_book.editor import syntax_text_char_format
|
||||||
from calibre.gui2.tweak_book.widgets import Dialog
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range
|
||||||
|
|
||||||
underline_styles = {'single', 'dash', 'dot', 'dash_dot', 'dash_dot_dot', 'wave', 'spell'}
|
underline_styles = {'single', 'dash', 'dot', 'dash_dot', 'dash_dot_dot', 'wave', 'spell'}
|
||||||
|
|
||||||
@ -310,11 +310,11 @@ def theme_format(theme, name):
|
|||||||
|
|
||||||
|
|
||||||
def custom_theme_names():
|
def custom_theme_names():
|
||||||
return tuple(iterkeys(tprefs['custom_themes']))
|
return tuple(tprefs['custom_themes'])
|
||||||
|
|
||||||
|
|
||||||
def builtin_theme_names():
|
def builtin_theme_names():
|
||||||
return tuple(iterkeys(THEMES))
|
return tuple(THEMES)
|
||||||
|
|
||||||
|
|
||||||
def all_theme_names():
|
def all_theme_names():
|
||||||
@ -612,8 +612,8 @@ class ThemeEditor(Dialog):
|
|||||||
|
|
||||||
def update_theme(self, name):
|
def update_theme(self, name):
|
||||||
data = tprefs['custom_themes'][name]
|
data = tprefs['custom_themes'][name]
|
||||||
extra = set(iterkeys(data)) - set(iterkeys(THEMES[default_theme()]))
|
extra = set(data) - set(THEMES[default_theme()])
|
||||||
missing = set(iterkeys(THEMES[default_theme()])) - set(iterkeys(data))
|
missing = set(THEMES[default_theme()]) - set(data)
|
||||||
for k in extra:
|
for k in extra:
|
||||||
data.pop(k)
|
data.pop(k)
|
||||||
for k in missing:
|
for k in missing:
|
||||||
|
@ -22,7 +22,7 @@ from calibre.gui2.tweak_book.widgets import Dialog, BusyCursor
|
|||||||
from calibre.utils.icu import primary_sort_key as sort_key
|
from calibre.utils.icu import primary_sort_key as sort_key
|
||||||
from calibre.utils.fonts.scanner import font_scanner, NoFonts
|
from calibre.utils.fonts.scanner import font_scanner, NoFonts
|
||||||
from calibre.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
from calibre.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type
|
from polyglot.builtins import iteritems, unicode_type
|
||||||
|
|
||||||
|
|
||||||
def show_font_face_rule_for_font_file(file_data, added_name, parent=None):
|
def show_font_face_rule_for_font_file(file_data, added_name, parent=None):
|
||||||
@ -103,7 +103,7 @@ class AllFonts(QAbstractTableModel):
|
|||||||
|
|
||||||
def do_sort(self):
|
def do_sort(self):
|
||||||
reverse = not self.sorted_on[1]
|
reverse = not self.sorted_on[1]
|
||||||
self.items = sorted(iterkeys(self.font_data), key=sort_key, reverse=reverse)
|
self.items = sorted(self.font_data, key=sort_key, reverse=reverse)
|
||||||
if self.sorted_on[0] != 'name':
|
if self.sorted_on[0] != 'name':
|
||||||
self.items.sort(key=self.font_data.get, reverse=reverse)
|
self.items.sort(key=self.font_data.get, reverse=reverse)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import numbers
|
|||||||
from operator import attrgetter, methodcaller
|
from operator import attrgetter, methodcaller
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from polyglot.builtins import (
|
from polyglot.builtins import (
|
||||||
iteritems, iterkeys, itervalues, map, unicode_type, range)
|
iteritems, itervalues, map, unicode_type, range)
|
||||||
from itertools import product
|
from itertools import product
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
|
|
||||||
@ -594,7 +594,7 @@ class TemplatesDialog(Dialog): # {{{
|
|||||||
self.l = l = QVBoxLayout(self)
|
self.l = l = QVBoxLayout(self)
|
||||||
|
|
||||||
self.syntaxes = s = QComboBox(self)
|
self.syntaxes = s = QComboBox(self)
|
||||||
s.addItems(sorted(iterkeys(DEFAULT_TEMPLATES)))
|
s.addItems(sorted(DEFAULT_TEMPLATES))
|
||||||
s.setCurrentIndex(s.findText('html'))
|
s.setCurrentIndex(s.findText('html'))
|
||||||
h = QHBoxLayout()
|
h = QHBoxLayout()
|
||||||
l.addLayout(h)
|
l.addLayout(h)
|
||||||
|
@ -34,7 +34,7 @@ from calibre.gui2.tweak_book.widgets import BusyCursor
|
|||||||
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
||||||
from calibre.utils.icu import primary_contains
|
from calibre.utils.icu import primary_contains
|
||||||
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, range
|
from polyglot.builtins import iteritems, unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
# The search panel {{{
|
# The search panel {{{
|
||||||
@ -1220,7 +1220,7 @@ class SavedSearches(QWidget):
|
|||||||
return err()
|
return err()
|
||||||
searches = []
|
searches = []
|
||||||
for item in obj['searches']:
|
for item in obj['searches']:
|
||||||
if not isinstance(item, dict) or not set(iterkeys(item)).issuperset(needed_keys):
|
if not isinstance(item, dict) or not set(item).issuperset(needed_keys):
|
||||||
return err
|
return err
|
||||||
searches.append({k:item[k] for k in needed_keys})
|
searches.append({k:item[k] for k in needed_keys})
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ from calibre.gui2 import min_available_height, error_dialog
|
|||||||
from calibre.gui2.languages import LanguagesEdit
|
from calibre.gui2.languages import LanguagesEdit
|
||||||
from calibre.gui2.shortcuts import ShortcutConfig
|
from calibre.gui2.shortcuts import ShortcutConfig
|
||||||
from calibre.gui2.viewer.config_ui import Ui_Dialog
|
from calibre.gui2.viewer.config_ui import Ui_Dialog
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type
|
from polyglot.builtins import iteritems, unicode_type
|
||||||
|
|
||||||
|
|
||||||
def config(defaults=None):
|
def config(defaults=None):
|
||||||
@ -213,7 +213,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
for x in ('load', 'delete'):
|
for x in ('load', 'delete'):
|
||||||
m = getattr(self, '%s_theme_button'%x).menu()
|
m = getattr(self, '%s_theme_button'%x).menu()
|
||||||
m.clear()
|
m.clear()
|
||||||
for x in iterkeys(self.themes):
|
for x in self.themes:
|
||||||
title = x[len('theme_'):]
|
title = x[len('theme_'):]
|
||||||
ac = m.addAction(title)
|
ac = m.addAction(title)
|
||||||
ac.theme_id = x
|
ac.theme_id = x
|
||||||
|
@ -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 (iteritems, iterkeys, itervalues, map,
|
from polyglot.builtins import (iteritems, itervalues, map,
|
||||||
unicode_type, string_or_bytes, zip)
|
unicode_type, string_or_bytes, zip)
|
||||||
|
|
||||||
|
|
||||||
@ -918,7 +918,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(zip(iterkeys(id_dict), map(unicode_type,
|
self.marked_ids_dict = dict(zip(iter(id_dict), map(unicode_type,
|
||||||
itervalues(id_dict))))
|
itervalues(id_dict))))
|
||||||
|
|
||||||
# Set the values in the cache
|
# Set the values in the cache
|
||||||
|
@ -47,7 +47,7 @@ from calibre.db.lazy import FormatMetadata, FormatsList
|
|||||||
from calibre.db.categories import Tag, CATEGORY_SORTS
|
from calibre.db.categories import Tag, CATEGORY_SORTS
|
||||||
from calibre.utils.localization import (canonicalize_lang,
|
from calibre.utils.localization import (canonicalize_lang,
|
||||||
calibre_langcode_to_name)
|
calibre_langcode_to_name)
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type, string_or_bytes
|
from polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
||||||
|
|
||||||
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
||||||
SPOOL_SIZE = 30*1024*1024
|
SPOOL_SIZE = 30*1024*1024
|
||||||
@ -1798,7 +1798,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
# First, build the maps. We need a category->items map and an
|
# First, build the maps. We need a category->items map and an
|
||||||
# item -> (item_id, sort_val) map to use in the books loop
|
# item -> (item_id, sort_val) map to use in the books loop
|
||||||
for category in iterkeys(tb_cats):
|
for category in tb_cats:
|
||||||
cat = tb_cats[category]
|
cat = tb_cats[category]
|
||||||
if not cat['is_category'] or cat['kind'] in ['user', 'search'] \
|
if not cat['is_category'] or cat['kind'] in ['user', 'search'] \
|
||||||
or category in ['news', 'formats'] or cat.get('is_csp',
|
or category in ['news', 'formats'] or cat.get('is_csp',
|
||||||
@ -1854,7 +1854,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
md.append((category, cat['rec_index'],
|
md.append((category, cat['rec_index'],
|
||||||
cat['is_multiple'].get('cache_to_list', None), False))
|
cat['is_multiple'].get('cache_to_list', None), False))
|
||||||
|
|
||||||
for category in iterkeys(tb_cats):
|
for category in tb_cats:
|
||||||
cat = tb_cats[category]
|
cat = tb_cats[category]
|
||||||
if cat['datatype'] == 'composite' and \
|
if cat['datatype'] == 'composite' and \
|
||||||
cat['display'].get('make_category', False):
|
cat['display'].get('make_category', False):
|
||||||
@ -1959,7 +1959,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
# and building the Tag instances.
|
# and building the Tag instances.
|
||||||
categories = {}
|
categories = {}
|
||||||
tag_class = Tag
|
tag_class = Tag
|
||||||
for category in iterkeys(tb_cats):
|
for category in tb_cats:
|
||||||
if category not in tcategories:
|
if category not in tcategories:
|
||||||
continue
|
continue
|
||||||
cat = tb_cats[category]
|
cat = tb_cats[category]
|
||||||
@ -2373,7 +2373,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.set_identifiers(id, identifiers, notify=False, commit=False)
|
self.set_identifiers(id, identifiers, notify=False, commit=False)
|
||||||
|
|
||||||
user_mi = mi.get_all_user_metadata(make_copy=False)
|
user_mi = mi.get_all_user_metadata(make_copy=False)
|
||||||
for key in iterkeys(user_mi):
|
for key in user_mi:
|
||||||
if key in self.field_metadata and \
|
if key in self.field_metadata and \
|
||||||
user_mi[key]['datatype'] == self.field_metadata[key]['datatype'] and \
|
user_mi[key]['datatype'] == self.field_metadata[key]['datatype'] and \
|
||||||
(user_mi[key]['datatype'] != 'text' or
|
(user_mi[key]['datatype'] != 'text' or
|
||||||
|
@ -7,7 +7,7 @@ import traceback
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
category_icon_map = {
|
category_icon_map = {
|
||||||
'authors' : 'user_profile.png',
|
'authors' : 'user_profile.png',
|
||||||
@ -509,7 +509,7 @@ class FieldMetadata(object):
|
|||||||
return self.is_custom_field(key) or key.startswith('@')
|
return self.is_custom_field(key) or key.startswith('@')
|
||||||
|
|
||||||
def ignorable_field_keys(self):
|
def ignorable_field_keys(self):
|
||||||
return [k for k in iterkeys(self._tb_cats) if self.is_ignorable_field(k)]
|
return [k for k in self._tb_cats if self.is_ignorable_field(k)]
|
||||||
|
|
||||||
def is_series_index(self, key):
|
def is_series_index(self, key):
|
||||||
try:
|
try:
|
||||||
|
@ -16,8 +16,7 @@ from calibre.library.prefs import DBPrefs
|
|||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
from calibre.utils.date import utcfromtimestamp
|
from calibre.utils.date import utcfromtimestamp
|
||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
from polyglot.builtins import iteritems, iterkeys
|
from polyglot.builtins import iteritems
|
||||||
i
|
|
||||||
|
|
||||||
NON_EBOOK_EXTENSIONS = frozenset([
|
NON_EBOOK_EXTENSIONS = frozenset([
|
||||||
'jpg', 'jpeg', 'gif', 'png', 'bmp',
|
'jpg', 'jpeg', 'gif', 'png', 'bmp',
|
||||||
@ -249,7 +248,7 @@ class Restore(Thread):
|
|||||||
self.failed_restores.append((book, traceback.format_exc()))
|
self.failed_restores.append((book, traceback.format_exc()))
|
||||||
self.progress_callback(book['mi'].title, i+1)
|
self.progress_callback(book['mi'].title, i+1)
|
||||||
|
|
||||||
for author in iterkeys(self.authors_links):
|
for author in self.authors_links:
|
||||||
link, ign = self.authors_links[author]
|
link, ign = self.authors_links[author]
|
||||||
db.conn.execute('UPDATE authors SET link=? WHERE name=?',
|
db.conn.execute('UPDATE authors SET link=? WHERE name=?',
|
||||||
(link, author.replace(',', '|')))
|
(link, author.replace(',', '|')))
|
||||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from calibre.utils.date import isoformat, DEFAULT_DATE
|
from calibre.utils.date import isoformat, DEFAULT_DATE
|
||||||
from polyglot.builtins import iterkeys, itervalues, unicode_type
|
from polyglot.builtins import itervalues, unicode_type
|
||||||
|
|
||||||
|
|
||||||
class SchemaUpgrade(object):
|
class SchemaUpgrade(object):
|
||||||
@ -590,7 +590,7 @@ class SchemaUpgrade(object):
|
|||||||
custom_recipe_filename
|
custom_recipe_filename
|
||||||
bdir = os.path.dirname(custom_recipes.file_path)
|
bdir = os.path.dirname(custom_recipes.file_path)
|
||||||
for id_, title, script in recipes:
|
for id_, title, script in recipes:
|
||||||
existing = frozenset(map(int, iterkeys(custom_recipes)))
|
existing = frozenset(map(int, custom_recipes))
|
||||||
if id_ in existing:
|
if id_ in existing:
|
||||||
id_ = max(existing) + 1000
|
id_ = max(existing) + 1000
|
||||||
id_ = str(id_)
|
id_ = str(id_)
|
||||||
|
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues, unicode_type, zip, string_or_bytes
|
from polyglot.builtins import iteritems, itervalues, unicode_type, zip, string_or_bytes
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
@ -83,7 +83,7 @@ def book_to_json(ctx, rd, db, book_id,
|
|||||||
if mtime is not None:
|
if mtime is not None:
|
||||||
v['mtime'] = isoformat(mtime, as_utc=True)
|
v['mtime'] = isoformat(mtime, as_utc=True)
|
||||||
data['format_metadata'] = mi.format_metadata
|
data['format_metadata'] = mi.format_metadata
|
||||||
fmts = set(x.lower() for x in iterkeys(mi.format_metadata))
|
fmts = set(x.lower() for x in mi.format_metadata)
|
||||||
pf = prefs['output_format'].lower()
|
pf = prefs['output_format'].lower()
|
||||||
other_fmts = list(fmts)
|
other_fmts = list(fmts)
|
||||||
try:
|
try:
|
||||||
|
@ -17,7 +17,7 @@ from calibre.srv.standalone import create_option_parser
|
|||||||
from calibre.srv.utils import create_sock_pair
|
from calibre.srv.utils import create_sock_pair
|
||||||
from calibre.srv.web_socket import DummyHandler
|
from calibre.srv.web_socket import DummyHandler
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import iterkeys, itervalues
|
from polyglot.builtins import itervalues
|
||||||
from polyglot.queue import Queue, Empty
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
MAX_RETRIES = 10
|
MAX_RETRIES = 10
|
||||||
@ -76,7 +76,7 @@ if islinux:
|
|||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
while True:
|
while True:
|
||||||
r = select.select([self.srv_sock] + list(iterkeys(self.fd_map)), [], [])[0]
|
r = select.select([self.srv_sock] + list(self.fd_map), [], [])[0]
|
||||||
modified = set()
|
modified = set()
|
||||||
for fd in r:
|
for fd in r:
|
||||||
if fd is self.srv_sock:
|
if fd is self.srv_sock:
|
||||||
|
@ -15,7 +15,7 @@ from calibre.srv.routes import Router
|
|||||||
from calibre.srv.users import UserManager
|
from calibre.srv.users import UserManager
|
||||||
from calibre.utils.date import utcnow
|
from calibre.utils.date import utcnow
|
||||||
from calibre.utils.search_query_parser import ParseException
|
from calibre.utils.search_query_parser import ParseException
|
||||||
from polyglot.builtins import iterkeys, itervalues
|
from polyglot.builtins import itervalues
|
||||||
|
|
||||||
|
|
||||||
class Context(object):
|
class Context(object):
|
||||||
@ -67,7 +67,7 @@ class Context(object):
|
|||||||
allowed_libraries = self.library_broker.allowed_libraries(lf)
|
allowed_libraries = self.library_broker.allowed_libraries(lf)
|
||||||
if not allowed_libraries:
|
if not allowed_libraries:
|
||||||
raise HTTPForbidden('The user {} is not allowed to access any libraries on this server'.format(request_data.username))
|
raise HTTPForbidden('The user {} is not allowed to access any libraries on this server'.format(request_data.username))
|
||||||
library_id = library_id or next(iterkeys(allowed_libraries))
|
library_id = library_id or next(iter(allowed_libraries))
|
||||||
if library_id in allowed_libraries:
|
if library_id in allowed_libraries:
|
||||||
return self.library_broker.get(library_id)
|
return self.library_broker.get(library_id)
|
||||||
raise HTTPForbidden('The user {} is not allowed to access the library {}'.format(request_data.username, library_id))
|
raise HTTPForbidden('The user {} is not allowed to access the library {}'.format(request_data.username, library_id))
|
||||||
@ -79,7 +79,7 @@ class Context(object):
|
|||||||
allowed_libraries = self.library_broker.allowed_libraries(lf)
|
allowed_libraries = self.library_broker.allowed_libraries(lf)
|
||||||
if not allowed_libraries:
|
if not allowed_libraries:
|
||||||
raise HTTPForbidden('The user {} is not allowed to access any libraries on this server'.format(request_data.username))
|
raise HTTPForbidden('The user {} is not allowed to access any libraries on this server'.format(request_data.username))
|
||||||
return dict(allowed_libraries), next(iterkeys(allowed_libraries))
|
return dict(allowed_libraries), next(iter(allowed_libraries))
|
||||||
|
|
||||||
def restriction_for(self, request_data, db):
|
def restriction_for(self, request_data, db):
|
||||||
return self.user_manager.library_restriction(request_data.username, path_for_db(db))
|
return self.user_manager.library_restriction(request_data.username, path_for_db(db))
|
||||||
|
@ -13,7 +13,7 @@ from calibre.db.cache import Cache
|
|||||||
from calibre.db.legacy import LibraryDatabase, create_backend, set_global_state
|
from calibre.db.legacy import LibraryDatabase, create_backend, set_global_state
|
||||||
from calibre.utils.filenames import samefile as _samefile
|
from calibre.utils.filenames import samefile as _samefile
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import iteritems, iterkeys, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
|
|
||||||
def canonicalize_path(p):
|
def canonicalize_path(p):
|
||||||
@ -121,7 +121,7 @@ class LibraryBroker(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def default_library(self):
|
def default_library(self):
|
||||||
return next(iterkeys(self.lmap))
|
return next(iter(self.lmap))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def library_map(self):
|
def library_map(self):
|
||||||
|
@ -27,7 +27,7 @@ from calibre.ebooks.oeb.polish.toc import get_toc, get_landmarks
|
|||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
from calibre.utils.short_uuid import uuid4
|
from calibre.utils.short_uuid import uuid4
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
from polyglot.builtins import iteritems, iterkeys, map, unicode_type
|
from polyglot.builtins import iteritems, map, unicode_type
|
||||||
from polyglot.urllib import quote, urlparse
|
from polyglot.urllib import quote, urlparse
|
||||||
|
|
||||||
RENDER_VERSION = 1
|
RENDER_VERSION = 1
|
||||||
@ -416,7 +416,7 @@ def map_epub_type(epub_type, attribs, elem):
|
|||||||
roles = OrderedDict([(k, True) for k in role.split()]) if role else OrderedDict()
|
roles = OrderedDict([(k, True) for k in role.split()]) if role else OrderedDict()
|
||||||
if val not in roles:
|
if val not in roles:
|
||||||
roles[val] = True
|
roles[val] = True
|
||||||
role = ' '.join(iterkeys(roles))
|
role = ' '.join(roles)
|
||||||
if in_attribs is None:
|
if in_attribs is None:
|
||||||
attribs.append(['role', role])
|
attribs.append(['role', role])
|
||||||
else:
|
else:
|
||||||
|
@ -13,7 +13,6 @@ from httplib import OK, NOT_FOUND, FORBIDDEN
|
|||||||
|
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
from calibre.srv.tests.base import LibraryBaseTest
|
from calibre.srv.tests.base import LibraryBaseTest
|
||||||
from polyglot.builtins import iterkeys
|
|
||||||
from polyglot.urllib import urlencode, quote
|
from polyglot.urllib import urlencode, quote
|
||||||
|
|
||||||
|
|
||||||
@ -46,12 +45,12 @@ class ContentTest(LibraryBaseTest):
|
|||||||
self.ae(request('/%s?id_is_uuid=true' % db.field_for('uuid', 1))[1], onedata)
|
self.ae(request('/%s?id_is_uuid=true' % db.field_for('uuid', 1))[1], onedata)
|
||||||
|
|
||||||
r, data = request('s')
|
r, data = request('s')
|
||||||
self.ae(set(iterkeys(data)), set(map(str, db.all_book_ids())))
|
self.ae(set(data), set(map(str, db.all_book_ids())))
|
||||||
r, zdata = request('s', headers={'Accept-Encoding':'gzip'})
|
r, zdata = request('s', headers={'Accept-Encoding':'gzip'})
|
||||||
self.ae(r.getheader('Content-Encoding'), 'gzip')
|
self.ae(r.getheader('Content-Encoding'), 'gzip')
|
||||||
self.ae(json.loads(zlib.decompress(zdata, 16+zlib.MAX_WBITS)), data)
|
self.ae(json.loads(zlib.decompress(zdata, 16+zlib.MAX_WBITS)), data)
|
||||||
r, data = request('s?ids=1,2')
|
r, data = request('s?ids=1,2')
|
||||||
self.ae(set(iterkeys(data)), {'1', '2'})
|
self.ae(set(data), {'1', '2'})
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from calibre import strftime
|
|||||||
from calibre.constants import iswindows, isosx, plugins, preferred_encoding
|
from calibre.constants import iswindows, isosx, plugins, preferred_encoding
|
||||||
from calibre.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
from calibre.utils.iso8601 import utc_tz, local_tz, UNDEFINED_DATE
|
||||||
from calibre.utils.localization import lcdata
|
from calibre.utils.localization import lcdata
|
||||||
from polyglot.builtins import iterkeys, unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
_utc_tz = utc_tz
|
_utc_tz = utc_tz
|
||||||
_local_tz = local_tz
|
_local_tz = local_tz
|
||||||
@ -478,7 +478,7 @@ def replace_months(datestr, clang):
|
|||||||
else:
|
else:
|
||||||
return datestr
|
return datestr
|
||||||
|
|
||||||
for k in iterkeys(dictoen):
|
for k in dictoen:
|
||||||
tmp = re.sub(k, dictoen[k], datestr)
|
tmp = re.sub(k, dictoen[k], datestr)
|
||||||
if tmp != datestr:
|
if tmp != datestr:
|
||||||
break
|
break
|
||||||
|
@ -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 iteritems, iterkeys, itervalues, unicode_type, range
|
from polyglot.builtins import iteritems, itervalues, unicode_type, range
|
||||||
|
|
||||||
|
|
||||||
def ascii_text(orig):
|
def ascii_text(orig):
|
||||||
@ -467,7 +467,7 @@ class WindowsAtomicFolderMove(object):
|
|||||||
|
|
||||||
def delete_originals(self):
|
def delete_originals(self):
|
||||||
import win32file
|
import win32file
|
||||||
for path in iterkeys(self.handle_map):
|
for path in self.handle_map:
|
||||||
win32file.DeleteFile(path)
|
win32file.DeleteFile(path)
|
||||||
self.close_handles()
|
self.close_handles()
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from collections import OrderedDict
|
|||||||
from calibre.utils.fonts.utils import read_bmp_prefix
|
from calibre.utils.fonts.utils import read_bmp_prefix
|
||||||
from calibre.utils.fonts.sfnt import UnknownTable, max_power_of_two
|
from calibre.utils.fonts.sfnt import UnknownTable, max_power_of_two
|
||||||
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
from calibre.utils.fonts.sfnt.errors import UnsupportedFont
|
||||||
from polyglot.builtins import iterkeys, range
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
def split_range(start_code, end_code, cmap): # {{{
|
def split_range(start_code, end_code, cmap): # {{{
|
||||||
@ -229,7 +229,7 @@ class CmapTable(UnknownTable):
|
|||||||
def set_character_map(self, cmap):
|
def set_character_map(self, cmap):
|
||||||
self.version, self.num_tables = 0, 1
|
self.version, self.num_tables = 0, 1
|
||||||
fmt = b'>7H'
|
fmt = b'>7H'
|
||||||
codes = sorted(iterkeys(cmap))
|
codes = sorted(cmap)
|
||||||
|
|
||||||
if not codes:
|
if not codes:
|
||||||
start_code = [0xffff]
|
start_code = [0xffff]
|
||||||
|
@ -25,7 +25,6 @@ from calibre.utils.fonts.sfnt.cmap import CmapTable
|
|||||||
from calibre.utils.fonts.sfnt.kern import KernTable
|
from calibre.utils.fonts.sfnt.kern import KernTable
|
||||||
from calibre.utils.fonts.sfnt.gsub import GSUBTable
|
from calibre.utils.fonts.sfnt.gsub import GSUBTable
|
||||||
from calibre.utils.fonts.sfnt.cff.table import CFFTable
|
from calibre.utils.fonts.sfnt.cff.table import CFFTable
|
||||||
from polyglot.builtins import iterkeys
|
|
||||||
|
|
||||||
# OpenType spec: http://www.microsoft.com/typography/otspec/otff.htm
|
# OpenType spec: http://www.microsoft.com/typography/otspec/otff.htm
|
||||||
|
|
||||||
@ -84,13 +83,13 @@ class Sfnt(object):
|
|||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
'''Iterate over the table tags in order.'''
|
'''Iterate over the table tags in order.'''
|
||||||
for x in sorted(iterkeys(self.tables)):
|
for x in sorted(self.tables):
|
||||||
yield x
|
yield x
|
||||||
# Although the optimal order is not alphabetical, the OTF spec says
|
# Although the optimal order is not alphabetical, the OTF spec says
|
||||||
# they should be alphabetical, so we stick with that. See
|
# they should be alphabetical, so we stick with that. See
|
||||||
# http://partners.adobe.com/public/developer/opentype/index_recs.html
|
# http://partners.adobe.com/public/developer/opentype/index_recs.html
|
||||||
# for optimal order.
|
# for optimal order.
|
||||||
# keys = list(self.tables.iterkeys())
|
# keys = list(self.tables)
|
||||||
# order = {x:i for i, x in enumerate((b'head', b'hhea', b'maxp', b'OS/2',
|
# order = {x:i for i, x in enumerate((b'head', b'hhea', b'maxp', b'OS/2',
|
||||||
# b'hmtx', b'LTSH', b'VDMX', b'hdmx', b'cmap', b'fpgm', b'prep',
|
# b'hmtx', b'LTSH', b'VDMX', b'hdmx', b'cmap', b'fpgm', b'prep',
|
||||||
# b'cvt ', b'loca', b'glyf', b'CFF ', b'kern', b'name', b'post',
|
# b'cvt ', b'loca', b'glyf', b'CFF ', b'kern', b'name', b'post',
|
||||||
|
@ -217,7 +217,7 @@ def print_stats(old_stats, new_stats):
|
|||||||
prints('='*80)
|
prints('='*80)
|
||||||
old_total = sum(old_stats.itervalues())
|
old_total = sum(old_stats.itervalues())
|
||||||
new_total = sum(new_stats.itervalues())
|
new_total = sum(new_stats.itervalues())
|
||||||
tables = sorted(old_stats.iterkeys(), key=lambda x:old_stats[x],
|
tables = sorted(old_stats, key=lambda x:old_stats[x],
|
||||||
reverse=True)
|
reverse=True)
|
||||||
for table in tables:
|
for table in tables:
|
||||||
osz = old_stats[table]
|
osz = old_stats[table]
|
||||||
|
@ -18,7 +18,7 @@ from calibre.constants import numeric_version
|
|||||||
from calibre.utils.iso8601 import parse_iso8601
|
from calibre.utils.iso8601 import parse_iso8601
|
||||||
from calibre.utils.date import now as nowf, utcnow, local_tz, isoformat, EPOCH, UNDEFINED_DATE
|
from calibre.utils.date import now as nowf, utcnow, local_tz, isoformat, EPOCH, UNDEFINED_DATE
|
||||||
from calibre.utils.recycle_bin import delete_file
|
from calibre.utils.recycle_bin import delete_file
|
||||||
from polyglot.builtins import iteritems, iterkeys, unicode_type
|
from polyglot.builtins import iteritems, unicode_type
|
||||||
|
|
||||||
NS = 'http://calibre-ebook.com/recipe_collection'
|
NS = 'http://calibre-ebook.com/recipe_collection'
|
||||||
E = ElementMaker(namespace=NS, nsmap={None:NS})
|
E = ElementMaker(namespace=NS, nsmap={None:NS})
|
||||||
@ -164,7 +164,7 @@ def add_custom_recipes(script_map):
|
|||||||
from calibre.web.feeds.recipes import custom_recipes, \
|
from calibre.web.feeds.recipes import custom_recipes, \
|
||||||
custom_recipe_filename
|
custom_recipe_filename
|
||||||
id_ = 1000
|
id_ = 1000
|
||||||
keys = tuple(map(int, iterkeys(custom_recipes)))
|
keys = tuple(map(int, custom_recipes))
|
||||||
if keys:
|
if keys:
|
||||||
id_ = max(keys)+1
|
id_ = max(keys)+1
|
||||||
bdir = os.path.dirname(custom_recipes.file_path)
|
bdir = os.path.dirname(custom_recipes.file_path)
|
||||||
|
@ -8,6 +8,11 @@ import sys
|
|||||||
|
|
||||||
is_py3 = sys.version_info.major >= 3
|
is_py3 = sys.version_info.major >= 3
|
||||||
|
|
||||||
|
|
||||||
|
def iterkeys(d):
|
||||||
|
return iter(d)
|
||||||
|
|
||||||
|
|
||||||
if is_py3:
|
if is_py3:
|
||||||
def reraise(tp, value, tb=None):
|
def reraise(tp, value, tb=None):
|
||||||
try:
|
try:
|
||||||
@ -38,9 +43,6 @@ if is_py3:
|
|||||||
def itervalues(d):
|
def itervalues(d):
|
||||||
return iter(d.values())
|
return iter(d.values())
|
||||||
|
|
||||||
def iterkeys(d):
|
|
||||||
return iter(d)
|
|
||||||
|
|
||||||
def environ_item(x):
|
def environ_item(x):
|
||||||
if isinstance(x, bytes):
|
if isinstance(x, bytes):
|
||||||
x = x.decode('utf-8')
|
x = x.decode('utf-8')
|
||||||
@ -65,9 +67,6 @@ else:
|
|||||||
def iteritems(d):
|
def iteritems(d):
|
||||||
return d.iteritems()
|
return d.iteritems()
|
||||||
|
|
||||||
def iterkeys(d):
|
|
||||||
return d.iterkeys()
|
|
||||||
|
|
||||||
def itervalues(d):
|
def itervalues(d):
|
||||||
return d.itervalues()
|
return d.itervalues()
|
||||||
|
|
||||||
|
@ -17,8 +17,6 @@ from tinycss.page3 import CSSPage3Parser
|
|||||||
from tinycss.fonts3 import CSSFonts3Parser
|
from tinycss.fonts3 import CSSFonts3Parser
|
||||||
from tinycss.media3 import CSSMedia3Parser
|
from tinycss.media3 import CSSMedia3Parser
|
||||||
|
|
||||||
from polyglot.builtins import iterkeys
|
|
||||||
|
|
||||||
|
|
||||||
PARSER_MODULES = {
|
PARSER_MODULES = {
|
||||||
'page3': CSSPage3Parser,
|
'page3': CSSPage3Parser,
|
||||||
@ -50,5 +48,5 @@ def make_parser(*features, **kwargs):
|
|||||||
|
|
||||||
def make_full_parser(**kwargs):
|
def make_full_parser(**kwargs):
|
||||||
''' A parser that parses all supported CSS 3 modules in addition to CSS 2.1 '''
|
''' A parser that parses all supported CSS 3 modules in addition to CSS 2.1 '''
|
||||||
features = tuple(iterkeys(PARSER_MODULES))
|
features = tuple(PARSER_MODULES)
|
||||||
return make_parser(*features, **kwargs)
|
return make_parser(*features, **kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user