From d61d164a94816827d7a72ef328afa3f07db00dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 10 Oct 2017 10:49:43 +0200 Subject: [PATCH] Decode path with file system encoding if it is not a unicode The environment variable APPDATA and sys.executable on windows are bytes under Python2 and strings under Python3. issue5810 review38851002 --- tryton/config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tryton/config.py b/tryton/config.py index d1e701db9a..4dab67bbd4 100644 --- a/tryton/config.py +++ b/tryton/config.py @@ -18,7 +18,10 @@ _ = gettext.gettext def get_config_dir(): if os.name == 'nt': - return os.path.join(os.environ['APPDATA'], '.config', 'tryton', + appdata = os.environ['APPDATA'] + if not isinstance(appdata, unicode): + appdata = unicode(appdata, sys.getfilesystemencoding()) + return os.path.join(appdata, '.config', 'tryton', __version__.rsplit('.', 1)[0]) return os.path.join(os.environ['HOME'], '.config', 'tryton', __version__.rsplit('.', 1)[0]) @@ -156,11 +159,11 @@ class ConfigManager(object): self.defaults.get(key))) CONFIG = ConfigManager() -CURRENT_DIR = unicode(os.path.dirname(__file__), - sys.getfilesystemencoding()) +CURRENT_DIR = os.path.dirname(__file__) if hasattr(sys, 'frozen'): - CURRENT_DIR = os.path.dirname(unicode(sys.executable, - sys.getfilesystemencoding())) + CURRENT_DIR = sys.executable +if not isinstance(CURRENT_DIR, unicode): + CURRENT_DIR = unicode(CURRENT_DIR, sys.getfilesystemencoding()) PIXMAPS_DIR = os.path.join(CURRENT_DIR, 'data', 'pixmaps', 'tryton') if not os.path.isdir(PIXMAPS_DIR):