jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/621881 )
Change subject: [IMPR] Allow multiple types of contributors parameter given for revision_count()
......................................................................
[IMPR] Allow multiple types of contributors parameter given for revision_count()
- Currently contributors parameter of Page.revision_count() is either
None or an iterable of username string. Now a single pywikibot.User
or an iterable of pywikibot.User may be given as well as a single
string as username.
- Some tests added
- Show a FutureWarning with contributingUsers because the result is
not as described and the method is deprecated for 5 years already
Change-Id: If7ef18690a9ab42c76cb22e28676fd2aaf8136a2
---
M pywikibot/page/__init__.py
M tests/page_tests.py
2 files changed, 24 insertions(+), 12 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index a286f29..bed8745 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1834,7 +1834,7 @@
self.revisions(total=total,
starttime=starttime, endtime=endtime))
- @deprecated('contributors()', since='20150206')
+ @deprecated('contributors().keys()', since='20150206', future_warning=True)
@deprecated_args(step=True)
def contributingUsers(self, total=None):
"""
@@ -1842,25 +1842,31 @@
@param total: iterate no more than this number of revisions in total
- @rtype: set
+ @rtype: dict_keys
"""
return self.contributors(total=total).keys()
- def revision_count(self, contributors=None):
- """
- Determine number of edits from a set of contributors.
+ def revision_count(self, contributors=None) -> int:
+ """Determine number of edits from contributors.
@param contributors: contributor usernames
- @type contributors: iterable of str
-
+ @type contributors: iterable of str or pywikibot.User,
+ a single pywikibot.User, a str or None
@return: number of edits for all provided usernames
- @rtype: int
"""
- if not contributors:
- return len(list(self.revisions()))
-
cnt = self.contributors()
- return sum(cnt[username] for username in contributors)
+
+ if not contributors:
+ return sum(cnt.values())
+
+ if isinstance(contributors, User):
+ contributors = contributors.username
+
+ if isinstance(contributors, str):
+ return cnt[contributors]
+
+ return sum(cnt[user.username] if isinstance(user, User) else cnt[user]
+ for user in contributors)
@deprecated('oldest_revision', since='20140421', future_warning=True)
def getCreator(self):
diff --git a/tests/page_tests.py b/tests/page_tests.py
index e10dc23..c1b3900 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -932,6 +932,12 @@
cnt = mp.contributors()
self.assertEqual(rev_count, sum(cnt.values()))
+ user, count = cnt.most_common(1)[0]
+ self.assertEqual(mp.revision_count([user]), count)
+ self.assertEqual(mp.revision_count(user), count)
+ self.assertEqual(mp.revision_count(pywikibot.User(self.site, user)),
+ count)
+
top_two = cnt.most_common(2)
self.assertIsInstance(top_two, list)
self.assertLength(top_two, 2)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/621881
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If7ef18690a9ab42c76cb22e28676fd2aaf8136a2
Gerrit-Change-Number: 621881
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/623592 )
Change subject: [bugfix] Remove socket_timeout fix in config2.py
......................................................................
[bugfix] Remove socket_timeout fix in config2.py
requests >= 2.20.1 is required and using requests < 2.4.0 is on
bot owner's own risk. The version is checked since March 2020
and it is no longer needed to fix socket_timeout value for
compatibility with this very outdated requests version published
before August 2014.
Removing this fix should solve T261748 probably.
Bug: T261748
Change-Id: I644efed987a1e102b9fb0fc62d7f510a49bc1232
---
M pywikibot/config2.py
1 file changed, 1 insertion(+), 10 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 3fd95a6..a6ef6ef 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -45,10 +45,8 @@
import sys
import types
-from distutils.version import StrictVersion
from locale import getdefaultlocale
from os import getenv, environ
-from requests import __version__ as requests_version
from textwrap import fill
from warnings import warn
@@ -784,7 +782,7 @@
# DO NOT set to None to disable timeouts. Otherwise this may freeze your
# script.
# You may assign either a tuple of two int or float values for connection and
-# read timeout, or a single value for both in a tuple (since requests 2.4.0).
+# read timeout, or a single value for both in a tuple.
socket_timeout = (6.05, 45)
@@ -1131,13 +1129,6 @@
"Defaulting to family='wikipedia' and mylang='test'.")
mylang = 'test'
-# Fix up socket_timeout
-# Older requests library expect a single value whereas newer versions also
-# accept a tuple (connect timeout, read timeout).
-if (isinstance(socket_timeout, tuple)
- and StrictVersion(requests_version) < StrictVersion('2.4.0')):
- socket_timeout = max(socket_timeout)
-
# SECURITY WARNINGS
if (not ignore_file_security_warnings
and private_files_permission & (stat.S_IRWXG | stat.S_IRWXO) != 0):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/623592
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I644efed987a1e102b9fb0fc62d7f510a49bc1232
Gerrit-Change-Number: 623592
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged