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
=== modified file 'NEWS'
--- NEWS 2010-09-14 09:29:57 +0000
+++ NEWS 2010-09-15 02:43:44 +0000
@@ -92,6 +92,9 @@
92Bug Fixes92Bug Fixes
93*********93*********
9494
95* Fix traceback with python-2.7's xmlrpclib
96 (Toshio Kuratomi, #612096)
97
95* Allow using both --using and --diff-options. 98* Allow using both --using and --diff-options.
96 (Matthäus G. Chajdas, #234708)99 (Matthäus G. Chajdas, #234708)
97100
98101
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- bzrlib/transport/http/_urllib2_wrappers.py 2010-05-08 05:56:28 +0000
+++ bzrlib/transport/http/_urllib2_wrappers.py 2010-09-15 02:43:44 +0000
@@ -75,6 +75,26 @@
75 )75 )
7676
7777
78class addinfourl(urllib2.addinfourl):
79 '''Replacement addinfourl class compatible with python-2.7's xmlrpclib
80
81 In python-2.7, xmlrpclib expects that the response object that it receives
82 has a getheader method. httplib.HTTPResponse provides this but
83 urllib2.addinfourl does not. Add the necessary functions here, ported to
84 use the internal data structures of addinfourl.
85 '''
86
87 def getheader(self, name, default=None):
88 if self.headers is None:
89 raise httplib.ResponseNotReady()
90 return self.headers.getheader(name, default)
91
92 def getheaders(self):
93 if self.headers is None:
94 raise httplib.ResponseNotReady()
95 return self.headers.items()
96
97
78class _ReportingFileSocket(object):98class _ReportingFileSocket(object):
7999
80 def __init__(self, filesock, report_activity=None):100 def __init__(self, filesock, report_activity=None):
@@ -656,7 +676,7 @@
656 r = response676 r = response
657 r.recv = r.read677 r.recv = r.read
658 fp = socket._fileobject(r, bufsize=65536)678 fp = socket._fileobject(r, bufsize=65536)
659 resp = urllib2.addinfourl(fp, r.msg, req.get_full_url())679 resp = addinfourl(fp, r.msg, req.get_full_url())
660 resp.code = r.status680 resp.code = r.status
661 resp.msg = r.reason681 resp.msg = r.reason
662 resp.version = r.version682 resp.version = r.version