~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to lp_registration.py

  • Committer: Martin Pool
  • Date: 2006-03-23 17:06:00 UTC
  • mto: (1668.1.8 bzr-0.8.mbp)
  • mto: This revision was merged to the branch mainline in revision 1710.
  • Revision ID: mbp@sourcefrog.net-20060323170600-faebb9dc3cc864a6
(register-branch) override xmlrpc user-agent; move Transport construction

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from getpass import getpass
18
18
import os
19
19
from urlparse import urlsplit, urlunsplit
20
 
from urllib import unquote, quote
 
20
import urllib
21
21
import xmlrpclib
22
22
 
23
23
import bzrlib.config
36
36
    registrant_email = None
37
37
    registrant_password = None
38
38
 
39
 
    def __init__(self):
 
39
 
 
40
    def __init__(self, transport=None):
40
41
        """Construct a new service talking to the launchpad rpc server"""
41
 
        pass
 
42
        if transport is None:
 
43
            uri_type = urllib.splittype(self.service_url)[0]
 
44
            if uri_type == 'https':
 
45
                transport = xmlrpclib.SafeTransport()
 
46
            else:
 
47
                transport = xmlrpclib.Transport()
 
48
            transport.user_agent = 'bzr/%s (xmlrpclib/%s)' \
 
49
                    % (bzrlib.__version__, xmlrpclib.__version__)
 
50
        self.transport = transport
 
51
 
42
52
 
43
53
    @property
44
54
    def service_url(self):
61
71
        assert '@' not in hostinfo
62
72
        assert self.registrant_email is not None
63
73
        assert self.registrant_password is not None
64
 
        hostinfo = '%s:%s@%s' % (quote(self.registrant_email),
65
 
                                 quote(self.registrant_password),
 
74
        hostinfo = '%s:%s@%s' % (urllib.quote(self.registrant_email),
 
75
                                 urllib.quote(self.registrant_password),
66
76
                                 hostinfo)
67
77
        url = urlunsplit((scheme, hostinfo, path, '', ''))
68
 
        if self.transport is None:
69
 
            self.transport = xmlrpclib.Transport()
70
 
            self.transport.user_agent = 'bzr/%s (xmlrpclib/%s)' \
71
 
                    % (bzrlib.__version__, xmlrpclib.__version__)
72
78
        return xmlrpclib.ServerProxy(url, transport=self.transport)
73
79
 
74
80
    def gather_user_credentials(self):