From 705bf8a811e2ea084fedfcfb72f7da790e6796f9 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Tue, 27 Jan 2009 20:36:10 -0500 Subject: [PATCH] Normalize URIs in a few more places where it might matter. --- src/calibre/ebooks/mobi/writer.py | 3 ++- src/calibre/ebooks/oeb/transforms/rasterize.py | 15 ++++++++------- src/calibre/ebooks/oeb/transforms/trimmanifest.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 3c5a39ebd2..92ecdf1a46 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -23,6 +23,7 @@ from PIL import Image from calibre.ebooks.oeb.base import XML_NS, XHTML, XHTML_NS, OEB_DOCS, \ OEB_RASTER_IMAGES from calibre.ebooks.oeb.base import xpath, barename, namespace, prefixname +from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.oeb.base import Logger, OEBBook from calibre.ebooks.oeb.profile import Context from calibre.ebooks.oeb.transforms.flatcss import CSSFlattener @@ -178,7 +179,7 @@ class Serializer(object): def serialize_href(self, href, base=None): hrefs = self.oeb.manifest.hrefs - path, frag = urldefrag(href) + path, frag = urldefrag(urlnormalize(href)) if path and base: path = base.abshref(path) if path and path not in hrefs: diff --git a/src/calibre/ebooks/oeb/transforms/rasterize.py b/src/calibre/ebooks/oeb/transforms/rasterize.py index 97d73d3dcb..12a2812898 100644 --- a/src/calibre/ebooks/oeb/transforms/rasterize.py +++ b/src/calibre/ebooks/oeb/transforms/rasterize.py @@ -23,6 +23,7 @@ from PyQt4.QtGui import QApplication from calibre.ebooks.oeb.base import XHTML_NS, XHTML, SVG_NS, SVG, XLINK from calibre.ebooks.oeb.base import SVG_MIME, PNG_MIME, JPEG_MIME from calibre.ebooks.oeb.base import xml2str, xpath, namespace, barename +from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.oeb.stylizer import Stylizer IMAGE_TAGS = set([XHTML('img'), XHTML('object')]) @@ -78,7 +79,7 @@ class SVGRasterizer(object): svg = item.data hrefs = self.oeb.manifest.hrefs for elem in xpath(svg, '//svg:*[@xl:href]'): - href = elem.attrib[XLINK('href')] + href = urlnormalize(elem.attrib[XLINK('href')]) path, frag = urldefrag(href) if not path: continue @@ -100,15 +101,15 @@ class SVGRasterizer(object): def rasterize_item(self, item, stylizer): html = item.data hrefs = self.oeb.manifest.hrefs - for elem in xpath(html, '//h:img'): - src = elem.get('src', None) - image = hrefs.get(item.abshref(src), None) if src else None + for elem in xpath(html, '//h:img[@src]'): + src = urlnormalize(elem.attrib['src']) + image = hrefs.get(item.abshref(src), None) if image and image.media_type == SVG_MIME: style = stylizer.style(elem) self.rasterize_external(elem, style, item, image) - for elem in xpath(html, '//h:object[@type="%s"]' % SVG_MIME): - data = elem.get('data', None) - image = hrefs.get(item.abshref(data), None) if data else None + for elem in xpath(html, '//h:object[@type="%s" and @data]' % SVG_MIME): + data = urlnormalize(elem.attrib['data']) + image = hrefs.get(item.abshref(data), None) if image and image.media_type == SVG_MIME: style = stylizer.style(elem) self.rasterize_external(elem, style, item, image) diff --git a/src/calibre/ebooks/oeb/transforms/trimmanifest.py b/src/calibre/ebooks/oeb/transforms/trimmanifest.py index bc95b43343..643952c03d 100644 --- a/src/calibre/ebooks/oeb/transforms/trimmanifest.py +++ b/src/calibre/ebooks/oeb/transforms/trimmanifest.py @@ -54,7 +54,7 @@ class ManifestTrimmer(object): new.add(found) elif item.media_type == CSS_MIME: def replacer(uri): - absuri = item.abshref(uri) + absuri = item.abshref(urlnormalize(uri)) if absuri in oeb.manifest.hrefs: found = oeb.manifest.hrefs[href] if found not in used: