From 2f2388fc2c82a5eea58bc588896eda2b3eceb475 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 30 Jan 2018 21:52:31 -0500 Subject: [PATCH] py3: Use import argument paths as bytestrings --- beets/ui/commands.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 3a1811cf3..5628c8bc1 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -934,6 +934,13 @@ def import_func(lib, opts, args): if not paths: raise ui.UserError(u'no path specified') + # On Python 2, we get filenames as raw bytes, which is what we + # need. On Python 3, we need to undo the "helpful" conversion to + # Unicode strings to get the real bytestring filename. + if not six.PY2: + paths = [p.encode(util.arg_encoding(), 'surrogateescape') + for p in paths] + import_files(lib, paths, query)