Steffen Daode Nurpmeso <sdao...@googlemail.com> added the comment:
Here's the patch.
----------
keywords: +patch
Added file: http://bugs.python.org/file21438/11700.1.diff
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11700>
_______________________________________
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -382,7 +382,7 @@
def get_file(self, key):
"""Return a file-like representation or raise a KeyError."""
f = open(os.path.join(self._path, self._lookup(key)), 'rb')
- return _ProxyFile(f)
+ return _ProxyFile(f, close=True)
def iterkeys(self):
"""Return an iterator over keys."""
@@ -1032,7 +1032,7 @@
raise KeyError('No message with key: %s' % key)
else:
raise
- return _ProxyFile(f)
+ return _ProxyFile(f, close=True)
def iterkeys(self):
"""Return an iterator over keys."""
@@ -1867,13 +1867,15 @@
class _ProxyFile:
"""A read-only wrapper of a file."""
- def __init__(self, f, pos=None):
+ def __init__(self, f, pos=None, close=False):
"""Initialize a _ProxyFile."""
self._file = f
if pos is None:
self._pos = f.tell()
else:
self._pos = pos
+ self._do_close = close
+ self._is_open = True
def read(self, size=None):
"""Read bytes."""
@@ -1919,9 +1921,11 @@
def close(self):
"""Close the file."""
- if hasattr(self._file, 'close'):
+ if self._do_close:
+ self._do_close = False
self._file.close()
- del self._file
+ del self._file
+ self._is_open = False
def _read(self, size, read_method):
"""Read size bytes using read_method."""
@@ -1953,7 +1957,7 @@
@property
def closed(self):
- return self._file.closed
+ return not self._is_open
class _PartialFile(_ProxyFile):
@@ -1988,11 +1992,6 @@
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
- del self._file
-
def _lock_file(f, dotlock=True):
"""Lock file f using lockf and dot locking."""
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com