diff --git a/src/calibre/ebooks/oeb/iterator.py b/src/calibre/ebooks/oeb/iterator.py index 372baf0959..8f8668b215 100644 --- a/src/calibre/ebooks/oeb/iterator.py +++ b/src/calibre/ebooks/oeb/iterator.py @@ -120,7 +120,10 @@ class EbookIterator(object): bad_map = {} font_family_pat = re.compile(r'font-family\s*:\s*([^;]+)') for csspath in css_files: - css = open(csspath, 'rb').read().decode('utf-8', 'replace') + try: + css = open(csspath, 'rb').read().decode('utf-8', 'replace') + except: + continue for match in re.compile(r'@font-face\s*{([^}]+)}').finditer(css): block = match.group(1) family = font_family_pat.search(block) diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index 508d9fd319..352e95daff 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -5,6 +5,7 @@ a zip archive. from __future__ import with_statement from calibre.ptempfile import TemporaryDirectory from calibre import sanitize_file_name +from calibre.constants import filesystem_encoding import struct, os, time, sys, shutil import binascii, cStringIO @@ -1030,6 +1031,15 @@ class ZipFile: targetpath = os.path.join(targetpath, member.filename) targetpath = os.path.normpath(targetpath) + if not isinstance(targetpath, unicode): + try: + targetpath = targetpath.decode('utf-8') + except: + try: + targetpath = targetpath.decode('cp437') + except: + targetpath = targetpath.decode('utf-8', 'replace') + targetpath = targetpath.encode(filesystem_encoding) # Create all upper directories if necessary. upperdirs = os.path.dirname(targetpath)