mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Sf bug [ #412214 ] ZipFile constructor leaves files open.
This applies the patch Fred Drake created to fix it. I'm checking it in since I had to apply the patch anyway in order to test its behavior on Windows.
This commit is contained in:
parent
42fc7ccdac
commit
7d3bad66e4
2 changed files with 30 additions and 0 deletions
|
@ -186,9 +186,23 @@ class ZipFile:
|
|||
else: # file is not a zip file, just append
|
||||
fp.seek(0, 2)
|
||||
else:
|
||||
if not self._filePassed:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
raise RuntimeError, 'Mode must be "r", "w" or "a"'
|
||||
|
||||
def _GetContents(self):
|
||||
"""Read the directory, making sure we close the file if the format
|
||||
is bad."""
|
||||
try:
|
||||
self._RealGetContents()
|
||||
except BadZipfile:
|
||||
if not self._filePassed:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
raise
|
||||
|
||||
def _RealGetContents(self):
|
||||
"""Read in the table of contents for the ZIP file."""
|
||||
fp = self.fp
|
||||
fp.seek(-22, 2) # Start of end-of-archive record
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue