John Vandenberg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234487
Change subject: Support requests 0.8.2
......................................................................
Support requests 0.8.2
Bug: T110637
Change-Id: I0a0edfe2d73321bb9f89f4f3ce6d235c08696578
---
M .travis.yml
M pywikibot/comms/http.py
M pywikibot/comms/threadedhttp.py
M setup.py
4 files changed, 40 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/87/234487/1
diff --git a/.travis.yml b/.travis.yml
index 7a60b58..f632682 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,6 +21,7 @@
- graphviz
- liblua5.1-0-dev
- python-ipaddr
+ - python-requests
before_install:
# When PYSETUP_TEST_EXTRAS is not enabled, do not allow the
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 835202f..4ea170c 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -38,10 +38,22 @@
if sys.version_info[0] > 2:
from http import cookiejar as cookielib
- from urllib.parse import quote
+ from urllib.parse import quote, urlparse
else:
import cookielib
from urllib2 import quote
+ from urlparse import urlparse
+
+try:
+ from requests.exceptions import SSLError
+except ImportError:
+
+ class SSLError():
+
+ """Fake SSLError."""
+
+ pass
+
from pywikibot import config
from pywikibot.exceptions import (
@@ -74,12 +86,16 @@
pywikibot.debug(u"Loaded cookies from file.", _logger)
session = requests.Session()
-session.cookies = cookie_jar
+if not isinstance(requests_oauthlib, Exception):
+ session.cookies = cookie_jar
+else:
+ session.cookies = requests.utils.dict_from_cookiejar(cookie_jar)
# Prepare flush on quit
def _flush():
- session.close()
+ if hasattr(session, 'close'):
+ session.close()
message = 'Closing network session.'
if hasattr(sys, 'last_type'):
# we quit because of an exception
@@ -255,7 +271,7 @@
@return: authentication token
@rtype: None or tuple of two str
"""
- parsed_uri = requests.utils.urlparse(uri)
+ parsed_uri = urlparse(uri)
netloc_parts = parsed_uri.netloc.split('.')
netlocs = [parsed_uri.netloc] + ['.'.join(['*'] + netloc_parts[i + 1:])
for i in range(len(netloc_parts))]
@@ -270,6 +286,8 @@
def _http_process(session, http_request):
+ global cookie_jar
+
method = http_request.method
uri = http_request.uri
body = http_request.body
@@ -292,9 +310,19 @@
# Note that the connections are pooled which mean that a future
# HTTPS request can succeed even if the certificate is invalid and
# verify=True, when a request with verify=False happened before
+ kwargs = {
+ 'auth': auth,
+ 'timeout': timeout,
+ 'verify': not ignore_validation,
+ }
+ if not hasattr(session, 'verify'):
+ del kwargs['verify']
+
response = session.request(method, uri, data=body, headers=headers,
- auth=auth, timeout=timeout,
- verify=not ignore_validation)
+ **kwargs)
+
+ if isinstance(session.cookies, dict):
+ cookie_jar = requests.utils.cookiejar_from_dict(session.cookies)
except Exception as e:
http_request.data = e
else:
@@ -309,7 +337,7 @@
@type request: L{threadedhttp.HttpRequest}
"""
# TODO: do some error correcting stuff
- if isinstance(request.data, requests.exceptions.SSLError):
+ if isinstance(request.data, SSLError):
if SSL_CERT_VERIFY_FAILED_MSG in str(request.data):
raise FatalServerError(str(request.data))
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index 6c6f72a..b44b2a0 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -117,7 +117,8 @@
def header_encoding(self):
"""Return charset given by the response header."""
if not hasattr(self, '_header_encoding'):
- pos = self.response_headers['content-type'].find('charset=')
+ content_type = self.response_headers['content-type']
+ pos = -1 if not content_type else content_type.find('charset=')
if pos >= 0:
pos += len('charset=')
encoding = self.response_headers['content-type'][pos:]
diff --git a/setup.py b/setup.py
index bbff59b..f3b7b7b 100644
--- a/setup.py
+++ b/setup.py
@@ -131,7 +131,8 @@
# them up and the warnings will stop. See
#
<https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning>
# for more details.
- dependencies += extra_deps['security']
+ # dependencies += extra_deps['security']
+ pass
script_deps['data_ingestion.py'] = extra_deps['csv']
--
To view, visit https://gerrit.wikimedia.org/r/234487
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a0edfe2d73321bb9f89f4f3ce6d235c08696578
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits