bpo-22454: Add shlex.join() (the opposite of shlex.split()) (GH-7605)
diff --git a/Lib/shlex.py b/Lib/shlex.py
index 2c9786c..fb1130d 100644
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -14,7 +14,7 @@
from io import StringIO
-__all__ = ["shlex", "split", "quote"]
+__all__ = ["shlex", "split", "quote", "join"]
class shlex:
"A lexical analyzer class for simple shell-like syntaxes."
@@ -305,6 +305,11 @@
return list(lex)
+def join(split_command):
+ """Return a shell-escaped string from *split_command*."""
+ return ' '.join(quote(arg) for arg in split_command)
+
+
_find_unsafe = re.compile(r'[^\w@%+=:,./-]', re.ASCII).search
def quote(s):