~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib2_wrappers.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-21 10:48:23 UTC
  • mfrom: (5393.6.3 bzr)
  • Revision ID: pqm@pqm.ubuntu.com-20100921104823-0jks3g5o1bahesyq
(spiv) Fix traceback with python 2.7's xmlrpclib. (Toshio Kuratomi)

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
    )
76
76
 
77
77
 
 
78
class 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
 
78
98
class _ReportingFileSocket(object):
79
99
 
80
100
    def __init__(self, filesock, report_activity=None):
656
676
            r = response
657
677
            r.recv = r.read
658
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
680
            resp.code = r.status
661
681
            resp.msg = r.reason
662
682
            resp.version = r.version