jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/986537 )
Change subject: [bugfix]: use only 'end' tags in ElementTree.iterparse ......................................................................
[bugfix]: use only 'end' tags in ElementTree.iterparse
See note in iterparse() official docs.
Bug: T354095 Change-Id: Id3498ad90c266aff5e98c79ff08bcc8f14a0bfac --- M pywikibot/xmlreader.py 1 file changed, 18 insertions(+), 7 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py index 5d3575e..a01c4d4 100644 --- a/pywikibot/xmlreader.py +++ b/pywikibot/xmlreader.py @@ -18,7 +18,6 @@ from __future__ import annotations
import re -from typing import Optional, Union
try: @@ -124,11 +123,11 @@ """
def __init__(self, filename, *, - allrevisions: Union[bool, str] = None, + allrevisions: bool | str = None, # when allrevisions removed, revisions can default to 'latest' revisions: str = 'first_found', - on_error: Optional[ - Callable[[Type[BaseException]], None]] = None) -> None: + on_error: None | ( + Callable[[Type[BaseException]], None]) = None) -> None: """Initializer.""" self.filename = filename self.on_error = on_error @@ -237,10 +236,10 @@
def _parse_all(self, event, elem): """Parser that yields all revisions.""" - if event == 'start' and elem.tag == f'{{{self.uri}}}page': + if event == 'end' and elem.tag == f'{{{self.uri}}}page': self._headers(elem) - if event == 'end' and elem.tag == f'{{{self.uri}}}revision': - yield self._create_revision(elem) + for revision in elem.findall(f'{{{self.uri}}}revision'): + yield self._create_revision(revision) elem.clear() self.root.clear()