mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
py3: port filter()
This commit is contained in:
parent
7f4728e29c
commit
34b86d8227
@ -64,7 +64,7 @@ class ElPais(BasicNewsRecipe):
|
||||
def preprocess_html(self, soup):
|
||||
for img in soup.findAll('img', srcset=True):
|
||||
try:
|
||||
img['src'] = filter(None, img['srcset'].split())[0]
|
||||
img['src'] = list(filter(None, img['srcset'].split()))[0]
|
||||
except IndexError:
|
||||
continue
|
||||
return soup
|
||||
|
@ -102,7 +102,7 @@ class HurriyetDailyNews_en(BasicNewsRecipe):
|
||||
regex = re.compile('rmRootLink', re.IGNORECASE)
|
||||
links = soup.findAll('a', {'class': regex})
|
||||
|
||||
filtered_links = filter(include_link, links)
|
||||
filtered_links = list(filter(include_link, links))
|
||||
self._p(' all sections: ' + ', '.join(map(self.text, links)))
|
||||
self._p(' filtered sections: ' +
|
||||
', '.join(map(self.text, filtered_links)))
|
||||
|
@ -5,7 +5,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys, os, re, time, random, warnings
|
||||
from polyglot.builtins import (builtins, codepoint_to_chr, iteritems,
|
||||
itervalues, unicode_type, range)
|
||||
itervalues, unicode_type, range, filter)
|
||||
builtins.__dict__['dynamic_property'] = lambda func: func(None)
|
||||
from math import floor
|
||||
from functools import partial
|
||||
@ -376,9 +376,9 @@ USER_AGENT_MOBILE = 'Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/
|
||||
def random_user_agent(choose=None, allow_ie=True):
|
||||
from calibre.utils.random_ua import common_user_agents
|
||||
ua_list = common_user_agents()
|
||||
ua_list = filter(lambda x: 'Mobile/' not in x, ua_list)
|
||||
ua_list = list(filter(lambda x: 'Mobile/' not in x, ua_list))
|
||||
if not allow_ie:
|
||||
ua_list = filter(lambda x: 'Trident/' not in x and 'Edge/' not in x, ua_list)
|
||||
ua_list = list(filter(lambda x: 'Trident/' not in x and 'Edge/' not in x, ua_list))
|
||||
return random.choice(ua_list) if choose is None else ua_list[choose]
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ import os, traceback, random, shutil, operator
|
||||
from io import BytesIO
|
||||
from collections import defaultdict, Set, MutableSet
|
||||
from functools import wraps, partial
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, zip, string_or_bytes, cmp
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, zip, string_or_bytes, cmp, filter
|
||||
from time import time
|
||||
|
||||
from calibre import isbytestring, as_unicode
|
||||
|
@ -16,7 +16,7 @@ from calibre.db.cache import Cache
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.utils.date import utcfromtimestamp
|
||||
from calibre import isbytestring, force_unicode
|
||||
from polyglot.builtins import iteritems
|
||||
from polyglot.builtins import iteritems, filter
|
||||
|
||||
NON_EBOOK_EXTENSIONS = frozenset([
|
||||
'jpg', 'jpeg', 'gif', 'png', 'bmp',
|
||||
@ -184,7 +184,7 @@ class Restore(Thread):
|
||||
|
||||
def process_dir(self, dirpath, filenames, book_id):
|
||||
book_id = int(book_id)
|
||||
formats = filter(self.is_ebook_file, filenames)
|
||||
formats = list(filter(self.is_ebook_file, filenames))
|
||||
fmts = [os.path.splitext(x)[1][1:].upper() for x in formats]
|
||||
sizes = [os.path.getsize(os.path.join(dirpath, x)) for x in formats]
|
||||
names = [os.path.splitext(x)[0] for x in formats]
|
||||
|
@ -9,7 +9,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
import os, errno, sys, re
|
||||
from locale import localeconv
|
||||
from collections import OrderedDict, namedtuple
|
||||
from polyglot.builtins import iteritems, itervalues, map, unicode_type, string_or_bytes
|
||||
from polyglot.builtins import iteritems, itervalues, map, unicode_type, string_or_bytes, filter
|
||||
from threading import Lock
|
||||
|
||||
from calibre import as_unicode, prints
|
||||
|
@ -15,7 +15,7 @@ from ctypes import (
|
||||
)
|
||||
from ctypes.wintypes import DWORD, WORD, ULONG, LPCWSTR, HWND, BOOL, LPWSTR, UINT, BYTE, HANDLE, USHORT
|
||||
from pprint import pprint, pformat
|
||||
from polyglot.builtins import iteritems, itervalues, map
|
||||
from polyglot.builtins import iteritems, itervalues, map, filter
|
||||
|
||||
from calibre import prints, as_unicode
|
||||
|
||||
@ -677,7 +677,7 @@ def get_volume_pathnames(volume_id, buf=None):
|
||||
continue
|
||||
raise
|
||||
ans = wstring_at(buf, bufsize.value)
|
||||
return buf, filter(None, ans.split('\0'))
|
||||
return buf, list(filter(None, ans.split('\0')))
|
||||
|
||||
# }}}
|
||||
|
||||
@ -979,7 +979,7 @@ def get_device_languages(hub_handle, device_port, buf=None):
|
||||
if dtype != 0x03:
|
||||
raise WindowsError('Invalid datatype for string descriptor: 0x%x' % dtype)
|
||||
data = cast(data.String, POINTER(USHORT*(sz//2)))
|
||||
return buf, filter(None, data.contents)
|
||||
return buf, list(filter(None, data.contents))
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -12,7 +12,7 @@ from calibre.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
from calibre import CurrentDir
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, filter
|
||||
|
||||
block_level_tags = (
|
||||
'address',
|
||||
@ -432,7 +432,7 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
br.tag = XHTML('p')
|
||||
br.text = u'\u00a0'
|
||||
style = br.get('style', '').split(';')
|
||||
style = filter(None, map(lambda x: x.strip(), style))
|
||||
style = list(filter(None, map(lambda x: x.strip(), style)))
|
||||
style.append('margin:0pt; border:0pt')
|
||||
# If the prior tag is a block (including a <br> we replaced)
|
||||
# then this <br> replacement should have a 1-line height.
|
||||
|
@ -5,7 +5,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
import os, glob, re, textwrap
|
||||
|
||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
from polyglot.builtins import iteritems
|
||||
from polyglot.builtins import iteritems, filter
|
||||
|
||||
border_style_map = {
|
||||
'single' : 'solid',
|
||||
|
@ -11,7 +11,7 @@ from operator import itemgetter
|
||||
from lxml import etree
|
||||
|
||||
from calibre.utils.icu import partition_by_first_letter, sort_key
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
|
||||
|
||||
def get_applicable_xe_fields(index, xe_fields, XPath, expand):
|
||||
@ -249,7 +249,7 @@ def polish_index_markup(index, blocks):
|
||||
if a:
|
||||
text = etree.tostring(a[0], method='text', with_tail=False, encoding=unicode_type).strip()
|
||||
if ':' in text:
|
||||
path_map[block] = parts = filter(None, (x.strip() for x in text.split(':')))
|
||||
path_map[block] = parts = list(filter(None, (x.strip() for x in text.split(':'))))
|
||||
if len(parts) > 1:
|
||||
split_up_block(block, a[0], text, parts, ldict)
|
||||
else:
|
||||
|
@ -10,7 +10,7 @@ from lxml.html.builder import TABLE, TR, TD
|
||||
|
||||
from calibre.ebooks.docx.block_styles import inherit, read_shd as rs, read_border, binary_property, border_props, ParagraphStyle, border_to_css
|
||||
from calibre.ebooks.docx.char_styles import RunStyle
|
||||
from polyglot.builtins import iteritems, itervalues, range
|
||||
from polyglot.builtins import iteritems, itervalues, range, filter
|
||||
|
||||
# Read from XML {{{
|
||||
read_shd = rs
|
||||
|
@ -29,7 +29,7 @@ from calibre.ebooks.docx.fields import Fields
|
||||
from calibre.ebooks.docx.settings import Settings
|
||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
from polyglot.builtins import iteritems, itervalues, filter
|
||||
|
||||
|
||||
NBSP = '\xa0'
|
||||
|
@ -15,7 +15,7 @@ from lxml import etree
|
||||
from calibre.ebooks import parse_css_length
|
||||
from calibre.ebooks.docx.writer.utils import convert_color, int_or_zero
|
||||
from calibre.utils.localization import lang_as_iso639_1
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
from tinycss.css21 import CSS21Parser
|
||||
|
||||
css_parser = CSS21Parser()
|
||||
@ -702,7 +702,7 @@ class StylesManager(object):
|
||||
counts[s] += sum(1 for b in blocks if not b.is_empty())
|
||||
for i, heading_tag in enumerate(sorted(heading_styles)):
|
||||
styles = sorted((smap[k] for k in heading_styles[heading_tag]), key=counts.__getitem__)
|
||||
styles = filter(lambda s:s.outline_level is None, styles)
|
||||
styles = list(filter(lambda s:s.outline_level is None, styles))
|
||||
if styles:
|
||||
heading_style = styles[-1]
|
||||
heading_style.outline_level = i
|
||||
|
@ -11,7 +11,7 @@ import time
|
||||
from calibre.constants import __appname__, __version__
|
||||
from calibre import strftime, prepare_string_for_xml as xml
|
||||
from calibre.utils.date import parse_date
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, filter
|
||||
|
||||
SONY_METADATA = u'''\
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
@ -10,6 +10,7 @@ import os
|
||||
from contextlib import closing
|
||||
|
||||
from calibre.customize import FileTypePlugin
|
||||
from polyglot.builtins import filter
|
||||
|
||||
|
||||
def is_comic(list_of_names):
|
||||
|
@ -8,6 +8,7 @@ import re
|
||||
from collections import deque
|
||||
|
||||
from calibre.utils.icu import capitalize, lower, upper
|
||||
from polyglot.builtins import filter
|
||||
|
||||
|
||||
def cap_author_token(token):
|
||||
@ -142,7 +143,7 @@ def map_authors(authors, rules=()):
|
||||
ans = []
|
||||
for a in authors:
|
||||
ans.extend(apply_rules(a, rules))
|
||||
return uniq(filter(None, ans))
|
||||
return uniq(list(filter(None, ans)))
|
||||
|
||||
|
||||
def find_tests():
|
||||
|
@ -14,7 +14,7 @@ from calibre.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
||||
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
||||
from calibre.library.field_metadata import FieldMetadata
|
||||
from calibre.utils.icu import sort_key
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
|
||||
# Special sets used to optimize the performance of getting and setting
|
||||
# attributes on Metadata objects
|
||||
|
@ -20,7 +20,7 @@ from calibre.utils.formatter import EvalFormatter
|
||||
from calibre.utils.date import is_date_undefined
|
||||
from calibre.utils.localization import calibre_langcode_to_name
|
||||
from calibre.utils.serialize import json_dumps
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, filter
|
||||
from polyglot.binary import as_hex_unicode
|
||||
|
||||
default_sort = ('title', 'title_sort', 'authors', 'author_sort', 'series', 'rating', 'pubdate', 'tags', 'publisher', 'identifiers')
|
||||
|
@ -18,7 +18,7 @@ from calibre.utils.config_base import tweaks
|
||||
from calibre.utils.date import parse_only_date
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from calibre.utils.imghdr import identify
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, filter
|
||||
from polyglot.binary import as_base64_bytes, from_base64_bytes
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ import json
|
||||
import re
|
||||
from collections import defaultdict, namedtuple
|
||||
from functools import wraps
|
||||
from polyglot.builtins import iteritems, map
|
||||
from polyglot.builtins import iteritems, map, filter
|
||||
|
||||
from lxml import etree
|
||||
|
||||
@ -411,7 +411,7 @@ def set_languages(root, prefixes, refines, languages):
|
||||
val = (lang.text or '').strip()
|
||||
if val:
|
||||
opf_languages.append(val)
|
||||
languages = filter(lambda x: x and x != 'und', normalize_languages(opf_languages, languages))
|
||||
languages = list(filter(lambda x: x and x != 'und', normalize_languages(opf_languages, languages)))
|
||||
if not languages:
|
||||
# EPUB spec says dc:language is required
|
||||
languages = ['und']
|
||||
@ -688,7 +688,7 @@ def read_tags(root, prefixes, refines):
|
||||
for dc in XPath('./opf:metadata/dc:subject')(root):
|
||||
if dc.text:
|
||||
ans.extend(map(normalize_whitespace, dc.text.split(',')))
|
||||
return uniq(filter(None, ans))
|
||||
return uniq(list(filter(None, ans)))
|
||||
|
||||
|
||||
def set_tags(root, prefixes, refines, val):
|
||||
@ -696,7 +696,7 @@ def set_tags(root, prefixes, refines, val):
|
||||
remove_element(dc, refines)
|
||||
m = XPath('./opf:metadata')(root)[0]
|
||||
if val:
|
||||
val = uniq(filter(None, val))
|
||||
val = uniq(list(filter(None, val)))
|
||||
for x in val:
|
||||
c = m.makeelement(DC('subject'))
|
||||
c.text = normalize_whitespace(x)
|
||||
|
@ -11,7 +11,7 @@ import re
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from polyglot.builtins import codepoint_to_chr, string_or_bytes, unicode_type, int_to_byte
|
||||
from polyglot.builtins import codepoint_to_chr, string_or_bytes, unicode_type, int_to_byte, filter
|
||||
|
||||
title_pat = re.compile(br'\{\\info.*?\{\\title(.*?)(?<!\\)\}', re.DOTALL)
|
||||
author_pat = re.compile(br'\{\\info.*?\{\\author(.*?)(?<!\\)\}', re.DOTALL)
|
||||
|
@ -5,6 +5,7 @@
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
from collections import deque
|
||||
from polyglot.builtins import filter
|
||||
|
||||
|
||||
def compile_pat(pat):
|
||||
@ -88,7 +89,7 @@ def apply_rules(tag, rules):
|
||||
ans.append(icu_upper(tag))
|
||||
break
|
||||
if ac == 'split':
|
||||
stags = filter(None, [x.strip() for x in tag.split(rule['replace'])])
|
||||
stags = list(filter(None, (x.strip() for x in tag.split(rule['replace']))))
|
||||
if stags:
|
||||
if stags[0] == tag:
|
||||
ans.append(tag)
|
||||
@ -121,7 +122,7 @@ def map_tags(tags, rules=()):
|
||||
ans = []
|
||||
for t in tags:
|
||||
ans.extend(apply_rules(t, rules))
|
||||
return uniq(filter(None, ans))
|
||||
return uniq(list(filter(None, ans)))
|
||||
|
||||
|
||||
def find_tests():
|
||||
@ -167,6 +168,7 @@ def find_tests():
|
||||
run(rule('split', 'a b', ' ', 'has'), 'a b', 'a,b')
|
||||
return unittest.defaultTestLoader.loadTestsFromTestCase(TestTagMapper)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.utils.run_tests import run_cli
|
||||
run_cli(find_tests())
|
||||
|
@ -14,6 +14,7 @@ from calibre.ebooks.oeb.base import OPF
|
||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||
from calibre.spell import parse_lang_code
|
||||
from calibre.utils.localization import lang_as_iso639_1
|
||||
from polyglot.builtins import filter
|
||||
|
||||
PARSER = etree.XMLParser(recover=True, no_network=True)
|
||||
|
||||
|
@ -19,7 +19,7 @@ from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.ebooks.metadata.opf2 import dump_dict
|
||||
from calibre.utils.date import parse_date, isoformat, now
|
||||
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from polyglot.builtins import iteritems, string_or_bytes
|
||||
from polyglot.builtins import iteritems, string_or_bytes, filter
|
||||
|
||||
_xml_declaration = re.compile(r'<\?xml[^<>]+encoding\s*=\s*[\'"](.*?)[\'"][^<>]*>', re.IGNORECASE)
|
||||
|
||||
|
@ -9,6 +9,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
from struct import unpack_from
|
||||
|
||||
from calibre.ebooks.mobi.debug.headers import EXTHHeader
|
||||
from polyglot.builtins import filter
|
||||
|
||||
|
||||
class ContainerHeader(object):
|
||||
@ -43,7 +44,7 @@ class ContainerHeader(object):
|
||||
|
||||
def add_hrefs(self, data):
|
||||
# kindlegen inserts a trailing | after the last href
|
||||
self.hrefs = filter(None, data.decode('utf-8').split('|'))
|
||||
self.hrefs = list(filter(None, data.decode('utf-8').split('|')))
|
||||
|
||||
def __str__(self):
|
||||
ans = [('*'*10) + ' Container Header ' + ('*'*10)]
|
||||
@ -64,4 +65,3 @@ class ContainerHeader(object):
|
||||
if len(self.bytes_after_exth) != self.null_bytes_after_exth:
|
||||
a('Non-null bytes present after EXTH header!!!!')
|
||||
return '\n'.join(ans) + '\n\n' + str(self.exth) + '\n\n' + ('Title: %s' % self.title)
|
||||
|
||||
|
@ -19,7 +19,7 @@ from odf.namespaces import TEXTNS as odTEXTNS
|
||||
|
||||
from calibre import CurrentDir, walk
|
||||
from calibre.ebooks.oeb.base import _css_logger
|
||||
from polyglot.builtins import unicode_type, string_or_bytes
|
||||
from polyglot.builtins import unicode_type, string_or_bytes, filter
|
||||
|
||||
|
||||
class Extract(ODF2XHTML):
|
||||
@ -129,8 +129,8 @@ class Extract(ODF2XHTML):
|
||||
if (len(div1), len(div2)) != (1, 1):
|
||||
continue
|
||||
cls = div1.get('class', '')
|
||||
first_rules = filter(None, [self.get_css_for_class(x) for x in
|
||||
cls.split()])
|
||||
first_rules = list(filter(None, [self.get_css_for_class(x) for x in
|
||||
cls.split()]))
|
||||
has_align = False
|
||||
for r in first_rules:
|
||||
if r.style.getProperty(u'text-align') is not None:
|
||||
@ -139,8 +139,8 @@ class Extract(ODF2XHTML):
|
||||
if not has_align:
|
||||
aval = None
|
||||
cls = div2.get(u'class', u'')
|
||||
rules = filter(None, [self.get_css_for_class(x) for x in
|
||||
cls.split()])
|
||||
rules = list(filter(None, [self.get_css_for_class(x) for x in
|
||||
cls.split()]))
|
||||
for r in rules:
|
||||
ml = r.style.getPropertyCSSValue(u'margin-left') or ml
|
||||
mr = r.style.getPropertyCSSValue(u'margin-right') or mr
|
||||
|
@ -22,7 +22,7 @@ from calibre.ebooks.oeb.parse_utils import (barename, XHTML_NS, RECOVER_PARSER,
|
||||
namespace, XHTML, parse_html, NotHTML)
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from calibre.utils.short_uuid import uuid4
|
||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, range, itervalues
|
||||
from polyglot.builtins import iteritems, unicode_type, string_or_bytes, range, itervalues, filter
|
||||
from polyglot.urllib import unquote, urldefrag, urljoin, urlparse, urlunparse
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
|
||||
@ -2008,7 +2008,7 @@ def rel_href(base_href, href):
|
||||
return href
|
||||
if '/' not in base_href:
|
||||
return href
|
||||
base = filter(lambda x: x and x != '.', os.path.dirname(os.path.normpath(base_href)).replace(os.sep, '/').split('/'))
|
||||
base = list(filter(lambda x: x and x != '.', os.path.dirname(os.path.normpath(base_href)).replace(os.sep, '/').split('/')))
|
||||
while True:
|
||||
try:
|
||||
idx = base.index('..')
|
||||
|
@ -18,7 +18,7 @@ from calibre.ebooks.oeb.normalize_css import normalize_filter_css, normalizers
|
||||
from calibre.ebooks.oeb.polish.pretty import pretty_script_or_style, pretty_xml_tree, serialize
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
from css_selectors import Select, SelectorError
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, filter
|
||||
|
||||
|
||||
def filter_used_rules(rules, log, select):
|
||||
@ -325,8 +325,7 @@ def remove_property_value(prop, predicate):
|
||||
values of the property would be removed, the property is removed from its
|
||||
parent instead. Note that this means the property must have a parent (a
|
||||
CSSStyleDeclaration). '''
|
||||
removed_vals = []
|
||||
removed_vals = filter(predicate, prop.propertyValue)
|
||||
removed_vals = list(filter(predicate, prop.propertyValue))
|
||||
if len(removed_vals) == len(prop.propertyValue):
|
||||
prop.parent.removeProperty(prop.name)
|
||||
else:
|
||||
|
@ -9,7 +9,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
from calibre.ebooks.oeb.polish.container import OEB_STYLES, OEB_DOCS
|
||||
from calibre.ebooks.oeb.normalize_css import normalize_font
|
||||
from tinycss.fonts3 import parse_font_family, parse_font, serialize_font_family, serialize_font
|
||||
from polyglot.builtins import iteritems
|
||||
from polyglot.builtins import iteritems, filter
|
||||
|
||||
|
||||
def unquote(x):
|
||||
@ -68,7 +68,7 @@ def change_font_in_declaration(style, old_name, new_name=None):
|
||||
ff = style.getProperty('font-family')
|
||||
if ff is not None:
|
||||
fams = parse_font_family(ff.propertyValue.cssText)
|
||||
nfams = filter(None, [new_name if x == old_name else x for x in fams])
|
||||
nfams = list(filter(None, [new_name if x == old_name else x for x in fams]))
|
||||
if fams != nfams:
|
||||
if nfams:
|
||||
ff.propertyValue.cssText = serialize_font_family(nfams)
|
||||
@ -79,7 +79,7 @@ def change_font_in_declaration(style, old_name, new_name=None):
|
||||
if ff is not None:
|
||||
props = parse_font(ff.propertyValue.cssText)
|
||||
fams = props.get('font-family') or []
|
||||
nfams = filter(None, [new_name if x == old_name else x for x in fams])
|
||||
nfams = list(filter(None, [new_name if x == old_name else x for x in fams]))
|
||||
if fams != nfams:
|
||||
props['font-family'] = nfams
|
||||
if nfams:
|
||||
|
@ -17,7 +17,7 @@ from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, get_container
|
||||
from calibre.ebooks.oeb.polish.parsing import parse
|
||||
from calibre.ebooks.oeb.polish.toc import find_existing_ncx_toc, find_existing_nav_toc
|
||||
from calibre.utils.icu import ord_string
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
|
||||
_patterns = None
|
||||
|
||||
@ -86,7 +86,7 @@ def get_words(text, lang):
|
||||
ans = split_into_words(unicode_type(text), lang)
|
||||
except (TypeError, ValueError):
|
||||
return ()
|
||||
return filter(filter_words, ans)
|
||||
return list(filter(filter_words, ans))
|
||||
|
||||
|
||||
def add_words(text, node, words, file_name, locale, node_item):
|
||||
|
@ -20,7 +20,7 @@ from calibre.ebooks import unit_convert
|
||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, xpath, urlnormalize
|
||||
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||
from css_selectors import Select, SelectorError, INAPPROPRIATE_PSEUDO_CLASSES
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
from tinycss.media3 import CSSMedia3Parser
|
||||
|
||||
css_parser_log.setLevel(logging.WARN)
|
||||
|
@ -15,7 +15,7 @@ import os, re
|
||||
from calibre.ebooks.rtf2xml import copy
|
||||
from calibre.utils.mreplace import MReplace
|
||||
from calibre.ptempfile import better_mktemp
|
||||
from polyglot.builtins import codepoint_to_chr, range
|
||||
from polyglot.builtins import codepoint_to_chr, range, filter
|
||||
|
||||
|
||||
class Tokenize:
|
||||
@ -124,7 +124,7 @@ class Tokenize:
|
||||
# split
|
||||
tokens = re.split(self.__splitexp, input_file)
|
||||
# remove empty tokens and \n
|
||||
return filter(lambda x: len(x) > 0 and x != '\n', tokens)
|
||||
return list(filter(lambda x: len(x) > 0 and x != '\n', tokens))
|
||||
|
||||
def __compile_expressions(self):
|
||||
SIMPLE_RPL = {
|
||||
@ -184,7 +184,7 @@ class Tokenize:
|
||||
# correct unicode
|
||||
tokens = map(self.__unicode_process, tokens)
|
||||
# remove empty items created by removing \uc
|
||||
tokens = filter(lambda x: len(x) > 0, tokens)
|
||||
tokens = list(filter(lambda x: len(x) > 0, tokens))
|
||||
|
||||
# write
|
||||
with open(self.__write_to, 'wb') as write_obj:
|
||||
|
@ -15,7 +15,7 @@ from PyQt5.Qt import (
|
||||
from calibre.ebooks.metadata import check_isbn
|
||||
from calibre.constants import iswindows
|
||||
from calibre.gui2 import gprefs, question_dialog, error_dialog
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, filter
|
||||
|
||||
|
||||
class AddFromISBN(QDialog):
|
||||
|
@ -32,7 +32,7 @@ from calibre.utils.date import qt_to_dt, internal_iso_format_string
|
||||
from calibre.utils.icu import capitalize, sort_key
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from calibre.gui2.widgets import LineEditECM
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, error_message
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, error_message, filter
|
||||
|
||||
Settings = namedtuple('Settings',
|
||||
'remove_all remove add au aus do_aus rating pub do_series do_autonumber '
|
||||
@ -186,7 +186,7 @@ class MyBlockingBusy(QDialog): # {{{
|
||||
self.progress_next_step_range.emit(len(self.ids))
|
||||
for book_id in self.ids:
|
||||
fmts = db.formats(book_id, verify_formats=False)
|
||||
paths = filter(None, [db.format_abspath(book_id, fmt) for fmt in fmts])
|
||||
paths = list(filter(None, [db.format_abspath(book_id, fmt) for fmt in fmts]))
|
||||
if paths:
|
||||
ret = worker(
|
||||
'calibre.ebooks.metadata.worker', 'read_metadata_bulk',
|
||||
|
@ -24,7 +24,7 @@ from calibre.gui2 import error_dialog, question_dialog, info_dialog, open_url, g
|
||||
from calibre.gui2.preferences.plugins import ConfigWidget
|
||||
from calibre.utils.date import UNDEFINED_DATE, format_date
|
||||
from calibre.utils.https import get_https_resource_securely
|
||||
from polyglot.builtins import itervalues, unicode_type
|
||||
from polyglot.builtins import itervalues, unicode_type, filter
|
||||
|
||||
SERVER = 'https://code.calibre-ebook.com/plugins/'
|
||||
INDEX_URL = '%splugins.json.bz2' % SERVER
|
||||
|
@ -35,7 +35,7 @@ from calibre.utils.img import image_from_data, Canvas, optimize_png, optimize_jp
|
||||
from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
||||
from calibre.utils.filenames import atomic_rename
|
||||
from lzma.xz import compress, decompress
|
||||
from polyglot.builtins import iteritems, map, range, reraise
|
||||
from polyglot.builtins import iteritems, map, range, reraise, filter
|
||||
from polyglot import http_client
|
||||
from polyglot.queue import Queue, Empty
|
||||
|
||||
|
@ -31,7 +31,7 @@ from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from calibre.utils.date import local_tz
|
||||
from calibre.library.comments import merge_comments as merge_two_comments
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
|
||||
BASE_TITLE = _('Edit Metadata')
|
||||
fetched_fields = ('title', 'title_sort', 'authors', 'author_sort', 'series',
|
||||
|
@ -20,7 +20,7 @@ from calibre.gui2.ui import get_gui
|
||||
from calibre.gui2.widgets2 import Dialog
|
||||
from calibre.utils.config import JSONConfig
|
||||
from calibre.utils.localization import localize_user_manual_link
|
||||
from polyglot.builtins import iteritems, unicode_type, range
|
||||
from polyglot.builtins import iteritems, unicode_type, range, filter
|
||||
|
||||
tag_maps = JSONConfig('tag-map-rules')
|
||||
|
||||
@ -154,7 +154,7 @@ class RuleEdit(QWidget):
|
||||
|
||||
def edit_tags(self):
|
||||
from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||
d = TagEditor(self, get_gui().current_db, current_tags=filter(None, [x.strip() for x in self.query.text().split(',')]))
|
||||
d = TagEditor(self, get_gui().current_db, current_tags=list(filter(None, [x.strip() for x in self.query.text().split(',')])))
|
||||
if d.exec_() == d.Accepted:
|
||||
self.query.setText(', '.join(d.tags))
|
||||
|
||||
|
@ -38,7 +38,7 @@ from calibre.gui2.tweak_book import (
|
||||
from calibre.gui2.tweak_book.editor import syntax_from_mime
|
||||
from calibre.gui2.tweak_book.templates import template_for
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, range
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, range, filter
|
||||
from polyglot.binary import as_hex_unicode
|
||||
|
||||
try:
|
||||
|
@ -8,7 +8,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import time, textwrap, json
|
||||
from bisect import bisect_right
|
||||
from polyglot.builtins import map, unicode_type
|
||||
from polyglot.builtins import map, unicode_type, filter
|
||||
from threading import Thread
|
||||
from functools import partial
|
||||
|
||||
@ -321,7 +321,7 @@ class WebPage(QWebPage):
|
||||
ans = None
|
||||
return ans
|
||||
val = self.mainFrame().evaluateJavaScript('window.calibre_preview_integration.line_numbers()')
|
||||
self._line_numbers = sorted(uniq(filter(lambda x:x is not None, map(atoi, val))))
|
||||
self._line_numbers = sorted(uniq(list(filter(lambda x:x is not None, map(atoi, val)))))
|
||||
return self._line_numbers
|
||||
|
||||
def go_to_line(self, lnum):
|
||||
|
@ -8,7 +8,7 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import time, textwrap, os
|
||||
from threading import Thread
|
||||
from polyglot.builtins import iteritems, map, range
|
||||
from polyglot.builtins import iteritems, map, range, filter
|
||||
from operator import itemgetter
|
||||
from functools import partial
|
||||
from collections import defaultdict
|
||||
@ -166,7 +166,7 @@ class FilesView(QTableView):
|
||||
|
||||
@property
|
||||
def selected_locations(self):
|
||||
return filter(None, (self.proxy.sourceModel().location(self.proxy.mapToSource(index)) for index in self.selectionModel().selectedIndexes()))
|
||||
return list(filter(None, (self.proxy.sourceModel().location(self.proxy.mapToSource(index)) for index in self.selectionModel().selectedIndexes())))
|
||||
|
||||
@property
|
||||
def current_location(self):
|
||||
|
@ -34,7 +34,7 @@ from calibre.gui2.tweak_book.widgets import BusyCursor
|
||||
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
||||
from calibre.utils.icu import primary_contains
|
||||
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
||||
from polyglot.builtins import iteritems, unicode_type, range, error_message
|
||||
from polyglot.builtins import iteritems, unicode_type, range, error_message, filter
|
||||
|
||||
|
||||
# The search panel {{{
|
||||
|
@ -37,7 +37,7 @@ from calibre.spell.import_from import import_from_oxt
|
||||
from calibre.spell.break_iterator import split_into_words
|
||||
from calibre.utils.localization import calibre_langcode_to_name, get_language, get_lang, canonicalize_lang
|
||||
from calibre.utils.icu import sort_key, primary_sort_key, primary_contains, contains
|
||||
from polyglot.builtins import iteritems, unicode_type, range
|
||||
from polyglot.builtins import iteritems, unicode_type, range, filter
|
||||
|
||||
LANG = 0
|
||||
COUNTRY = 1
|
||||
@ -720,7 +720,7 @@ class WordsModel(QAbstractTableModel):
|
||||
return True
|
||||
|
||||
def do_filter(self):
|
||||
self.items = filter(self.filter_item, self.words)
|
||||
self.items = list(filter(self.filter_item, self.words))
|
||||
|
||||
def toggle_ignored(self, row):
|
||||
w = self.word_for_row(row)
|
||||
|
@ -9,7 +9,7 @@ from threading import Thread
|
||||
from uuid import uuid4
|
||||
|
||||
from PyQt5.Qt import pyqtSignal, QEventLoop, Qt
|
||||
from polyglot.builtins import string_or_bytes
|
||||
from polyglot.builtins import string_or_bytes, filter
|
||||
|
||||
is64bit = sys.maxsize > (1 << 32)
|
||||
base = sys.extensions_location if hasattr(sys, 'new_app_layout') else os.path.dirname(sys.executable)
|
||||
@ -359,7 +359,7 @@ def test(helper=HELPER):
|
||||
if server.err_msg is not None:
|
||||
raise RuntimeError(server.err_msg)
|
||||
server.join(2)
|
||||
parts = filter(None, server.data.split(b'\0'))
|
||||
parts = list(filter(None, server.data.split(b'\0')))
|
||||
if parts[0] != secret:
|
||||
raise RuntimeError('Did not get back secret: %r != %r' % (secret, parts[0]))
|
||||
q = parts[1].decode('utf-8')
|
||||
|
@ -14,7 +14,7 @@ from calibre.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
|
||||
from calibre.customize.conversion import DummyReporter
|
||||
from calibre.constants import preferred_encoding
|
||||
from calibre.ebooks.metadata import format_isbn
|
||||
from polyglot.builtins import string_or_bytes
|
||||
from polyglot.builtins import string_or_bytes, filter
|
||||
|
||||
|
||||
class BIBTEX(CatalogPlugin):
|
||||
@ -384,7 +384,7 @@ class BIBTEX(CatalogPlugin):
|
||||
|
||||
# check in book strict if all is ok else throw a warning into log
|
||||
if bib_entry == 'book' :
|
||||
nb_books = len(filter(check_entry_book_valid, data))
|
||||
nb_books = len(list(filter(check_entry_book_valid, data)))
|
||||
if nb_books < nb_entries :
|
||||
log.warn("Only %d entries in %d are book compatible" % (nb_books, nb_entries))
|
||||
nb_entries = nb_books
|
||||
|
@ -10,7 +10,7 @@ import re, os, traceback, fnmatch
|
||||
from calibre import isbytestring
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from polyglot.builtins import iteritems
|
||||
from polyglot.builtins import iteritems, filter
|
||||
|
||||
EBOOK_EXTENSIONS = frozenset(BOOK_EXTENSIONS)
|
||||
NORMALS = frozenset(['metadata.opf', 'cover.jpg'])
|
||||
|
@ -12,7 +12,7 @@ from calibre.ebooks.metadata import MetaInformation
|
||||
from calibre.ebooks.metadata import string_to_authors
|
||||
from calibre.utils.serialize import pickle_loads, pickle_dumps
|
||||
from calibre import isbytestring
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.builtins import unicode_type, filter
|
||||
|
||||
|
||||
class Concatenate(object):
|
||||
@ -1070,8 +1070,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
self.conn.get('SELECT id, name FROM authors')]
|
||||
|
||||
def all_author_names(self):
|
||||
return filter(None, [i[0].strip().replace('|', ',') for i in self.conn.get(
|
||||
'SELECT name FROM authors')])
|
||||
return list(filter(None, [i[0].strip().replace('|', ',') for i in self.conn.get(
|
||||
'SELECT name FROM authors')]))
|
||||
|
||||
def all_publishers(self):
|
||||
return [(i[0], i[1]) for i in
|
||||
|
@ -16,7 +16,7 @@ from calibre.library.prefs import DBPrefs
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.utils.date import utcfromtimestamp
|
||||
from calibre import isbytestring
|
||||
from polyglot.builtins import iteritems
|
||||
from polyglot.builtins import iteritems, filter
|
||||
|
||||
NON_EBOOK_EXTENSIONS = frozenset([
|
||||
'jpg', 'jpeg', 'gif', 'png', 'bmp',
|
||||
@ -174,7 +174,7 @@ class Restore(Thread):
|
||||
|
||||
def process_dir(self, dirpath, filenames, book_id):
|
||||
book_id = int(book_id)
|
||||
formats = filter(self.is_ebook_file, filenames)
|
||||
formats = list(filter(self.is_ebook_file, filenames))
|
||||
fmts = [os.path.splitext(x)[1][1:].upper() for x in formats]
|
||||
sizes = [os.path.getsize(os.path.join(dirpath, x)) for x in formats]
|
||||
names = [os.path.splitext(x)[0] for x in formats]
|
||||
|
@ -18,7 +18,7 @@ from calibre.spell import parse_lang_code
|
||||
from calibre.utils.config import JSONConfig
|
||||
from calibre.utils.icu import capitalize
|
||||
from calibre.utils.localization import get_lang, get_system_locale
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, filter
|
||||
|
||||
Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id')
|
||||
LoadedDictionary = namedtuple('Dictionary', 'primary_locale locales obj builtin name id')
|
||||
|
@ -15,7 +15,7 @@ from calibre.srv.routes import Router
|
||||
from calibre.srv.users import UserManager
|
||||
from calibre.utils.date import utcnow
|
||||
from calibre.utils.search_query_parser import ParseException
|
||||
from polyglot.builtins import itervalues
|
||||
from polyglot.builtins import itervalues, filter
|
||||
|
||||
|
||||
class Context(object):
|
||||
|
@ -16,7 +16,7 @@ from calibre.srv.loop import Connection, READ, WRITE
|
||||
from calibre.srv.utils import MultiDict, HTTP1, HTTP11, Accumulator
|
||||
from polyglot import http_client, reprlib
|
||||
from polyglot.urllib import unquote
|
||||
from polyglot.builtins import error_message
|
||||
from polyglot.builtins import error_message, filter
|
||||
|
||||
protocol_map = {(1, 0):HTTP1, (1, 1):HTTP11}
|
||||
quoted_slash = re.compile(br'%2[fF]')
|
||||
|
@ -19,7 +19,7 @@ from calibre.srv.routes import endpoint
|
||||
from calibre.srv.utils import get_library_data, http_date
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from calibre.utils.date import dt_as_local, is_date_undefined, timestampfromdt
|
||||
from polyglot.builtins import iteritems, string_or_bytes
|
||||
from polyglot.builtins import iteritems, string_or_bytes, filter
|
||||
from polyglot.urllib import urlencode
|
||||
|
||||
# /mobile {{{
|
||||
|
@ -9,7 +9,7 @@ from functools import partial
|
||||
|
||||
from calibre import prints
|
||||
from calibre.constants import preferred_encoding
|
||||
from polyglot.builtins import iteritems, raw_input
|
||||
from polyglot.builtins import iteritems, raw_input, filter
|
||||
|
||||
# Manage users CLI {{{
|
||||
|
||||
@ -175,7 +175,7 @@ def manage_users_cli(path=None):
|
||||
pass
|
||||
else:
|
||||
names = get_input(_('Enter a comma separated list of library names:'))
|
||||
names = filter(None, [x.strip() for x in names.split(',')])
|
||||
names = list(filter(None, [x.strip() for x in names.split(',')]))
|
||||
w = 'allowed_library_names' if c == 1 else 'blocked_library_names'
|
||||
t = _('Allowing access only to libraries: {}') if c == 1 else _(
|
||||
'Allowing access to all libraries, except: {}')
|
||||
|
@ -22,7 +22,7 @@ from calibre.utils.icu import collation_order
|
||||
from calibre.utils.localization import calibre_langcode_to_name
|
||||
from calibre.library.comments import comments_to_html, markdown
|
||||
from calibre.library.field_metadata import category_icon_map
|
||||
from polyglot.builtins import iteritems, itervalues, range
|
||||
from polyglot.builtins import iteritems, itervalues, range, filter
|
||||
from polyglot.urllib import quote
|
||||
|
||||
IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split())
|
||||
@ -304,7 +304,7 @@ categories_with_ratings = {'authors', 'series', 'publisher', 'tags'}
|
||||
|
||||
|
||||
def get_name_components(name):
|
||||
components = filter(None, [t.strip() for t in name.split('.')])
|
||||
components = list(filter(None, [t.strip() for t in name.split('.')]))
|
||||
if not components or '.'.join(components) != name:
|
||||
components = [name]
|
||||
return components
|
||||
@ -533,9 +533,9 @@ def render_categories(opts, db, category_data):
|
||||
if opts.hidden_categories:
|
||||
# We have to remove hidden categories after all processing is done as
|
||||
# items from a hidden category could be in a user category
|
||||
root['children'] = filter((lambda child:items[child['id']]['category'] not in opts.hidden_categories), root['children'])
|
||||
root['children'] = list(filter((lambda child:items[child['id']]['category'] not in opts.hidden_categories), root['children']))
|
||||
if opts.hide_empty_categories:
|
||||
root['children'] = filter((lambda child:items[child['id']]['count'] > 0), root['children'])
|
||||
root['children'] = list(filter((lambda child:items[child['id']]['count'] > 0), root['children']))
|
||||
return {'root':root, 'item_map': items}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ from calibre import force_unicode
|
||||
from calibre.srv.errors import HTTPNotFound, HTTPInternalServerError
|
||||
from calibre.srv.routes import endpoint
|
||||
from calibre.srv.utils import get_library_data, http_date, Offsets
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from polyglot.builtins import iteritems, unicode_type, filter
|
||||
from polyglot.urllib import urlencode
|
||||
from polyglot.binary import as_hex_unicode, from_hex_unicode
|
||||
|
||||
|
@ -12,7 +12,7 @@ from operator import attrgetter
|
||||
from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError
|
||||
from calibre.srv.utils import http_date
|
||||
from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, range, zip
|
||||
from polyglot.builtins import iteritems, itervalues, unicode_type, range, zip, filter
|
||||
from polyglot import http_client
|
||||
from polyglot.urllib import quote as urlquote
|
||||
|
||||
@ -114,7 +114,7 @@ class Route(object):
|
||||
del endpoint_
|
||||
if not self.endpoint.route.startswith('/'):
|
||||
raise RouteError('A route must start with /, %s does not' % self.endpoint.route)
|
||||
parts = filter(None, self.endpoint.route.split('/'))
|
||||
parts = list(filter(None, self.endpoint.route.split('/')))
|
||||
matchers = self.matchers = []
|
||||
self.defaults = {}
|
||||
found_optional_part = False
|
||||
|
@ -8,7 +8,7 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os
|
||||
from calibre.srv.tests.base import BaseTest
|
||||
from polyglot.builtins import itervalues
|
||||
from polyglot.builtins import itervalues, filter
|
||||
|
||||
|
||||
class TestRouter(BaseTest):
|
||||
@ -53,7 +53,7 @@ class TestRouter(BaseTest):
|
||||
router = Router()
|
||||
|
||||
def find(path):
|
||||
path = filter(None, path.split('/'))
|
||||
path = list(filter(None, path.split('/')))
|
||||
ep, args = router.find_route(path)
|
||||
args = list(args)
|
||||
return ep, args
|
||||
|
@ -3,7 +3,7 @@ __copyright__ = '2010, sengian <sengian1@gmail.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import re
|
||||
from polyglot.builtins import codepoint_to_chr, map, range
|
||||
from polyglot.builtins import codepoint_to_chr, map, range, filter
|
||||
from polyglot.html_entities import name2codepoint
|
||||
from calibre.constants import plugins, preferred_encoding
|
||||
|
||||
|
@ -16,7 +16,7 @@ from calibre.constants import (config_dir, iswindows, isosx, plugins, DEBUG,
|
||||
isworker, filesystem_encoding)
|
||||
from calibre.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
||||
from calibre.utils.icu import sort_key
|
||||
from polyglot.builtins import itervalues, unicode_type
|
||||
from polyglot.builtins import itervalues, unicode_type, filter
|
||||
|
||||
|
||||
class NoFonts(ValueError):
|
||||
@ -281,7 +281,7 @@ class FontScanner(Thread):
|
||||
return False
|
||||
|
||||
for family in self.find_font_families():
|
||||
faces = filter(filter_faces, self.fonts_for_family(family))
|
||||
faces = list(filter(filter_faces, self.fonts_for_family(family)))
|
||||
if not faces:
|
||||
continue
|
||||
generic_family = panose_to_css_generic_family(faces[0]['panose'])
|
||||
|
@ -8,6 +8,7 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys
|
||||
from polyglot.builtins import filter
|
||||
|
||||
is_narrow_build = sys.maxunicode < 0x10ffff
|
||||
|
||||
|
@ -16,7 +16,7 @@ from itertools import islice
|
||||
from calibre import detect_ncpus as cpu_count, as_unicode
|
||||
from calibre.constants import plugins, filesystem_encoding
|
||||
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
||||
from polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input
|
||||
from polyglot.builtins import iteritems, itervalues, map, unicode_type, range, zip, raw_input, filter
|
||||
from polyglot.queue import Queue
|
||||
|
||||
DEFAULT_LEVEL1 = '/'
|
||||
|
@ -16,6 +16,7 @@ import win32con, win32api, win32gui, pywintypes, winerror
|
||||
from calibre import prints
|
||||
from calibre.gui2 import must_use_qt
|
||||
from calibre.utils.winreg.default_programs import split_commandline
|
||||
from polyglot.builtins import filter
|
||||
|
||||
ICON_SIZE = 64
|
||||
|
||||
|
@ -22,7 +22,7 @@ from calibre.utils.filenames import atomic_rename
|
||||
from calibre.utils.terminal import ANSIStream
|
||||
from duktape import Context, JSError, to_python
|
||||
from lzma.xz import compress, decompress
|
||||
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message
|
||||
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter
|
||||
from polyglot.queue import Empty, Queue
|
||||
|
||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||
@ -395,8 +395,8 @@ class Repl(Thread):
|
||||
def completer(text, num):
|
||||
if self.completions is None:
|
||||
self.to_repl.put(('complete', text))
|
||||
self.completions = filter(None, self.get_from_repl())
|
||||
if self.completions is None:
|
||||
self.completions = list(filter(None, self.get_from_repl()))
|
||||
if not self.completions:
|
||||
return None
|
||||
try:
|
||||
return self.completions[num]
|
||||
|
Loading…
x
Reference in New Issue
Block a user