jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/367321 )
Change subject: Raise a new exception class when we get a page with namespace < 0 ......................................................................
Raise a new exception class when we get a page with namespace < 0
This could be used to handle this error in scripts more properly
Bug: T169213 Change-Id: Icb312829e575fa85c0c2d477f3e7cb904dd27bfb --- M pywikibot/__init__.py M pywikibot/data/api.py M pywikibot/exceptions.py 3 files changed, 19 insertions(+), 3 deletions(-)
Approvals: Huji: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index e4000cc..348b596 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -53,7 +53,7 @@ SiteDefinitionError, NoSuchSite, UnknownSite, UnknownFamily, UnknownExtension, NoUsername, UserBlocked, - PageRelatedError, IsRedirectPage, IsNotRedirectPage, + PageRelatedError, UnsupportedPage, IsRedirectPage, IsNotRedirectPage, PageSaveRelatedError, PageNotSaved, OtherPageSaveError, LockedPage, CascadeLockedPage, LockedNoPage, NoCreateError, EditConflict, PageDeletedConflict, PageCreatedConflict, @@ -106,7 +106,8 @@ 'SiteDefinitionError', 'NoSuchSite', 'UnknownSite', 'UnknownFamily', 'UnknownExtension', 'NoUsername', 'UserBlocked', 'UserActionRefuse', - 'PageRelatedError', 'IsRedirectPage', 'IsNotRedirectPage', + 'PageRelatedError', 'UnsupportedPage', 'IsRedirectPage', + 'IsNotRedirectPage', 'PageSaveRelatedError', 'PageNotSaved', 'OtherPageSaveError', 'LockedPage', 'CascadeLockedPage', 'LockedNoPage', 'NoCreateError', 'EditConflict', 'PageDeletedConflict', 'PageCreatedConflict', diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 6dc86d6..a84db31 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -35,7 +35,7 @@ from pywikibot.comms import http from pywikibot.exceptions import ( Server504Error, Server414Error, FatalServerError, NoUsername, - Error, TimeoutError, InvalidTitle + Error, TimeoutError, InvalidTitle, UnsupportedPage ) from pywikibot.tools import ( MediaWikiVersion, deprecated, itergroup, ip, PY2, getargspec, @@ -3144,6 +3144,8 @@ property which would make the value present must be in the props parameter. @type props: iterable of string + @raises InvalidTitle: Page title is invalid + @raises UnsupportedPage: Page with namespace < 0 is not supported yet """ if "pageid" in pagedict: page._pageid = int(pagedict['pageid']) @@ -3154,6 +3156,8 @@ if page.site.sametitle(page.title(), pagedict['title']): if 'invalid' in pagedict: raise InvalidTitle('%s: %s' % (page, pagedict['invalidreason'])) + if int(pagedict['ns']) < 0: + raise UnsupportedPage(page) raise AssertionError( "Page %s has neither 'pageid' nor 'missing' attribute" % pagedict['title']) page._contentmodel = pagedict.get('contentmodel') # can be None diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py index d9dff19..52018df 100644 --- a/pywikibot/exceptions.py +++ b/pywikibot/exceptions.py @@ -24,6 +24,7 @@ PageRelatedError: any exception which is caused by an operation on a Page.
- NoPage: Page does not exist + - UnsupportedPage: Page is not supported due to a namespace restriction - IsRedirectPage: Page is a redirect page - IsNotRedirectPage: Page is not a redirect page - CircularRedirect: Page is a circular redirect @@ -227,6 +228,16 @@ pass
+class UnsupportedPage(PageRelatedError): + + """Unsupported page due to namespace restriction.""" + + # namespaces < 0 aren't supported (T169213) + message = 'Page %s is not supported due to namespace restriction.' + + pass + + class NoMoveTarget(PageRelatedError):
"""Expected move target page not found."""