~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/lp_registration.py

merge trunk and resolve conflicts to cleanup submission

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    errors,
32
32
    __version__ as _bzrlib_version,
33
33
    )
 
34
from bzrlib.transport.http import _urllib2_wrappers
34
35
 
35
36
# for testing, do
36
37
'''
53
54
        errors.BzrError.__init__(self, url=url)
54
55
 
55
56
 
 
57
class XMLRPCTransport(xmlrpclib.Transport):
 
58
 
 
59
    def __init__(self, scheme):
 
60
        # In python2.4 xmlrpclib.Transport is a old-style class, and does not
 
61
        # define __init__, so we check first
 
62
        init = getattr(xmlrpclib.Transport, '__init__', None)
 
63
        if init is not None:
 
64
            init(self)
 
65
        self._scheme = scheme
 
66
        self._opener = _urllib2_wrappers.Opener()
 
67
        self.verbose = 0
 
68
 
 
69
    def request(self, host, handler, request_body, verbose=0):
 
70
        self.verbose = verbose
 
71
        url = self._scheme + "://" + host + handler
 
72
        request = _urllib2_wrappers.Request("POST", url, request_body)
 
73
        # FIXME: _urllib2_wrappers will override user-agent with its own
 
74
        # request.add_header("User-Agent", self.user_agent)
 
75
        request.add_header("Content-Type", "text/xml")
 
76
 
 
77
        response = self._opener.open(request)
 
78
        if response.code != 200:
 
79
            raise xmlrpclib.ProtocolError(host + handler, response.code,
 
80
                                          response.msg, response.info())
 
81
        return self.parse_response(response)
 
82
 
 
83
 
56
84
class LaunchpadService(object):
57
85
    """A service to talk to Launchpad via XMLRPC.
58
86
 
90
118
        self._lp_instance = lp_instance
91
119
        if transport is None:
92
120
            uri_type = urllib.splittype(self.service_url)[0]
93
 
            if uri_type == 'https':
94
 
                transport = xmlrpclib.SafeTransport()
95
 
            else:
96
 
                transport = xmlrpclib.Transport()
 
121
            transport = XMLRPCTransport(uri_type)
97
122
            transport.user_agent = 'bzr/%s (xmlrpclib/%s)' \
98
123
                    % (_bzrlib_version, xmlrpclib.__version__)
99
124
        self.transport = transport