From 2730aa9ad6810d3eb12c68a79a01366684a3ce6c Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 30 Jun 2017 14:30:54 -0400 Subject: [PATCH] make sure window paths of directories are in string not unicode --- lbrynet/conf.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 6a960d11f..8efeaa87e 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -43,6 +43,21 @@ settings_encoders = { '.yml': yaml.safe_dump } +def _win_path_to_bytes(path): + """ + Encode Windows paths to string. appdirs.user_data_dir() + on windows will return unicode path, unlike other platforms + which returns string. This will cause problems + because we use strings for filenames and combining them with + os.path.join() will result in errors. + """ + for encoding in ('ASCII', 'MBCS'): + try: + return path.encode(encoding) + except (UnicodeEncodeError, LookupError): + pass + return path + if sys.platform.startswith('darwin'): platform = DARWIN default_download_directory = os.path.join(os.path.expanduser('~'), 'Downloads') @@ -57,6 +72,10 @@ elif sys.platform.startswith('win'): get_path(FOLDERID.RoamingAppData, UserHandle.current), 'lbrynet') default_lbryum_dir = os.path.join( get_path(FOLDERID.RoamingAppData, UserHandle.current), 'lbryum') + + default_download_directory = _win_path_to_bytes(default_download_directory) + default_data_dir = _win_path_to_bytes(default_data_dir) + default_lbryum_dir = _win_path_to_bytes(default_lbryum_dir) else: platform = LINUX default_download_directory = os.path.join(os.path.expanduser('~'), 'Downloads')