diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-06-17 22:23:04 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-06-17 22:23:04 -0400 |
commit | f1138bb1b6ead7ddeae3e38e3c507d63d09669c3 (patch) | |
tree | e2d0369d88eb7945d5b86ffe2439d96639dc0554 /Lib/mailbox.py | |
parent | c74a6ba2d6c1f331896cf8dacc698b0b88c7e670 (diff) | |
download | cpython-git-f1138bb1b6ead7ddeae3e38e3c507d63d09669c3.tar.gz |
#11700: proxy object close methods can now be called multiple times
This makes them work like the close provided by regular file objects. This
patch also backports the close-the-underlying-file code for _ProxyFile objects
that was introduced along with context manager support in the 3.x branch.
Diffstat (limited to 'Lib/mailbox.py')
-rw-r--r-- | Lib/mailbox.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 9978359633..a9d9c282ea 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1854,7 +1854,10 @@ class _ProxyFile: def close(self): """Close the file.""" - del self._file + if hasattr(self, '_file'): + if hasattr(self._file, 'close'): + self._file.close() + del self._file def _read(self, size, read_method): """Read size bytes using read_method.""" @@ -1898,6 +1901,12 @@ class _PartialFile(_ProxyFile): size = remaining return _ProxyFile._read(self, size, read_method) + def close(self): + # do *not* close the underlying file object for partial files, + # since it's global to the mailbox object + if hasattr(self, '_file'): + del self._file + def _lock_file(f, dotlock=True): """Lock file f using lockf and dot locking.""" |