Support unicode filenames

Python2 encodes commandline parameters based on the default system encoding.
We must explicitly decode this to unicode.
Python3 uses unicode filenames by default, so no action needed.
This commit is contained in:
sneakypete81 2013-12-19 18:52:01 +00:00
parent d6d84f4e0b
commit 76411cb166

View file

@ -123,7 +123,14 @@ def extract_files(params):
updated_params = {} updated_params = {}
for name in params: for name in params:
if name == "photo" and params[name].startswith("@"): if name == "photo" and params[name].startswith("@"):
files[name] = open(os.path.expanduser(params[name][1:]), 'rb') filename = params[name][1:]
# Python2 uses encoded commandline parameters.
# Decode to Unicode if necessary.
if isinstance(filename, bytes):
filename = filename.decode(sys.getfilesystemencoding())
files[name] = open(os.path.expanduser(filename), 'rb')
else: else:
updated_params[name] = params[name] updated_params[name] = params[name]