diff options
Diffstat (limited to 'paramiko/sftp_file.py')
-rw-r--r-- | paramiko/sftp_file.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index 8c5c7aca..d4ecb89f 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 @@ -474,3 +477,9 @@ class SFTPFile (BufferedFile): x = self._saved_exception self._saved_exception = None raise x + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() |