mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue minidom.unlink with a context manager
This commit is contained in:
parent
3dcb5acdb0
commit
17173cfe7b
3 changed files with 22 additions and 0 deletions
|
@ -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.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue