Xqt has uploaded a new change for review. (
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/data/api.py
M pywikibot/exceptions.py
2 files changed, 14 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/21/367321/1
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index acb0d19..c283832 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -36,7 +36,7 @@
from pywikibot.exceptions import (
Server504Error, Server414Error, FatalServerError, NoUsername,
Error,
- InvalidTitle
+ InvalidTitle, UnsupportedPage
)
from pywikibot.tools import (
MediaWikiVersion, deprecated, itergroup, ip, PY2, getargspec,
@@ -3156,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 aa249c7..0b863cb 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
@@ -225,6 +226,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."""
--
To view, visit https://gerrit.wikimedia.org/r/367321
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb312829e575fa85c0c2d477f3e7cb904dd27bfb
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits