Fix #7288 (calibre cannot work correctly if the temporary path contain non-ASCII characters)

This commit is contained in:
Kovid Goyal 2010-10-27 11:26:04 -06:00
parent 1043079737
commit 0e23cdd9b6
2 changed files with 4 additions and 5 deletions

View File

@ -25,6 +25,7 @@ from calibre.translations.dynamic import translate
from calibre.ebooks.chardet import xml_to_unicode from calibre.ebooks.chardet import xml_to_unicode
from calibre.ebooks.oeb.entitydefs import ENTITYDEFS from calibre.ebooks.oeb.entitydefs import ENTITYDEFS
from calibre.ebooks.conversion.preprocess import CSSPreProcessor from calibre.ebooks.conversion.preprocess import CSSPreProcessor
from calibre import isbytestring
RECOVER_PARSER = etree.XMLParser(recover=True, no_network=True) RECOVER_PARSER = etree.XMLParser(recover=True, no_network=True)
@ -404,7 +405,8 @@ class DirContainer(object):
def __init__(self, path, log): def __init__(self, path, log):
self.log = log self.log = log
path = unicode(path) if isbytestring(path):
path = path.decode(filesystem_encoding)
ext = os.path.splitext(path)[1].lower() ext = os.path.splitext(path)[1].lower()
if ext == '.opf': if ext == '.opf':
self.opfname = os.path.basename(path) self.opfname = os.path.basename(path)

View File

@ -7,8 +7,7 @@ being closed.
""" """
import tempfile, os, atexit, binascii, cPickle import tempfile, os, atexit, binascii, cPickle
from calibre import __version__, __appname__, isbytestring from calibre.constants import __version__, __appname__
from calibre.constants import filesystem_encoding
def cleanup(path): def cleanup(path):
try: try:
@ -43,8 +42,6 @@ def base_dir():
_base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__, _base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__,
__version__)) __version__))
atexit.register(remove_dir, _base_dir) atexit.register(remove_dir, _base_dir)
if isbytestring(_base_dir):
_base_dir = _base_dir.decode(filesystem_encoding)
return _base_dir return _base_dir
class PersistentTemporaryFile(object): class PersistentTemporaryFile(object):