diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2010-06-09 08:13:42 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2010-06-09 08:13:42 (GMT) |
commit | 17173cfe7b5f880c02a8f9468f17607ec84e5b39 (patch) | |
tree | 51a9e201ac3e86ad153505c8da15b4229f5f39f3 /Lib/xml/dom | |
parent | 3dcb5acdb0151d1686762329ec07ae2ac4d1caae (diff) | |
download | cpython-17173cfe7b5f880c02a8f9468f17607ec84e5b39.zip cpython-17173cfe7b5f880c02a8f9468f17607ec84e5b39.tar.gz cpython-17173cfe7b5f880c02a8f9468f17607ec84e5b39.tar.bz2 |
http://bugs.python.org/issue8832
Issue minidom.unlink with a context manager
Diffstat (limited to 'Lib/xml/dom')
-rw-r--r-- | Lib/xml/dom/minidom.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index f4f4400..7616b46 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -268,6 +268,14 @@ class Node(xml.dom.Node): self.previousSibling = None self.nextSibling = None + # A Node is its own context manager, to ensure that an unlink() call occurs. + # This is similar to how a file object works. + def __enter__(self): + return self + + def __exit__(self, et, ev, tb): + self.unlink() + defproperty(Node, "firstChild", doc="First child node, or None.") defproperty(Node, "lastChild", doc="Last child node, or None.") defproperty(Node, "localName", doc="Namespace-local name of this node.") |