mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 15:33:15 +01:00
Standardize on Python's fsencode for arguments
This can apparently never be `None`, as of Python 3.2.
This commit is contained in:
parent
82d41446a2
commit
086bab55b1
1 changed files with 5 additions and 10 deletions
|
|
@ -17,7 +17,6 @@
|
|||
import os
|
||||
import sys
|
||||
import errno
|
||||
import locale
|
||||
import re
|
||||
import tempfile
|
||||
import shutil
|
||||
|
|
@ -332,12 +331,7 @@ def arg_encoding():
|
|||
"""Get the encoding for command-line arguments (and other OS
|
||||
locale-sensitive strings).
|
||||
"""
|
||||
try:
|
||||
return locale.getdefaultlocale()[1] or 'utf-8'
|
||||
except ValueError:
|
||||
# Invalid locale environment variable setting. To avoid
|
||||
# failing entirely for no good reason, assume UTF-8.
|
||||
return 'utf-8'
|
||||
return sys.getfilesystemencoding()
|
||||
|
||||
|
||||
def _fsencoding():
|
||||
|
|
@ -837,13 +831,14 @@ def cpu_count():
|
|||
|
||||
|
||||
def convert_command_args(args):
|
||||
"""Convert command arguments to bytestrings on Python 2 and
|
||||
surrogate-escaped strings on Python 3."""
|
||||
"""Convert command arguments, which may either be `bytes` or `str`
|
||||
objects, to uniformly surrogate-escaped strings.
|
||||
"""
|
||||
assert isinstance(args, list)
|
||||
|
||||
def convert(arg):
|
||||
if isinstance(arg, bytes):
|
||||
arg = arg.decode(arg_encoding(), 'surrogateescape')
|
||||
return os.fsdecode(arg)
|
||||
return arg
|
||||
|
||||
return [convert(a) for a in args]
|
||||
|
|
|
|||
Loading…
Reference in a new issue