mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Zip file handling: Try to correctly interpret files with non english characters in their file names inside the zip file
This commit is contained in:
parent
b33bfe2e43
commit
5cc4caf147
@ -120,7 +120,10 @@ class EbookIterator(object):
|
|||||||
bad_map = {}
|
bad_map = {}
|
||||||
font_family_pat = re.compile(r'font-family\s*:\s*([^;]+)')
|
font_family_pat = re.compile(r'font-family\s*:\s*([^;]+)')
|
||||||
for csspath in css_files:
|
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):
|
for match in re.compile(r'@font-face\s*{([^}]+)}').finditer(css):
|
||||||
block = match.group(1)
|
block = match.group(1)
|
||||||
family = font_family_pat.search(block)
|
family = font_family_pat.search(block)
|
||||||
|
@ -5,6 +5,7 @@ a zip archive.
|
|||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre import sanitize_file_name
|
from calibre import sanitize_file_name
|
||||||
|
from calibre.constants import filesystem_encoding
|
||||||
import struct, os, time, sys, shutil
|
import struct, os, time, sys, shutil
|
||||||
import binascii, cStringIO
|
import binascii, cStringIO
|
||||||
|
|
||||||
@ -1030,6 +1031,15 @@ class ZipFile:
|
|||||||
targetpath = os.path.join(targetpath, member.filename)
|
targetpath = os.path.join(targetpath, member.filename)
|
||||||
|
|
||||||
targetpath = os.path.normpath(targetpath)
|
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.
|
# Create all upper directories if necessary.
|
||||||
upperdirs = os.path.dirname(targetpath)
|
upperdirs = os.path.dirname(targetpath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user