Issue 5511: zipfile - add exit attribute to make ZipFile object compatible with with_statement (original) (raw)

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:46 admin set github: 49761
2009-12-30 13:55:28 ezio.melotti set status: open -> closedversions: + Python 3.2, - Python 3.1messages: + resolution: accepted -> fixedstage: test needed -> resolved
2009-10-08 14:29:25 brian.curtin set files: + issue5511_complete_20091008.patchkeywords: + patchmessages: +
2009-10-08 08:48:34 ezio.melotti set keywords: - patch, needs review
2009-09-12 21:52:58 ezio.melotti set resolution: acceptedmessages: +
2009-07-26 00:27:35 brian.curtin set files: - zipfile_issue_5511.patch
2009-07-26 00:27:23 brian.curtin set files: + issue5511_complete.patchmessages: +
2009-07-25 17:36:58 gregory.p.smith set assignee: ezio.melotti
2009-07-24 06🔞28 ezio.melotti set priority: normalnosy: + ezio.melottimessages: + keywords: + needs reviewstage: needs patch -> test needed
2009-07-24 03:12:06 brian.curtin set files: + zipfile_issue_5511.patchnosy: + brian.curtinmessages: + keywords: + patch
2009-03-18 18:29:52 benjamin.peterson set stage: needs patchversions: + Python 3.1, Python 2.7, - Python 2.6
2009-03-18 18:24:22 petruchio create