diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2019-07-05 15:47:00 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2019-07-05 20:18:05 -0400 |
commit | 12c019db9a3b45c8af6d2261d507177d0427fe0f (patch) | |
tree | 5aa27b954a5829e2c1ff57022188f278489c16bb /paramiko/proxy.py | |
parent | ccf48a12f35db3c4becbb4b2e695a445da983f24 (diff) | |
download | paramiko-12c019db9a3b45c8af6d2261d507177d0427fe0f.tar.gz |
Actually test ProxyCommand as currently implemented
Including shuffling around the imports therein so they can actually be
mocked, without losing the property of "can be imported under GAE".
Diffstat (limited to 'paramiko/proxy.py')
-rw-r--r-- | paramiko/proxy.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/paramiko/proxy.py b/paramiko/proxy.py index 444c47b6..61591b81 100644 --- a/paramiko/proxy.py +++ b/paramiko/proxy.py @@ -18,12 +18,20 @@ import os -from shlex import split as shlsplit +import shlex import signal from select import select import socket import time +# Try-and-ignore import so platforms w/o subprocess (eg Google App Engine) can +# still import paramiko. +subprocess, subprocess_import_error = None, None +try: + import subprocess +except ImportError as e: + pass + from paramiko.ssh_exception import ProxyCommandFailure from paramiko.util import ClosingContextManager @@ -48,13 +56,12 @@ class ProxyCommand(ClosingContextManager): :param str command_line: the command that should be executed and used as the proxy. """ - # NOTE: subprocess import done lazily so platforms without it (e.g. - # GAE) can still import us during overall Paramiko load. - from subprocess import Popen, PIPE - - self.cmd = shlsplit(command_line) - self.process = Popen( - self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=0 + if subprocess is None: + raise subprocess_import_error + self.cmd = shlex.split(command_line) + self.process = subprocess.Popen( + self.cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, bufsize=0 ) self.timeout = None |