From d96ad4bfe5d4ce98663f010695700cfe5ef392ed Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Jun 2009 13:01:55 -0700 Subject: [PATCH] Fix #2613 (ValueError: max() arg is an empty sequence) --- src/calibre/ebooks/oeb/base.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 4410b762b6..3ece412013 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -321,6 +321,27 @@ def urlnormalize(href): parts = (urlquote(part) for part in parts) return urlunparse(parts) +def merge_multiple_html_heads_and_bodies(root, log=None): + heads, bodies = xpath(root, '//h:head'), xpath(root, '//h:body') + if not (len(heads) > 1 or len(bodies) > 1): return root + for child in root: root.remove(child) + head = root.makeelement(XHTML('head')) + body = root.makeelement(XHTML('body')) + for h in heads: + for x in h: + head.append(x) + for b in bodies: + for x in b: + body.append(x) + map(root.append, (head, body)) + if log is not None: + log.warn('Merging multiple and sections') + return root + + + + + class DummyHandler(logging.Handler): def __init__(self): @@ -786,6 +807,8 @@ class Manifest(object): for elem in data: nroot.append(elem) data = nroot + + data = merge_multiple_html_heads_and_bodies(data, self.oeb.logger) # Ensure has a head = xpath(data, '/h:html/h:head') head = head[0] if head else None