Merge lp:~toshio/bzr/python27-lp-fix into lp:bzr

Proposed by Toshio Kuratomi
Status: Merged
Approved by: Martin Pool
Approved revision: no longer in the source branch.
Merged at revision: 5439
Proposed branch: lp:~toshio/bzr/python27-lp-fix
Merge into: lp:bzr
Diff against target: 53 lines (+24/-1)
2 files modified
NEWS (+3/-0)
bzrlib/transport/http/_urllib2_wrappers.py (+21/-1)
To merge this branch: bzr merge lp:~toshio/bzr/python27-lp-fix
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+35487@code.launchpad.net

Commit message

Fix traceback with python 2.7's xmlrpclib.

Description of the change

Fixes a problem running on python-2.7.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

Thanks. It would be good to have a comment in the class explaining with a link why we need this.

+ return self.headers/getheader(name, default)

Is that really true? It overrides /?

Also we need news.

Revision history for this message
Toshio Kuratomi (toshio) wrote :

That's a typo. Figuring out what it does need to return now.

Revision history for this message
Toshio Kuratomi (toshio) wrote :

New revision pushed -- corrects the return value, adds a class docstring to explain why we need it, and adds an entry to NEWS.

Revision history for this message
Martin Pool (mbp) wrote :

It would be nice to have a test that would have failed when your typo was present. I guess that would require running up a real listening xmlrpc server, which is perhaps a bit more work...

I might give people a chance to object and say that's easy to do, otherwise let's merge it.

It would be worth manually testing it still works on at least one of python2.[456].

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

This does seem to work for me on python 2.6.6

Revision history for this message
Andrew Bennetts (spiv) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-09-14 09:29:57 +0000
3+++ NEWS 2010-09-15 02:43:44 +0000
4@@ -92,6 +92,9 @@
5 Bug Fixes
6 *********
7
8+* Fix traceback with python-2.7's xmlrpclib
9+ (Toshio Kuratomi, #612096)
10+
11 * Allow using both --using and --diff-options.
12 (Matthäus G. Chajdas, #234708)
13
14
15=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
16--- bzrlib/transport/http/_urllib2_wrappers.py 2010-05-08 05:56:28 +0000
17+++ bzrlib/transport/http/_urllib2_wrappers.py 2010-09-15 02:43:44 +0000
18@@ -75,6 +75,26 @@
19 )
20
21
22+class addinfourl(urllib2.addinfourl):
23+ '''Replacement addinfourl class compatible with python-2.7's xmlrpclib
24+
25+ In python-2.7, xmlrpclib expects that the response object that it receives
26+ has a getheader method. httplib.HTTPResponse provides this but
27+ urllib2.addinfourl does not. Add the necessary functions here, ported to
28+ use the internal data structures of addinfourl.
29+ '''
30+
31+ def getheader(self, name, default=None):
32+ if self.headers is None:
33+ raise httplib.ResponseNotReady()
34+ return self.headers.getheader(name, default)
35+
36+ def getheaders(self):
37+ if self.headers is None:
38+ raise httplib.ResponseNotReady()
39+ return self.headers.items()
40+
41+
42 class _ReportingFileSocket(object):
43
44 def __init__(self, filesock, report_activity=None):
45@@ -656,7 +676,7 @@
46 r = response
47 r.recv = r.read
48 fp = socket._fileobject(r, bufsize=65536)
49- resp = urllib2.addinfourl(fp, r.msg, req.get_full_url())
50+ resp = addinfourl(fp, r.msg, req.get_full_url())
51 resp.code = r.status
52 resp.msg = r.reason
53 resp.version = r.version