jenkins-bot merged this change.

View Change

Approvals: Huji: Looks good to me, approved D3r1ck01: Looks good to me, but someone else must approve jenkins-bot: Verified
[IMPR] use site.watch() when calling site.watchpage()

- use site.watch() when calling site.watchpage() and remove code
duplication.
- self.watchpage is old enough to ommit the detailed api response.
site.watch should be used in that case which raises a KeyError
in such case.

Change-Id: I1143f0a8fa5c409760a656f154f28b79ad2ece94
---
M pywikibot/site.py
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/pywikibot/site.py b/pywikibot/site.py
index ffa45da..36ba13c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -6082,6 +6082,7 @@
if False add them (default).
@return: True if API returned expected response; False otherwise
@rtype: bool
+ @raises KeyError: 'watch' isn't in API response

"""
parameters = {'action': 'watch',
@@ -6125,16 +6126,12 @@
@rtype: bool

"""
- parameters = {'action': 'watch',
- 'title': page,
- 'token': self.tokens['watch'],
- 'unwatch': unwatch}
- req = self._simple_request(**parameters)
- result = req.submit()
- if 'watch' not in result:
- pywikibot.error('watchpage: Unexpected API response:\n%s' % result)
- return False
- return ('unwatched' if unwatch else 'watched') in result['watch']
+ try:
+ result = self.watch(page, unwatch)
+ except KeyError:
+ pywikibot.error('watchpage: Unexpected API response')
+ result = False
+ return result

@must_be(group='user')
def purgepages(

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1143f0a8fa5c409760a656f154f28b79ad2ece94
Gerrit-Change-Number: 494677
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Huji <huji.huji@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)