diff options
author | Robey Pointer <robey@master-shake.local> | 2006-02-05 22:42:28 -0800 |
---|---|---|
committer | Robey Pointer <robey@master-shake.local> | 2006-02-05 22:42:28 -0800 |
commit | 619192814d18dffbcde159b5431db4e044fdb8ba (patch) | |
tree | 9885b117f139bf91ba827607394c9bf9817a13a6 | |
parent | 2853a7ae0548cf898f0acebe3e7df7ceb92a0025 (diff) |
[project @ robey@master-shake.local-20060206064228-23198d2e82bd7248]
add getpeername() call to make asyncore work better
-rw-r--r-- | paramiko/channel.py | 12 | ||||
-rw-r--r-- | paramiko/transport.py | 15 |
2 files changed, 27 insertions, 0 deletions
diff --git a/paramiko/channel.py b/paramiko/channel.py index 9d2f76b9..6eca4bc3 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -433,6 +433,18 @@ class Channel (object): else: self.settimeout(0.0) + def getpeername(self): + """ + Return the address of the remote side of this Channel, if possible. + This is just a wrapper around C{'getpeername'} on the Transport, used + to provide enough of a socket-like interface to allow asyncore to work. + (asyncore likes to call C{'getpeername'}.) + + @return: the address if the remote host, if known + @rtype: tuple(str, int) + """ + return self.transport.getpeername() + def close(self): """ Close the channel. All future read/write operations on the channel diff --git a/paramiko/transport.py b/paramiko/transport.py index d646b5a4..e65f61f0 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1210,6 +1210,21 @@ class Transport (threading.Thread): self._preferred_compression = ( 'zlib@openssh.com', 'zlib', 'none' ) else: self._preferred_compression = ( 'none', ) + + def getpeername(self): + """ + Return the address of the remote side of this Transport, if possible. + This is effectively a wrapper around C{'getpeername'} on the underlying + socket. If the socket-like object has no C{'getpeername'} method, + then C{("unknown", 0)} is returned. + + @return: the address if the remote host, if known + @rtype: tuple(str, int) + """ + gp = getattr(self.sock, 'getpeername', None) + if gp is None: + return ('unknown', 0) + return gp() def stop_thread(self): self.active = False |