Skip to content

Commit 9984c8f

Browse files
committed
gh-148428: Address review: docstring, doc markup, user-stream clear() test
1 parent a28581c commit 9984c8f

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

Doc/library/xml.dom.pulldom.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ DOMEventStream Objects
147147

148148
.. method:: DOMEventStream.reset()
149149

150-
.. method:: DOMEventStream.clear()
150+
.. method:: clear()
151151

152-
Release the parsing objects and close the underlying stream if it
153-
was opened by :func:`parse`. Streams provided by the caller are not
154-
closed. It is safe to call this method more than once.
152+
Release references to the parser, the stream and the DOM builder,
153+
and close the stream if it was opened by :func:`parse`. Streams
154+
provided by the caller are not closed. It is safe to call this
155+
method more than once. The event stream cannot be used after
156+
calling this method.
155157

156158
.. versionchanged:: next
157159
This method now closes the underlying stream if it was opened

Lib/test/test_pulldom.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def test_clear_closes_owned_stream(self):
5959
self.assertTrue(stream.closed)
6060
events.clear() # should not raise
6161

62+
def test_clear_does_not_close_user_stream(self):
63+
with open(tstfile, 'rb') as f:
64+
events = pulldom.parse(f)
65+
list(events)
66+
events.clear()
67+
self.assertFalse(f.closed)
68+
6269
def test_parse_semantics(self):
6370
"""Test DOMEventStream parsing semantics."""
6471

Lib/xml/dom/pulldom.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ def _emit(self):
281281
return rc
282282

283283
def clear(self):
284-
"""clear(): Explicitly release parsing objects"""
284+
"""Release the parsing objects.
285+
286+
The stream is closed if it was opened by parse().
287+
"""
285288
if self._owns_stream and self.stream is not None:
286289
self.stream.close()
287290
if self.pulldom is not None:

0 commit comments

Comments
 (0)