~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-11-03 03:58:26 UTC
  • mfrom: (4668.1.5 2.1.0b2)
  • Revision ID: pqm@pqm.ubuntu.com-20091103035826-tr4qa6fznzmirgiq
(jam) Merge 2.1.0b2 (-final) to bzr.dev

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, use_datetime=0):
 
60
        xmlrpclib.Transport.__init__(self, use_datetime=use_datetime)
 
61
        self._scheme = scheme
 
62
        self._opener = _urllib2_wrappers.Opener()
 
63
        self.verbose = 0
 
64
 
 
65
    def request(self, host, handler, request_body, verbose=0):
 
66
        self.verbose = verbose
 
67
        url = self._scheme + "://" + host + handler
 
68
        request = _urllib2_wrappers.Request("POST", url, request_body)
 
69
        # FIXME: _urllib2_wrappers will override user-agent with its own
 
70
        # request.add_header("User-Agent", self.user_agent)
 
71
        request.add_header("Content-Type", "text/xml")
 
72
 
 
73
        response = self._opener.open(request)
 
74
        if response.code != 200:
 
75
            raise xmlrpclib.ProtocolError(host + handler, response.code,
 
76
                                          response.msg, response.info())
 
77
        return self.parse_response(response)
 
78
 
 
79
 
56
80
class LaunchpadService(object):
57
81
    """A service to talk to Launchpad via XMLRPC.
58
82
 
90
114
        self._lp_instance = lp_instance
91
115
        if transport is None:
92
116
            uri_type = urllib.splittype(self.service_url)[0]
93
 
            if uri_type == 'https':
94
 
                transport = xmlrpclib.SafeTransport()
95
 
            else:
96
 
                transport = xmlrpclib.Transport()
 
117
            transport = XMLRPCTransport(uri_type)
97
118
            transport.user_agent = 'bzr/%s (xmlrpclib/%s)' \
98
119
                    % (_bzrlib_version, xmlrpclib.__version__)
99
120
        self.transport = transport