From 7e63bc95e2f277a31be70ff5356e44ae85e1575f Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Mon, 19 Jan 2009 15:03:50 -0500 Subject: [PATCH 1/2] Fix #1649: - Handle empty XML files while manifest trimming - Ignore s with non OPS raster image @src --- src/calibre/ebooks/mobi/writer.py | 3 +-- src/calibre/ebooks/oeb/transforms/trimmanifest.py | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 62d444ee95..d9f3a841ab 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -180,7 +180,6 @@ class Serializer(object): if not isinstance(elem.tag, basestring) \ or namespace(elem.tag) not in nsrmap: return - hrefs = self.oeb.manifest.hrefs tag = prefixname(elem.tag, nsrmap) for attr in ('name', 'id'): if attr in elem.attrib: @@ -203,7 +202,7 @@ class Serializer(object): continue elif attr == 'src': href = item.abshref(val) - if href in hrefs: + if href in self.images: index = self.images[href] buffer.write('recindex="%05d"' % index) continue diff --git a/src/calibre/ebooks/oeb/transforms/trimmanifest.py b/src/calibre/ebooks/oeb/transforms/trimmanifest.py index bd2c388245..b150a12831 100644 --- a/src/calibre/ebooks/oeb/transforms/trimmanifest.py +++ b/src/calibre/ebooks/oeb/transforms/trimmanifest.py @@ -41,8 +41,9 @@ class ManifestTrimmer(object): while unchecked: new = set() for item in unchecked: - if item.media_type in OEB_DOCS or \ - item.media_type[-4:] in ('/xml', '+xml'): + if (item.media_type in OEB_DOCS or + item.media_type[-4:] in ('/xml', '+xml')) and \ + item.data is not None: hrefs = [sel(item.data) for sel in LINK_SELECTORS] for href in chain(*hrefs): href = item.abshref(href) From 50d041712986148de67d4101caa4392dfecdacf8 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Mon, 19 Jan 2009 15:13:31 -0500 Subject: [PATCH 2/2] Fix #1650: - Handle a //guide/reference[@cover] which specifies the raster image cover directly --- src/calibre/ebooks/mobi/mobiml.py | 9 ++++++--- src/calibre/ebooks/oeb/base.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index 7a74bd9401..720bb3df8f 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -12,7 +12,7 @@ import copy import re from lxml import etree from calibre.ebooks.oeb.base import namespace, barename -from calibre.ebooks.oeb.base import XHTML, XHTML_NS +from calibre.ebooks.oeb.base import XHTML, XHTML_NS, OEB_DOCS from calibre.ebooks.oeb.stylizer import Stylizer from calibre.ebooks.oeb.transforms.flatcss import KeyMapper @@ -96,8 +96,11 @@ class MobiMLizer(object): href = oeb.guide['cover'].href del oeb.guide['cover'] item = oeb.manifest.hrefs[href] - oeb.manifest.remove(item) - + if item.spine_position is not None: + oeb.spine.remove(item) + if item.media_type in OEB_DOCS: + self.oeb.manifest.remove(item) + def mobimlize_spine(self): for item in self.oeb.spine: stylizer = Stylizer(item.data, item.href, self.oeb, self.profile) diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 4248657e23..892d7c507e 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -506,6 +506,7 @@ class Spine(object): self.items.pop(index) for i in xrange(index, len(self.items)): self.items[i].spine_position = i + item.spine_position = None def __iter__(self): for item in self.items: