jenkins-bot merged this change.

View Change

Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
[IMPR] raise SpamblacklistError with spamblacklist APIError

- rename SpamfilterError with SpamblacklistError
- add SpamblacklistError to the _ep_errors exceptions list
- SpamblacklistError needs an additional url parameter.
pass err.other[err.code]['matches'] to it which contains the
expected additional urls. The wikitext err.info is already shown by
the api warning message.
- Python 3 in contrast to Python 2 also prints the APIError exception
by default with that subsequent message:
"During handling of the above exception, another exception occurred:"
The error can be raise with "from statement", e.g. "from err" In
that case the APIError will be printed too but the subsequent message
changes to:
"The above exception was the direct cause of the following exception:"
To hide the APIError exception printing in Python 3 SpamblacklistError
must be raised "from None". To support Python 2 compatibility exec
method is needed here.

Bug: T249436
Change-Id: I4346e2e6c56a38718c35191f0d0653e818a66333
---
M pywikibot/__init__.py
M pywikibot/bot.py
M pywikibot/exceptions.py
M pywikibot/site/__init__.py
4 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index e5aaf8a..b33c68c 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -44,11 +44,11 @@
LockedPage, CascadeLockedPage, LockedNoPage, NoCreateError,
EditConflict, PageDeletedConflict, PageCreatedConflict,
ServerError, FatalServerError, Server504Error,
- CaptchaError, SpamfilterError, TitleblacklistError,
+ CaptchaError, SpamblacklistError, TitleblacklistError,
CircularRedirect, InterwikiRedirectPage, WikiBaseError, NoWikibaseEntity,
CoordinateGlobeUnknownException,
DeprecatedPageNotFoundError as _DeprecatedPageNotFoundError,
- _EmailUserError,
+ _DeprecatedSpamfilterError, _EmailUserError,
)
from pywikibot.family import Family
from pywikibot.i18n import translate
@@ -104,10 +104,10 @@
'Page', 'PageCreatedConflict', 'PageDeletedConflict', 'PageNotSaved',
'PageRelatedError', 'PageSaveRelatedError', 'PropertyPage',
'QuitKeyboardInterrupt', 'SectionError', 'Server504Error', 'ServerError',
- 'showHelp', 'Site', 'SiteDefinitionError', 'SiteLink', 'SpamfilterError',
- 'stdout', 'TitleblacklistError', 'translate', 'ui', 'unicode2html',
- 'UnicodeMixin', 'UnknownExtension', 'UnknownFamily', 'UnknownSite',
- 'UnsupportedPage', 'UploadWarning', 'url2unicode', 'User',
+ 'showHelp', 'Site', 'SiteDefinitionError', 'SiteLink',
+ 'SpamblacklistError', 'stdout', 'TitleblacklistError', 'translate', 'ui',
+ 'unicode2html', 'UnicodeMixin', 'UnknownExtension', 'UnknownFamily',
+ 'UnknownSite', 'UnsupportedPage', 'UploadWarning', 'url2unicode', 'User',
'UserActionRefuse', 'UserBlocked', 'warning', 'WikiBaseError',
'WikidataBot',
)
@@ -1445,6 +1445,11 @@
'used by pywikibot; use http.fetch() instead.'),
since='20140924')
wrapper._add_deprecated_attr(
+ 'SpamfilterError', _DeprecatedSpamfilterError,
+ warning_message='SpamfilterError is deprecated; '
+ 'use SpamblacklistError instead.',
+ since='20200405')
+wrapper._add_deprecated_attr(
'UserActionRefuse', _EmailUserError,
warning_message='UserActionRefuse is deprecated; '
'use UserRightsError and/or NotEmailableError instead.',
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index a2b65ca..456d069 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1263,7 +1263,7 @@
if isinstance(e, pywikibot.EditConflict):
pywikibot.output('Skipping %s because of edit conflict'
% page.title())
- elif isinstance(e, pywikibot.SpamfilterError):
+ elif isinstance(e, pywikibot.SpamblacklistError):
pywikibot.output(
'Cannot change %s because of blacklist entry %s'
% (page.title(), e.url))
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index deca5ea..f5479e8 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -38,7 +38,7 @@
PageSaveRelatedError: page exceptions within the save operation on a Page
(alias: PageNotSaved).

- - SpamfilterError: MediaWiki spam filter detected a blacklisted URL
+ - SpamblacklistError: MediaWiki spam filter detected a blacklisted URL
- TitleblacklistError: MediaWiki detected a blacklisted page title
- OtherPageSaveError: misc. other save related exception.
- LockedPage: Page is locked
@@ -451,7 +451,7 @@
pass


-class SpamfilterError(PageSaveRelatedError):
+class SpamblacklistError(PageSaveRelatedError):

"""Page save failed because MediaWiki detected a blacklisted spam URL."""

@@ -461,7 +461,7 @@
def __init__(self, page, url):
"""Initializer."""
self.url = url
- super(SpamfilterError, self).__init__(page)
+ super(SpamblacklistError, self).__init__(page)


class TitleblacklistError(PageSaveRelatedError):
@@ -627,6 +627,14 @@
pass


+@__deprecated(since='20200405')
+class _DeprecatedSpamfilterError(SpamblacklistError):
+
+ """MediaWiki detected a blacklisted spam URL (deprecated)."""
+
+ pass
+
+
wrapper = _ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
'UploadWarning',
@@ -639,6 +647,10 @@
'longer used by pywikibot; use '
'http.fetch() instead.',
since='20141214')
+wrapper._add_deprecated_attr('SpamfilterError', _DeprecatedSpamfilterError,
+ warning_message='SpamfilterError is deprecated; '
+ 'use SpamblacklistError instead.',
+ since='20200405')
wrapper._add_deprecated_attr(
'UserActionRefuse', _EmailUserError,
warning_message='UserActionRefuse is deprecated; '
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index f7b8471..3906be9 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -63,7 +63,7 @@
PageRelatedError,
PageSaveRelatedError,
SiteDefinitionError,
- SpamfilterError,
+ SpamblacklistError,
TitleblacklistError,
UnknownExtension,
UnknownSite,
@@ -5265,6 +5265,7 @@
'protectedtitle': LockedNoPage,
'cascadeprotected': CascadeLockedPage,
'titleblacklist-forbidden': TitleblacklistError,
+ 'spamblacklist': SpamblacklistError,
}
_ep_text_overrides = {'appendtext', 'prependtext', 'undo'}

