summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRed_M <pooatyou.com@gmail.com>2018-03-30 12:28:37 +1000
committerRed_M <pooatyou.com@gmail.com>2018-03-30 12:28:37 +1000
commitf98b16f0b58915815c5ac90884f9d7e9631d4fc4 (patch)
treea7ffe0edca35469b00ac629be8938952a52037ff
parent4fce2c648d03842b5c775f3109d5cd6602a5034c (diff)
downloadpexpect-f98b16f0b58915815c5ac90884f9d7e9631d4fc4.tar.gz
Allow shlex to handle the quotes if running in python 3.
-rw-r--r--pexpect/pxssh.py27
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