This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: zipfile - add __exit__ attribute to make ZipFile object compatible with with_statement
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: brian.curtin, ezio.melotti, petruchio
Priority: normal Keywords: patch

Created on 2009-03-18 18:24 by petruchio, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue5511_complete.patch brian.curtin, 2009-07-26 00:27 code, test, and doc changes
issue5511_complete_20091008.patch brian.curtin, 2009-10-08 14:29 Added close tests per Ezio's suggestion
Messages (7)
msg83768 - (view) Author: J.R. Allen (petruchio) Date: 2009-03-18 18:24
Currently the zipfile.ZipFile class has no __exit__ atribute, so it 
does not work with a with statement as other file objects do.  Can this 
be implemented?
msg90869 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-07-24 03:12
Submitted a patch against trunk. Let me know if you need anything else
(doc patch?).
msg90870 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-07-24 06:18
It would be nice if you could provide unit tests.
If you can also provide a patch for the doc, it's even better.
msg90932 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-07-26 00:27
Attached is a patch containing the fix, the updated tests, and the doc
change. Let me know if you have any questions, suggestions, etc.
msg92554 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-09-12 21:52
I think there should also be one or more tests that check if the file is
closed correctly after the __exit__, in normal conditions and possibly
in different situations (e.g. when an error is raised ).
Unlike regular file objects, ZipFile objects don't have a 'closed'
attribute, instead they set self.fp to None when the 'close' method is
called.
msg93746 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-10-08 14:29
Added two tests -- test_close and test_close_on_exception, which check
if fp is None after __exit__ from a normal and exception case.
msg97030 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-12-30 13:55
Done in r77136 (trunk) and r77142 (py3k). Thanks for the patch!
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49761
2009-12-30 13:55:28ezio.melottisetstatus: open -> closed
versions: + Python 3.2, - Python 3.1
messages: + msg97030

resolution: accepted -> fixed
stage: test needed -> resolved
2009-10-08 14:29:25brian.curtinsetfiles: + issue5511_complete_20091008.patch
keywords: + patch
messages: + msg93746
2009-10-08 08:48:34ezio.melottisetkeywords: - patch, needs review
2009-09-12 21:52:58ezio.melottisetresolution: accepted
messages: + msg92554
2009-07-26 00:27:35brian.curtinsetfiles: - zipfile_issue_5511.patch
2009-07-26 00:27:23brian.curtinsetfiles: + issue5511_complete.patch

messages: + msg90932
2009-07-25 17:36:58gregory.p.smithsetassignee: ezio.melotti
2009-07-24 06:18:28ezio.melottisetpriority: normal

nosy: + ezio.melotti
messages: + msg90870

keywords: + needs review
stage: needs patch -> test needed
2009-07-24 03:12:06brian.curtinsetfiles: + zipfile_issue_5511.patch

nosy: + brian.curtin
messages: + msg90869

keywords: + patch
2009-03-18 18:29:52benjamin.petersonsetstage: needs patch
versions: + Python 3.1, Python 2.7, - Python 2.6
2009-03-18 18:24:22petruchiocreate