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:
parent
d6d84f4e0b
commit
76411cb166
1 changed files with 8 additions and 1 deletions
|
@ -123,7 +123,14 @@ def extract_files(params):
|
|||
updated_params = {}
|
||||
for name in params:
|
||||
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:
|
||||
updated_params[name] = params[name]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue