diff Lib/mailbox.py @ 70857:8319db2dd342 3.2

#11700: proxy object close methods can now be called multiple times This makes them work like the close provided by regular file objects.
author R David Murray <rdmurray@bitdance.com>
date Fri, 17 Jun 2011 22:24:05 -0400
parents fea1920ae75f
children 5f27a9f67a34 5ea81e4c58a7
line wrap: on
line diff
--- a/Lib/mailbox.py	Fri Jun 17 12:54:56 2011 -0400
+++ b/Lib/mailbox.py	Fri Jun 17 22:24:05 2011 -0400
@@ -1923,9 +1923,10 @@
 
     def close(self):
         """Close the file."""
-        if hasattr(self._file, 'close'):
-            self._file.close()
-        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."""
@@ -1957,6 +1958,10 @@
 
     @property
     def closed(self):
+        if not hasattr(self, '_file'):
+            return True
+        if not hasattr(self._file, 'closed'):
+            return False
         return self._file.closed
 
 
@@ -1995,7 +2000,8 @@
     def close(self):
         # do *not* close the underlying file object for partial files,
         # since it's global to the mailbox object
-        del self._file
+        if hasattr(self, '_file'):
+            del self._file
 
 
 def _lock_file(f, dotlock=True):