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: automate minidom.unlink() with a context manager
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, fdrake, kristjan.jonsson, r.david.murray
Priority: normal Keywords: easy, needs review, patch

Created on 2010-05-27 13:03 by kristjan.jonsson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
minidomcontext.patch kristjan.jonsson, 2010-05-27 13:02
Messages (7)
msg106610 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-05-27 13:02
It is all to easy to forget to "unlink()" minidom documents resulting in huge memory usage.
This patch allows to automate that process with a context manager, similar to how files can be closed in the same way:

with xml.dom.minidom.parse() as dom:
    workwith(dom)

will automatically call dom.unlink() when context manager is exited.
Patch provided.
msg107339 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-06-08 19:57
Any comments?
msg107341 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2010-06-08 20:25
+1
msg107349 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-08 21:14
Looks good to me.
msg107350 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-08 21:15
The test passes if __exit__ doesn't call unlink.  Otherwise the patch looks good to me.
msg107372 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-06-09 08:14
Thank you all.
I updated the unittest, and committed this in:
revision: 81856
msg107378 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-09 10:32
You forgot to close the bug :)

Note that if you write “rNNNN” or “revision NNNN”, Roundup will make a link out of it.
History
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 53078
2010-06-09 10:32:24eric.araujosetstatus: open -> closed
keywords: patch, patch, easy, needs review
resolution: accepted
messages: + msg107378
2010-06-09 08:14:45kristjan.jonssonsetkeywords: patch, patch, easy, needs review

messages: + msg107372
stage: resolved
2010-06-08 21:15:46r.david.murraysetkeywords: patch, patch, easy, needs review
nosy: + r.david.murray
messages: + msg107350

2010-06-08 21:14:10eric.araujosetkeywords: patch, patch, easy, needs review
nosy: + eric.araujo
messages: + msg107349

2010-06-08 20:25:06fdrakesetkeywords: patch, patch, easy, needs review
nosy: + fdrake
messages: + msg107341

2010-06-08 19:57:42kristjan.jonssonsetkeywords: patch, patch, easy, needs review

messages: + msg107339
2010-05-27 13:03:00kristjan.jonssoncreate