Mpaa has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/816295 )
Change subject: [BUGFIX] Exit loop in PageFromFileReader if match.end() <= 0 ......................................................................
[BUGFIX] Exit loop in PageFromFileReader if match.end() <= 0
Bug: T313684 Change-Id: I797dbc1f7d12a84740e2ffab2d6b233087e159b2 --- M scripts/pagefromfile.py 1 file changed, 9 insertions(+), 12 deletions(-)
Approvals: Mpaa: Looks good to me, approved Xqt: Verified
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py index a29606f..f1809c2 100755 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -213,28 +213,25 @@ pywikibot.error(e) return
- position = 0 length = 0 - while True: + while text: try: - length, title, contents = self.findpage(text[position:]) + length, title, contents = self.findpage(text) except AttributeError: if not length: pywikibot.output('\nStart or end marker not found.') else: pywikibot.output('End of file.') break + except NoTitleError as err: pywikibot.output('\nNo title found - skipping a page.') - position += err.offset - continue - if length == 0: - break - position += length - - page = pywikibot.Page(self.site, title) - setattr(page, CTX_ATTR, contents.strip()) - yield page + text = text[err.offset:] + else: + page = pywikibot.Page(self.site, title) + setattr(page, CTX_ATTR, contents.strip()) + yield page + text = text[length:]
def findpage(self, text) -> Tuple[int, str, str]: """Find page to work on."""
pywikibot-commits@lists.wikimedia.org