diff options
author | Red_M <pooatyou.com@gmail.com> | 2018-03-30 12:28:37 +1000 |
---|---|---|
committer | Red_M <pooatyou.com@gmail.com> | 2018-03-30 12:28:37 +1000 |
commit | f98b16f0b58915815c5ac90884f9d7e9631d4fc4 (patch) | |
tree | a7ffe0edca35469b00ac629be8938952a52037ff | |
parent | 4fce2c648d03842b5c775f3109d5cd6602a5034c (diff) | |
download | pexpect-f98b16f0b58915815c5ac90884f9d7e9631d4fc4.tar.gz |
Allow shlex to handle the quotes if running in python 3.
-rw-r--r-- | pexpect/pxssh.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/pexpect/pxssh.py b/pexpect/pxssh.py index 60e3d8c..5f65ac1 100644 --- a/pexpect/pxssh.py +++ b/pexpect/pxssh.py @@ -32,18 +32,21 @@ class ExceptionPxssh(ExceptionPexpect): '''Raised for pxssh exceptions. ''' -_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search - -def quote(s): - """Return a shell-escaped version of the string *s*.""" - if not s: - return "''" - if _find_unsafe(s) is None: - return s - - # use single quotes, and put single quotes into double quotes - # the string $'b is then quoted as '$'"'"'b' - return "'" + s.replace("'", "'\"'\"'") + "'" +if sys.version_info > (3, 0): + from shlex import quote +else: + _find_unsafe = re.compile(r'[^\w@%+=:,./-]').search + + def quote(s): + """Return a shell-escaped version of the string *s*.""" + if not s: + return "''" + if _find_unsafe(s) is None: + return s + + # use single quotes, and put single quotes into double quotes + # the string $'b is then quoted as '$'"'"'b' + return "'" + s.replace("'", "'\"'\"'") + "'" class pxssh (spawn): '''This class extends pexpect.spawn to specialize setting up SSH |