mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
bpo-22454: Add shlex.join() (the opposite of shlex.split()) (GH-7605)
This commit is contained in:
parent
f83d1dbd3b
commit
ca80495592
5 changed files with 48 additions and 1 deletions
|
@ -14,7 +14,7 @@ from collections import deque
|
|||
|
||||
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 @@ def split(s, comments=False, posix=True):
|
|||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue