paramiko/paramiko — pull request #334 by tokibito (2014-05-24 03:45:22+00:00)
Title: Fixes to work on Google App Engine

This PR resolves some problems when using GoogleAppEngine Sockets API.

1: Subprocess module doesn't work on Google App Engine.

```
Traceback (most recent call last):
File "/home/tokibito/src/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/tokibito/src/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/tokibito/src/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
File "/home/tokibito/sandbox/gae-paramiko/main.py", line 2, in
import paramiko
File "/home/tokibito/sandbox/gae-paramiko/lib/paramiko/__init__.py", line 56, in
from paramiko.proxy import ProxyCommand
File "/home/tokibito/sandbox/gae-paramiko/lib/paramiko/proxy.py", line 24, in
from subprocess import Popen, PIPE
```

2: It is raises the socket error if the active check timeout is too short.

```
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/apps/s~nullpobug-sandbox-hrd/ssh.376051288567321218/main.py", line 9, in app
client.connect('test.nullpobug.com', username='spam', key_filename=os.path.join(base_dir, 'secret.key'))
File "/base/data/home/apps/s~nullpobug-sandbox-hrd/ssh.376051288567321218/lib/paramiko/client.py", line 242, in connect
t.start_client()
File "/base/data/home/apps/s~nullpobug-sandbox-hrd/ssh.376051288567321218/lib/paramiko/transport.py", line 346, in start_client
raise e
SSHException: Error reading SSH protocol banner[Errno 11] Resource temporarily unavailable
```

Such code works on Google App Engine with this patch.

```
import os
import paramiko
import paramiko.transport

def app(environ, start_response):
base_dir = os.path.dirname(os.path.abspath(__file__))
paramiko.transport.Transport._active_check_timeout = 5
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('test.nullpobug.com', username='spam', key_filename=os.path.join(base_dir, 'secret.key'))
stdin, stdout, stderr = client.exec_command('uname -a')

start_response('200 OK', [('Content-type', 'text/plain')])
return stdout.read()
```