John Vandenberg has submitted this change and it was merged.
Change subject: Add NoCreateError and fix a bug about issubclass
......................................................................
Add NoCreateError and fix a bug about issubclass
With nocreate=True, if page doesn't exist, API will return
missingtitle which is not recognized by PWB. This patch adds
NoCreateError to match with this missingtitle in this case.
This patch also fixes a bug when issubclass is used but the first
parameter is not a class, leading to an error
"TypeError: issubclass() arg 1 must be a class"
Change-Id: I11f80783c9febce51538e868a0b1edb42cce4ec3
---
M pywikibot/__init__.py
M pywikibot/exceptions.py
M pywikibot/site.py
3 files changed, 15 insertions(+), 5 deletions(-)
Approvals:
John Vandenberg: Verified; Looks good to me, approved
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index ad0c475..14327d2 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -40,7 +40,7 @@
NoUsername, UserBlocked,
PageRelatedError, IsRedirectPage, IsNotRedirectPage,
PageSaveRelatedError, PageNotSaved, OtherPageSaveError,
- LockedPage, CascadeLockedPage, LockedNoPage,
+ LockedPage, CascadeLockedPage, LockedNoPage, NoCreateError,
EditConflict, PageDeletedConflict, PageCreatedConflict,
ServerError, FatalServerError, Server504Error,
CaptchaError, SpamfilterError, CircularRedirect,
@@ -76,7 +76,7 @@
'NoUsername', 'UserBlocked',
'PageRelatedError', 'IsRedirectPage',
'IsNotRedirectPage',
'PageSaveRelatedError', 'PageNotSaved',
'OtherPageSaveError',
- 'LockedPage', 'CascadeLockedPage', 'LockedNoPage',
+ 'LockedPage', 'CascadeLockedPage', 'LockedNoPage',
'NoCreateError',
'EditConflict', 'PageDeletedConflict',
'PageCreatedConflict',
'UploadWarning',
'ServerError', 'FatalServerError', 'Server504Error',
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index ad0c566..d735038 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -35,6 +35,7 @@
- PageDeletedConflict: Page was deleted since being retrieved
- PageCreatedConflict: Page was created by another user
- ArticleExistsConflict: Page article already exists
+ - NoCreateError: parameter nocreate not allow page creation
ServerError: a problem with the server.
- FatalServerError: A fatal/non-recoverable server error
@@ -259,6 +260,13 @@
PageNotSaved = PageSaveRelatedError
+class NoCreateError(PageSaveRelatedError):
+
+ """Parameter nocreate doesn't allow page
creation."""
+
+ message = u"Page %s could not be created due to parameter nocreate"
+
+ pass
class EditConflict(PageSaveRelatedError):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index dffd696..17611ee 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -50,6 +50,7 @@
SiteDefinitionError,
NoUsername,
SpamfilterError,
+ NoCreateError,
UserBlocked,
)
@@ -3682,6 +3683,7 @@
"noedit-anon": """Bot is not logged in, and anon users
are not authorized to edit on %(site)s wiki""",
"noedit": "User %(user)s not authorized to edit pages on %(site)s
wiki",
+ "missingtitle": NoCreateError,
"editconflict": EditConflict,
"articleexists": PageCreatedConflict,
"pagedeleted": PageDeletedConflict,
@@ -3775,9 +3777,7 @@
% err.code,
_logger)
if err.code in self._ep_errors:
- if issubclass(self._ep_errors[err.code], PageSaveRelatedError):
- raise self._ep_errors[err.code](page)
- else:
+ if isinstance(self._ep_errors[err.code], basestring):
errdata = {
'site': self,
'title': page.title(withSection=False),
@@ -3785,6 +3785,8 @@
'info': err.info
}
raise Error(self._ep_errors[err.code] % errdata)
+ else:
+ raise self._ep_errors[err.code](page)
pywikibot.debug(
u"editpage: Unexpected error code '%s' received."
% err.code,
--
To view, visit
https://gerrit.wikimedia.org/r/168816
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I11f80783c9febce51538e868a0b1edb42cce4ec3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>