mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ZIP file extraction: Try to detect file name encoding instead of assuming UTF-8
This commit is contained in:
parent
5cc4caf147
commit
71bb26c827
@ -6,6 +6,7 @@ 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
|
from calibre.constants import filesystem_encoding
|
||||||
|
from calibre.ebooks.chardet import detect
|
||||||
import struct, os, time, sys, shutil
|
import struct, os, time, sys, shutil
|
||||||
import binascii, cStringIO
|
import binascii, cStringIO
|
||||||
|
|
||||||
@ -1032,13 +1033,11 @@ class ZipFile:
|
|||||||
|
|
||||||
targetpath = os.path.normpath(targetpath)
|
targetpath = os.path.normpath(targetpath)
|
||||||
if not isinstance(targetpath, unicode):
|
if not isinstance(targetpath, unicode):
|
||||||
|
encoding = detect(targetpath)['encoding']
|
||||||
try:
|
try:
|
||||||
targetpath = targetpath.decode('utf-8')
|
targetpath = targetpath.decode(encoding)
|
||||||
except:
|
except:
|
||||||
try:
|
targetpath = targetpath.decode('utf-8', 'replace')
|
||||||
targetpath = targetpath.decode('cp437')
|
|
||||||
except:
|
|
||||||
targetpath = targetpath.decode('utf-8', 'replace')
|
|
||||||
targetpath = targetpath.encode(filesystem_encoding)
|
targetpath = targetpath.encode(filesystem_encoding)
|
||||||
|
|
||||||
# Create all upper directories if necessary.
|
# Create all upper directories if necessary.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user