jenkins-bot has submitted this change and it was merged.
Change subject: Replace httplib and urllib with httplib2
......................................................................
Replace httplib and urllib with httplib2
The module pywikibot.version contacts the code repository servers
to fetch version information. It uses httplib and urllib instead of
pywikibot 2.0's pywikibot.comms.http package which uses httplib2
with additional functionality like proxy & user-agent config, and
httplib2 has the capability to set a debug level on all requests.
As the version module is typically the first network communications of
pywikibot, as it logs version information after argument handling,
it is highly desirable that there are not several different libraries
performing network requests, each with their own quirks.
By delay-loading the pywikibot http until the online version methods
are invoked, module loading order problems as avoided.
This also replaces the hard-coded incorrect user-agent which was
'SVN/1.7.5-pywikibot1' to now be 'SVN/1.7.5 Pywikibot/x' where x
is always the current Pywikibot release version.
Bug: 66102
Change-Id: I5fa5c776cfd4c3239eb7fdca24a381e8029b26f5
---
M pywikibot/comms/http.py
M pywikibot/version.py
2 files changed, 17 insertions(+), 11 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index e9703ff..518cccd 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -252,7 +252,9 @@
if request.data[0].status == 504:
raise Server504Error("Server %s timed out" % site.hostname())
- if request.data[0].status != 200:
+ # HTTP status 207 is also a success status for Webdav FINDPROP,
+ # used by the version module.
+ if request.data[0].status not in (200, 207):
pywikibot.warning(u"Http response status %(status)s"
% {'status': request.data[0].status})
diff --git a/pywikibot/version.py b/pywikibot/version.py
index 2fd8cf9..9243910 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -13,7 +13,6 @@
import os
import time
import datetime
-import urllib
import subprocess
import pywikibot.config2 as config
@@ -146,15 +145,17 @@
@return: the git hash
@rtype: str
"""
- import httplib
+ from StringIO import StringIO
import xml.dom.minidom
- conn = httplib.HTTPSConnection('github.com')
- conn.request('PROPFIND', '/wikimedia/%s/!svn/vcc/default' % tag,
- "<?xml version='1.0'
encoding='utf-8'?>"
- "<propfind
xmlns=\"DAV:\"><allprop/></propfind>",
- {'Label': rev, 'User-Agent':
'SVN/1.7.5-pywikibot1'})
- resp = conn.getresponse()
- dom = xml.dom.minidom.parse(resp)
+ from pywikibot.comms import http
+
+ uri = 'https://github.com/wikimedia/%s/!svn/vcc/default' % tag
+ data = http.request(site=None, uri=uri, method='PROPFIND',
+ body="<?xml version='1.0'
encoding='utf-8'?>"
+ "<propfind
xmlns=\"DAV:\"><allprop/></propfind>",
+ headers={'label': str(rev), 'user-agent':
'SVN/1.7.5 {pwb}'})
+
+ dom = xml.dom.minidom.parse(StringIO(data))
hsh = dom.getElementsByTagName("C:git-commit")[0].firstChild.nodeValue
return hsh
@@ -239,9 +240,12 @@
@param repo: (optional) Online repository location
@type repo: URL or string
"""
+ from pywikibot.comms import http
+
url = repo or 'https://git.wikimedia.org/feed/pywikibot/core'
hsh = None
- buf = urllib.urlopen(url).readlines()
+ buf = http.request(site=None, uri=url)
+ buf = buf.split('\r\n')
try:
hsh = buf[13].split('/')[5][:-1]
except Exception as e:
--
To view, visit
https://gerrit.wikimedia.org/r/153300
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5fa5c776cfd4c3239eb7fdca24a381e8029b26f5
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>