From 8e697988af494f4cd499911c9a15ee25d6e2a492 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Wed, 27 Feb 2013 15:56:09 -0800 Subject: [PATCH] Changelog + docs re #127 --- NEWS | 2 ++ paramiko/sftp_client.py | 2 +- paramiko/sftp_file.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 10b2bf5..cd98477 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ Releases v1.10.0 (DD MM YYYY) -------------------- +* #127: Turn `SFTPFile` into a context manager. Thanks to Michael Williamson +* for the patch. * #116: Limit `Message.get_bytes` to an upper bound of 1MB to protect against potential DoS vectors. Thanks to `@mvschaik` for catch & patch. * #115: Add convenience `get_pty` kwarg to `Client.exec_command` so users not diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 8cb8cea..7df643f 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -198,7 +198,7 @@ class SFTPClient (BaseSFTP): Open a file on the remote server. The arguments are the same as for python's built-in C{file} (aka C{open}). A file-like object is returned, which closely mimics the behavior of a normal python file - object. + object, including the ability to be used as a context manager. The mode indicates how the file is to be opened: C{'r'} for reading, C{'w'} for writing (truncating an existing file), C{'a'} for appending, diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index c9fc76f..d4ecb89 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -34,6 +34,9 @@ from paramiko.sftp_attr import SFTPAttributes class SFTPFile (BufferedFile): """ Proxy object for a file on the remote server, in client mode SFTP. + + Instances of this class may be used as context managers in the same way + that built-in Python file objects are. """ # Some sftp servers will choke if you send read/write requests larger than