mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8 and code simplification
This commit is contained in:
parent
05b97d86e0
commit
f8a2449d7f
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user