@@ -5390,16 +5391,24 @@
'logged in' % err.code,
_logger)
if err.code in self._ep_errors:
- if isinstance(self._ep_errors[err.code], UnicodeType):
+ exception = self._ep_errors[err.code]
+ if isinstance(exception, UnicodeType):
errdata = {
'site': self,
'title': page.title(with_section=False),
'user': self.user(),
'info': err.info
}
- raise Error(self._ep_errors[err.code] % errdata)
+ raise Error(exception % errdata)
+ elif issubclass(exception, SpamblacklistError):
+ urls = ', '.join(err.other[err.code]['matches'])
+ exec_string = ('raise exception(page, url="{}")'
+ .format(urls))
+ if not PY2:
+ exec_string += ' from None'
+ exec(exec_string)
else:
- raise self._ep_errors[err.code](page)
+ raise exception(page)
pywikibot.debug(
"editpage: Unexpected error code '%s' received."
% err.code,
@@ -5450,8 +5459,8 @@
return False

if 'spamblacklist' in result['edit']:
- raise SpamfilterError(page,
- result['edit']['spamblacklist'])
+ raise SpamblacklistError(
+ page, result['edit']['spamblacklist'])

if 'code' in result['edit'] and 'info' in result['edit']:
pywikibot.error(

To view, visit change 586037. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I4346e2e6c56a38718c35191f0d0653e818a66333
Gerrit-Change-Number: 586037
Gerrit-PatchSet: 13
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Dvorapa <dvorapa@seznam.cz>
Gerrit-CC: Matěj Suchánek <matejsuchanek97@gmail.com>