jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/356129 )
Change subject: [IMPR] Make socket_timeout recalculation reusable
......................................................................
[IMPR] Make socket_timeout recalculation reusable
On older installations of requests it's not possible to use two timeout values
but newer versions may have two: one for the connection one for read timeout.
To ensure the right value depending on the requests version there was a fix
inside http.py; this should be moved to the upper library place to be
reusable by other library scripts like rcstreams or eventstreams.
config2.py:
- Since requests > 2.4.1 is required with T134647 for pwb now
the default socket_timeout may be a tuple again. Use new values for it.
- fix the socket_timeout to a single value dependig on
requests version but use the higher of the two values.
Remove warning because labs is still using older requests version 2.2.1.
- http.py:
remove the socket_timeout fixer which was transfered to config2.py.
Bug: T166539
Change-Id: I598ac9fa2fa4f237b68d44bd8cf3c587d5768bd1
---
M pywikibot/comms/http.py
M pywikibot/config2.py
2 files changed, 13 insertions(+), 10 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index bbf20b3..e889975 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -14,7 +14,7 @@
from __future__ import absolute_import, print_function, unicode_literals
#
-# (C) Pywikibot team, 2007-2016
+# (C) Pywikibot team, 2007-2017
#
# Distributed under the terms of the MIT license.
#
@@ -25,7 +25,6 @@
import atexit
import sys
-from distutils.version import StrictVersion
from string import Formatter
from warnings import warn
@@ -69,13 +68,6 @@
SSL_CERT_VERIFY_FAILED_MSG = 'certificate verify failed'
_logger = "comm.http"
-
-if (isinstance(config.socket_timeout, tuple) and
- StrictVersion(requests.__version__) < StrictVersion('2.4.0')):
- warning('The configured timeout is a tuple but requests does not '
- 'support a tuple as a timeout. It uses the lower of the '
- 'two.')
- config.socket_timeout = min(config.socket_timeout)
def mode_check_decorator(func):
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 78898cc..8c2ddeb 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -50,7 +50,11 @@
import sys
import types
+from distutils.version import StrictVersion
from locale import getdefaultlocale
+
+from requests import __version__ as requests_version
+
from warnings import warn
from pywikibot.logging import error, output, warning
@@ -782,7 +786,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).
-socket_timeout = 75
+socket_timeout = (6.05, 45)
# ############# COSMETIC CHANGES SETTINGS ##############
@@ -1128,6 +1132,13 @@
"Defaulting to family='test' and
mylang='test'.")
family = 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/356129
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I598ac9fa2fa4f237b68d44bd8cf3c587d5768bd1
Gerrit-PatchSet: 9
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>