diff options
author | Robey Pointer <robey@lag.net> | 2005-04-18 00:30:52 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2005-04-18 00:30:52 +0000 |
commit | 89ccac6bfa1e731f287e32b600e0d87d170e0ae7 (patch) | |
tree | f6cc2a26233f32686ecbeedfc3b1f675b47c0744 | |
parent | 29a5381ba17c5c93e7ed5c07a4ece223a8ed0b66 (diff) |
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-163]
add SFTPClient.close()
add SFTPClient.close() and add a simple little unit test for it.
-rw-r--r-- | paramiko/sftp_client.py | 8 | ||||
-rwxr-xr-x | tests/test_sftp.py | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 3beee67d..329667ca 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -74,6 +74,14 @@ class SFTPClient (BaseSFTP): return selfclass(chan) from_transport = classmethod(from_transport) + def close(self): + """ + Close the SFTP session and its underlying channel. + + @since: 1.4 + """ + self.sock.close() + def listdir(self, path): """ Return a list containing the names of the entries in the given C{path}. diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 79a52c25..5d4d921c 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -63,6 +63,7 @@ decreased compared with chicken. FOLDER = os.environ.get('TEST_FOLDER', 'temp-testing') sftp = None +tc = None g_big_file_test = True @@ -101,7 +102,7 @@ class SFTPTest (unittest.TestCase): init = staticmethod(init) def init_loopback(): - global sftp + global sftp, tc socks = LoopSocket() sockc = LoopSocket() @@ -144,6 +145,20 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/test') + def test_1a_close(self): + """ + verify that closing the sftp session doesn't do anything bad, and that + a new one can be opened. + """ + global sftp + sftp.close() + try: + sftp.open(FOLDER + '/test2', 'w') + self.fail('expected exception') + except: + pass + sftp = paramiko.SFTP.from_transport(tc) + def test_2_write(self): """ verify that a file can be created and written, and the size is correct. |