Skip to content

Commit

Permalink
Merge "Raise a new exception class when we get a page with namespace …
Browse files Browse the repository at this point in the history
…< 0"
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Sep 18, 2017
2 parents 681bf23 + 5d6d9b1 commit 3f83d3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pywikibot/__init__.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion pywikibot/data/api.py
Expand Up @@ -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,
Expand Down Expand Up @@ -3170,6 +3170,8 @@ def update_page(page, pagedict, props=[]):
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'])
Expand All @@ -3180,6 +3182,8 @@ def update_page(page, pagedict, props=[]):
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
Expand Down
11 changes: 11 additions & 0 deletions pywikibot/exceptions.py
Expand Up @@ -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
Expand Down Expand Up @@ -227,6 +228,16 @@ class NoPage(PageRelatedError): # noqa
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."""
Expand Down

0 comments on commit 3f83d3c

Please sign in to comment.