diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index c536006912..9ec154dec6 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1024,8 +1024,8 @@ class Manifest(object): - XML content is parsed and returned as an lxml.etree element. - CSS and CSS-variant content is parsed and returned as a css_parser CSS DOM stylesheet. - - All other content is returned as a :class:`str` object with no - special parsing. + - All other content is returned as a :class:`str` or :class:`bytes` + object with no special parsing. """ data = self._data if data is None: diff --git a/src/calibre/ebooks/oeb/transforms/rasterize.py b/src/calibre/ebooks/oeb/transforms/rasterize.py index 35a96df60f..83651b23e5 100644 --- a/src/calibre/ebooks/oeb/transforms/rasterize.py +++ b/src/calibre/ebooks/oeb/transforms/rasterize.py @@ -1,7 +1,7 @@ ''' SVG rasterization transform. ''' -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2008, Marshall T. Vandegrift ' @@ -77,7 +77,7 @@ class SVGRasterizer(object): logger.info('Found SVG image height in %, trying to convert...') try: h = float(image.get('height').replace('%', ''))/100. - image.set('height', str(h*sizes[1])) + image.set('height', unicode_type(h*sizes[1])) except: logger.exception('Failed to convert percentage height:', image.get('height')) @@ -101,7 +101,7 @@ class SVGRasterizer(object): buffer = QBuffer(array) buffer.open(QIODevice.WriteOnly) image.save(buffer, format) - return str(array) + return array.data() def dataize_manifest(self): for item in self.oeb.manifest.values(): @@ -121,10 +121,10 @@ class SVGRasterizer(object): if abshref not in hrefs: continue linkee = hrefs[abshref] - data = str(linkee) + data = unicode_type(linkee) ext = what(None, data) or 'jpg' with PersistentTemporaryFile(suffix='.'+ext) as pt: - pt.write(data) + pt.write(data.encode('utf-8')) self.temp_files.append(pt.name) elem.attrib[XLINK('href')] = pt.name return svg @@ -182,7 +182,7 @@ class SVGRasterizer(object): height = style['height'] width = (width / 72) * self.profile.dpi height = (height / 72) * self.profile.dpi - data = QByteArray(str(svgitem)) + data = QByteArray(unicode_type(svgitem).encode('utf-8')) svg = QSvgRenderer(data) size = svg.defaultSize() size.scale(width, height, Qt.KeepAspectRatio) @@ -202,7 +202,7 @@ class SVGRasterizer(object): buffer = QBuffer(array) buffer.open(QIODevice.WriteOnly) image.save(buffer, 'PNG') - data = str(array) + data = array.data() manifest = self.oeb.manifest href = os.path.splitext(svgitem.href)[0] + '.png' id, href = manifest.generate(svgitem.id, href)