jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/286789 )
Change subject: [IMPR] Simplify User class ......................................................................
[IMPR] Simplify User class
- deprecate User.name() method, use User.username property instead. Replace deprecated method in welcome.py. - Simplify editCount() and groups() method - use username property in getUserTalkPage instead of title() method - remove some tests inside deprecated sendMail which are already done by send_email method. - replace contrib.get('comment', None) by dict.get('comment') because None is the default result when the key doesn't exist. - Some doc added.
Change-Id: I6b727280046b0d63b15484139426ec794e00eb49 --- M pywikibot/page.py M scripts/welcome.py 2 files changed, 29 insertions(+), 37 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 604ddb3..131820f 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -12,7 +12,7 @@
""" # -# (C) Pywikibot team, 2008-2016 +# (C) Pywikibot team, 2008-2017 # # Distributed under the terms of the MIT license. # @@ -52,7 +52,6 @@ from pywikibot.comms import http from pywikibot.exceptions import ( AutoblockUser, - _EmailUserError, NotEmailableError, SiteDefinitionError, UserRightsError, @@ -2847,9 +2846,12 @@ pywikibot.output( "This is an autoblock ID, you can only use to unblock it.")
+ @deprecated('User.username') def name(self): """ The username. + + DEPRECATED: use username instead.
@rtype: unicode """ @@ -2958,10 +2960,7 @@
@rtype: int or long """ - if 'editcount' in self.getprops(force): - return self.getprops()['editcount'] - else: - return 0 + return self.getprops(force).get('editcount', 0)
def isBlocked(self, force=False): """ @@ -2993,13 +2992,10 @@
@param force: if True, forces reloading the data from API @type force: bool - + @return: groups property @rtype: list """ - if 'groups' in self.getprops(force): - return self.getprops()['groups'] - else: - return [] + return self.getprops(force).get('groups', [])
def getUserPage(self, subpage=u''): """ @@ -3008,6 +3004,8 @@ @param subpage: subpage part to be appended to the main page title (optional) @type subpage: unicode + @return: Page object of user page or user subpage + @rtype: Page """ if self._isAutoblock: # This user is probably being queried for purpose of lifting @@ -3025,6 +3023,8 @@ @param subpage: subpage part to be appended to the main talk page title (optional) @type subpage: unicode + @return: Page object of user talk page or user talk subpage + @rtype: Page """ if self._isAutoblock: # This user is probably being queried for purpose of lifting @@ -3033,7 +3033,7 @@ "This is an autoblock ID, you can only use to unblock it.") if subpage: subpage = u'/' + subpage - return Page(Link(self.title(withNamespace=False) + subpage, + return Page(Link(self.username + subpage, self.site, defaultNamespace=3))
def send_email(self, subject, text, ccme=False): @@ -3087,22 +3087,15 @@ @type text: unicode @param ccme: if True, sends a copy of this email to the bot @type ccme: bool - @raises _EmailUserError: logged in user does not have 'sendemail' right - or the target has disabled receiving emails + @raises NotEmailableError: the user of this User is not emailable + @raises UserRightsError: logged in user does not have 'sendemail' right @return: operation successful indicator @rtype: bool """ - if not self.isEmailable(): - raise _EmailUserError('This user is not mailable') - - if not self.site.has_right('sendemail'): - raise _EmailUserError('You don't have permission to send mail') - if self.send_email(subject, text, ccme=ccme): pywikibot.output('Email sent.') return True - else: - return False + return False
def block(self, expiry, reason, anononly=True, nocreate=True, autoblock=True, noemail=False, reblock=False): @@ -3172,8 +3165,7 @@ yield (Page(self.site, contrib['title'], contrib['ns']), contrib['revid'], ts, - contrib.get('comment', None) - ) + contrib.get('comment'))
@deprecate_arg("number", "total") def uploadedImages(self, total=10): diff --git a/scripts/welcome.py b/scripts/welcome.py index 60c981d..db7b5d2 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -165,8 +165,8 @@ # (C) Filnik, 2007-2011 # (C) Daniel Herding, 2007 # (C) Alex Shih-Han Lin, 2009-2010 -# (C) xqt, 2009-2016 -# (C) Pywikibot team, 2008-2016 +# (C) xqt, 2009-2017 +# (C) Pywikibot team, 2008-2017 # # Distributed under the terms of the MIT license. # @@ -660,7 +660,7 @@
for result in queue: # Adding the log... (don't take care of the variable's name...). - luser = pywikibot.url2link(result.name(), self.site, self.site) + luser = pywikibot.url2link(result.username, self.site, self.site) text += u'\n{{WLE|user=%s|contribs=%d}}' % ( luser, result.editCount()) # update log page. @@ -729,30 +729,30 @@ for users in us: if users.isBlocked(): showStatus(3) - pywikibot.output(u'%s has been blocked!' % users.name()) + pywikibot.output('%s has been blocked!' % users.username) continue if 'bot' in users.groups(): showStatus(3) - pywikibot.output(u'%s is a bot!' % users.name()) + pywikibot.output('%s is a bot!' % users.username) continue - if 'bot' in users.name().lower(): + if 'bot' in users.username.lower(): showStatus(3) pywikibot.output(u'%s might be a global bot!' - % users.name()) + % users.username) continue if users.editCount() >= globalvar.attachEditCount: showStatus(2) pywikibot.output(u'%s has enough edits to be welcomed.' - % users.name()) + % users.username) ustp = users.getUserTalkPage() if ustp.exists(): showStatus(3) pywikibot.output(u'%s has been already welcomed.' - % users.name()) + % users.username) continue else: - if self.badNameFilter(users.name()): - self.reportBadAccount(users.name()) + if self.badNameFilter(users.username): + self.reportBadAccount(users.username) continue welcome_text = i18n.translate(self.site, netext) if globalvar.randomSign: @@ -807,11 +807,11 @@ if not globalvar.quiet: showStatus(1) pywikibot.output(u'%s has no contributions.' - % users.name()) + % users.username) else: showStatus(1) pywikibot.output(u'%s has only %d contributions.' - % (users.name(), users.editCount())) + % (users.username, users.editCount())) # That user mustn't be welcomed. continue if globalvar.makeWelcomeLog and i18n.translate(
pywikibot-commits@lists.wikimedia.org