mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-16 19:13:32 +02:00
Removed iteritems and itervalues, which are redundant
This commit is contained in:
@@ -16,7 +16,6 @@ from ebook_converter.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYL
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.utils.filenames import ascii_filename, ascii_text
|
||||
from ebook_converter.utils.icu import numeric_sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -208,7 +207,7 @@ class CSSFlattener(object):
|
||||
|
||||
def store_page_margins(self):
|
||||
self.opts._stored_page_margins = {}
|
||||
for item, stylizer in iteritems(self.stylizers):
|
||||
for item, stylizer in self.stylizers.items():
|
||||
margins = self.opts._stored_page_margins[item.href] = {}
|
||||
for prop, val in stylizer.page_rule.items():
|
||||
p, w = prop.partition('-')[::2]
|
||||
@@ -262,7 +261,7 @@ class CSSFlattener(object):
|
||||
if font[k] != 'normal':
|
||||
cfont[k] = font[k]
|
||||
rule = '@font-face { %s }'%('; '.join('%s:%s'%(k, v) for k, v in
|
||||
iteritems(cfont)))
|
||||
cfont.items()))
|
||||
rule = css_parser.parseString(rule)
|
||||
efi.append(rule)
|
||||
|
||||
@@ -527,7 +526,7 @@ class CSSFlattener(object):
|
||||
keep_classes = set()
|
||||
|
||||
if cssdict:
|
||||
items = sorted(iteritems(cssdict))
|
||||
items = sorted(cssdict.items())
|
||||
css = ';\n'.join(u'%s: %s' % (key, val) for key, val in items)
|
||||
classes = node.get('class', '').strip() or 'calibre'
|
||||
classes_list = classes.split()
|
||||
@@ -544,8 +543,8 @@ class CSSFlattener(object):
|
||||
node.attrib['class'] = match
|
||||
keep_classes.add(match)
|
||||
|
||||
for psel, cssdict in iteritems(pseudo_classes):
|
||||
items = sorted(iteritems(cssdict))
|
||||
for psel, cssdict in pseudo_classes.items():
|
||||
items = sorted(cssdict.items())
|
||||
css = ';\n'.join('%s: %s' % (key, val) for key, val in items)
|
||||
pstyles = pseudo_styles[psel]
|
||||
if css in pstyles:
|
||||
@@ -647,7 +646,7 @@ class CSSFlattener(object):
|
||||
gc_map[css] = href
|
||||
|
||||
ans = {}
|
||||
for css, items in iteritems(global_css):
|
||||
for css, items in global_css.items():
|
||||
for item in items:
|
||||
ans[item] = gc_map[css]
|
||||
return ans
|
||||
@@ -663,7 +662,7 @@ class CSSFlattener(object):
|
||||
fsize = self.context.dest.fbase
|
||||
self.flatten_node(html, stylizer, names, styles, pseudo_styles, fsize, item.id, recurse=False)
|
||||
self.flatten_node(html.find(XHTML('body')), stylizer, names, styles, pseudo_styles, fsize, item.id)
|
||||
items = sorted(((key, val) for (val, key) in iteritems(styles)))
|
||||
items = sorted(((key, val) for (val, key) in styles.items()))
|
||||
# :hover must come after link and :active must come after :hover
|
||||
psels = sorted(pseudo_styles, key=lambda x :
|
||||
{'hover':1, 'active':2}.get(x, 0))
|
||||
@@ -671,7 +670,7 @@ class CSSFlattener(object):
|
||||
styles = pseudo_styles[psel]
|
||||
if not styles:
|
||||
continue
|
||||
x = sorted(((k+':'+psel, v) for v, k in iteritems(styles)))
|
||||
x = sorted(((k+':'+psel, v) for v, k in styles.items()))
|
||||
items.extend(x)
|
||||
|
||||
css = ''.join(".%s {\n%s;\n}\n\n" % (key, val) for key, val in items)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import os, re
|
||||
from ebook_converter.utils.date import isoformat, now
|
||||
from ebook_converter import guess_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -48,7 +47,7 @@ def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
|
||||
m.clear('series')
|
||||
identifiers = mi.get_identifiers()
|
||||
set_isbn = False
|
||||
for typ, val in iteritems(identifiers):
|
||||
for typ, val in identifiers.items():
|
||||
has = False
|
||||
if typ.lower() == 'isbn':
|
||||
set_isbn = True
|
||||
|
||||
@@ -2,7 +2,6 @@ import numbers
|
||||
from collections import Counter
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import barename, XPath
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -149,7 +148,7 @@ class RemoveFakeMargins(object):
|
||||
self.levels[level].append(p)
|
||||
|
||||
remove = set()
|
||||
for k, v in iteritems(self.levels):
|
||||
for k, v in self.levels.items():
|
||||
num = len(v)
|
||||
self.log.debug('Found %d items of level:'%num, k)
|
||||
level = int(k.split('_')[-1])
|
||||
|
||||
@@ -15,7 +15,6 @@ from ebook_converter.ebooks.epub import rules
|
||||
from ebook_converter.ebooks.oeb.base import (OEB_STYLES, XPNSMAP as NAMESPACES,
|
||||
rewrite_links, XHTML, urlnormalize)
|
||||
from ebook_converter.ebooks.oeb.polish.split import do_split
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter.css_selectors import Select, SelectorError
|
||||
|
||||
@@ -243,7 +242,7 @@ class FlowSplitter(object):
|
||||
|
||||
self.trees = [orig_tree]
|
||||
while ordered_ids:
|
||||
pb_id, (pattern, before) = next(iteritems(ordered_ids))
|
||||
pb_id, (pattern, before) = next(iter(ordered_ids.items()))
|
||||
del ordered_ids[pb_id]
|
||||
for i in range(len(self.trees)-1, -1, -1):
|
||||
tree = self.trees[i]
|
||||
|
||||
@@ -7,7 +7,6 @@ from collections import OrderedDict, Counter
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text, barename
|
||||
from ebook_converter.ebooks import ConversionError
|
||||
from ebook_converter.polyglot.builtins import itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -269,8 +268,8 @@ class DetectStructure(object):
|
||||
return []
|
||||
|
||||
for document in self.oeb.spine:
|
||||
previous_level1 = list(itervalues(added))[-1] if added else None
|
||||
previous_level2 = list(itervalues(added2))[-1] if added2 else None
|
||||
previous_level1 = list(added.values())[-1] if added else None
|
||||
previous_level2 = list(added2.values())[-1] if added2 else None
|
||||
|
||||
level1_toc, level1_title = self.get_toc_parts_for_xpath(self.opts.level1_toc)
|
||||
for elem in find_matches(level1_toc, document.data):
|
||||
|
||||
@@ -2,7 +2,6 @@ from collections import defaultdict
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import urlnormalize, css_text
|
||||
from ebook_converter.utils.fonts.sfnt.subset import subset, NoGlyphs, UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
from ebook_converter.tinycss.fonts3 import parse_font_family
|
||||
|
||||
|
||||
@@ -148,7 +147,7 @@ class SubsetFonts(object):
|
||||
else:
|
||||
fonts[item.href] = font
|
||||
|
||||
for font in itervalues(fonts):
|
||||
for font in fonts.values():
|
||||
if not font['chars']:
|
||||
self.log('The font %s is unused. Removing it.'%font['src'])
|
||||
remove(font)
|
||||
@@ -167,8 +166,8 @@ class SubsetFonts(object):
|
||||
totals[1] += sz
|
||||
else:
|
||||
font['item'].data = raw
|
||||
nlen = sum(itervalues(new_stats))
|
||||
olen = sum(itervalues(old_stats))
|
||||
nlen = sum(new_stats.values())
|
||||
olen = sum(old_stats.values())
|
||||
self.log('Decreased the font %s to %.1f%% of its original size'%
|
||||
(font['src'], nlen/olen *100))
|
||||
totals[0] += nlen
|
||||
@@ -204,7 +203,7 @@ class SubsetFonts(object):
|
||||
if rule.type != rule.STYLE_RULE:
|
||||
continue
|
||||
props = {k:v for k,v in
|
||||
iteritems(get_font_properties(rule)) if v}
|
||||
get_font_properties(rule).items() if v}
|
||||
if not props:
|
||||
continue
|
||||
for sel in rule.selectorList:
|
||||
|
||||
Reference in New Issue
Block a user