Skip to content

Commit 76411cb

Browse files
committed
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.
1 parent d6d84f4 commit 76411cb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

trovebox/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ def extract_files(params):
123123
updated_params = {}
124124
for name in params:
125125
if name == "photo" and params[name].startswith("@"):
126-
files[name] = open(os.path.expanduser(params[name][1:]), 'rb')
126+
filename = params[name][1:]
127+
128+
# Python2 uses encoded commandline parameters.
129+
# Decode to Unicode if necessary.
130+
if isinstance(filename, bytes):
131+
filename = filename.decode(sys.getfilesystemencoding())
132+
133+
files[name] = open(os.path.expanduser(filename), 'rb')
127134
else:
128135
updated_params[name] = params[name]
129136

0 commit comments

Comments
 (0)