jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/684118 )
Change subject: [FEAT] skip InvalidPageError in replace.py and fixing_redirects.py ......................................................................
[FEAT] skip InvalidPageError in replace.py and fixing_redirects.py
- add a new InvalidPageError exception derived from PageLoadRelatedError - raise InvalidPageError if a page as no version history instead of raising StopIteration - ignore InvalidPageError within replace.py and fixing_redirects.py when retrieving the page content
Bug: T280043 Change-Id: I05d9626c3c081cecdaa28ad284d65802c909c22e --- M pywikibot/exceptions.py M pywikibot/page/__init__.py M scripts/fixing_redirects.py M scripts/replace.py 4 files changed, 27 insertions(+), 4 deletions(-)
Approvals: Meno25: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py index 48c85ed..3b63e87 100644 --- a/pywikibot/exceptions.py +++ b/pywikibot/exceptions.py @@ -23,6 +23,7 @@ | +-- NotEmailableError | +-- PageLoadRelatedError | | +-- InconsistentTitleError + | | +-- InvalidPageError | +-- PageSaveRelatedError | | +-- EditConflictError | | | +-- ArticleExistsConflictError @@ -99,6 +100,7 @@ - IsNotRedirectPageError: Page is not a redirect page - CircularRedirectError: Page is a circular redirect - InterwikiRedirectPageError: Page is a redirect to another site + - InvalidPageError: Page is invalid e.g. without history - NotEmailableError: The target user has disabled email - NoMoveTargetError: An expected move target page does not exist
@@ -465,6 +467,13 @@ super().__init__(page)
+class InvalidPageError(PageLoadRelatedError): + + """Invalid page title.""" + + message = 'Page %s is invalid.' + + class InvalidTitleError(Error):
"""Invalid page title.""" diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 7401812..415f6b3 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -38,6 +38,7 @@ EntityTypeUnknownError, Error, InterwikiRedirectPageError, + InvalidPageError, InvalidTitleError, IsNotRedirectPageError, IsRedirectPageError, @@ -556,7 +557,10 @@ rev = self._latest_cached_revision() if rev is not None: return rev - return next(self.revisions(content=True, total=1)) + + with suppress(StopIteration): + return next(self.revisions(content=True, total=1)) + raise InvalidPageError(self)
@property def text(self) -> str: diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py index fc7341f..738b8f5 100755 --- a/scripts/fixing_redirects.py +++ b/scripts/fixing_redirects.py @@ -28,6 +28,7 @@ from pywikibot.exceptions import ( CircularRedirectError, InterwikiRedirectPageError, + InvalidPageError, InvalidTitleError, NoMoveTargetError, ) @@ -171,7 +172,12 @@ def treat_page(self): """Change all redirects from the current page to actual links.""" links = self.current_page.linkedPages() - newtext = self.current_page.text + try: + newtext = self.current_page.text + except InvalidPageError: + pywikibot.exception() + return + i = None for i, page in enumerate(links): target = self.get_target(page) diff --git a/scripts/replace.py b/scripts/replace.py index 9da35a2..7a17b8f 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -151,7 +151,7 @@ import pywikibot from pywikibot import editor, fixes, i18n, pagegenerators, textlib from pywikibot.bot import ExistingPageBot, SingleSiteBot -from pywikibot.exceptions import NoPageError +from pywikibot.exceptions import InvalidPageError, NoPageError from pywikibot.tools import chars, deprecated_args
@@ -672,7 +672,11 @@
def treat(self, page): """Work on each page retrieved from generator.""" - original_text = page.text + try: + original_text = page.text + except InvalidPageError: + pywikibot.exception() + return applied = set() new_text = original_text last_text = None
pywikibot-commits@lists.wikimedia.org