pep8 and code simplification

This commit is contained in:
Kovid Goyal 2017-01-25 17:28:45 +05:30
parent 05b97d86e0
commit f8a2449d7f
2 changed files with 3 additions and 12 deletions

View File

@ -220,4 +220,3 @@ def cleanup_markup(log, root, styles, dest_dir, detect_cover, XPath):
log.debug('Detected an image that looks like a cover')
img.getparent().remove(img)
return path

View File

@ -7,6 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from collections import namedtuple
from itertools import count
from lxml.etree import tostring
@ -14,14 +15,6 @@ from calibre.ebooks.metadata.toc import TOC
from calibre.ebooks.oeb.polish.toc import elem_to_toc_text
class Count(object):
__slots__ = ('val',)
def __init__(self):
self.val = 0
def from_headings(body, log, namespace):
' Create a TOC from headings in the document '
XPath, descendants = namespace.XPath, namespace.descendants
@ -33,13 +26,12 @@ def from_headings(body, log, namespace):
level_item_map = {i+1:frozenset(xp(body)) for i, xp in enumerate(xpaths)}
item_level_map = {e:i for i, elems in level_item_map.iteritems() for e in elems}
idcount = Count()
idcount = count()
def ensure_id(elem):
ans = elem.get('id', None)
if not ans:
idcount.val += 1
ans = 'toc_id_%d' % idcount.val
ans = 'toc_id_%d' % (next(idcount) + 1)
elem.set('id', ans)
return ans