aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dl/compat.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2017-06-17 23:14:24 +0700
committerSergey M․ <dstftw@gmail.com>2017-06-17 23:14:24 +0700
commitb08e235f09b360262b97ef361a2321839a0534cc (patch)
treef61282ac44e182e60d3053c812669a0710a6301e /youtube_dl/compat.py
parentbe80986ed9175af0a0fb216edfdfaeeb9769d1dd (diff)
downloadyoutube-dl-b08e235f09b360262b97ef361a2321839a0534cc.zip
youtube-dl-b08e235f09b360262b97ef361a2321839a0534cc.tar.gz
youtube-dl-b08e235f09b360262b97ef361a2321839a0534cc.tar.bz2
[compat] Fix compat_shlex_quote on Windows (closes #5889, closes #10254)
Diffstat (limited to 'youtube_dl/compat.py')
-rw-r--r--youtube_dl/compat.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 7ef3274..9e4e13b 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -2617,14 +2617,22 @@ except ImportError: # Python 2
parsed_result[name] = [value]
return parsed_result
-try:
- from shlex import quote as compat_shlex_quote
-except ImportError: # Python < 3.3
+
+compat_os_name = os._name if os.name == 'java' else os.name
+
+
+if compat_os_name == 'nt':
def compat_shlex_quote(s):
- if re.match(r'^[-_\w./]+$', s):
- return s
- else:
- return "'" + s.replace("'", "'\"'\"'") + "'"
+ return s if re.match(r'^[-_\w./]+$', s) else '"%s"' % s.replace('"', '\\"')
+else:
+ try:
+ from shlex import quote as compat_shlex_quote
+ except ImportError: # Python < 3.3
+ def compat_shlex_quote(s):
+ if re.match(r'^[-_\w./]+$', s):
+ return s
+ else:
+ return "'" + s.replace("'", "'\"'\"'") + "'"
try:
@@ -2649,9 +2657,6 @@ def compat_ord(c):
return ord(c)
-compat_os_name = os._name if os.name == 'java' else os.name
-
-
if sys.version_info >= (3, 0):
compat_getenv = os.getenv
compat_expanduser = os.path.expanduser