py3 compat

This commit is contained in:
Kovid Goyal 2019-11-24 08:27:54 +05:30
parent 99a478ae88
commit 6272c2b1eb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,11 +7,13 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import re
from calibre.ebooks.oeb.base import XPath, urlunquote
from polyglot.builtins import as_bytes
class DataURL(object):
def __call__(self, oeb, opts):
from calibre.utils.imghdr import what
self.log = oeb.log
attr_path = XPath('//h:img[@src]')
for item in oeb.spine:
@ -35,7 +37,7 @@ class DataURL(object):
continue
else:
data = urlunquote(data)
from imghdr import what
data = as_bytes(data)
fmt = what(None, data)
if not fmt:
self.log.warn('Image encoded as data URL has unknown format, ignoring')