/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-06-01 23:52:12 UTC
  • mfrom: (0.140.55 bzr-stats)
  • mto: This revision was merged to the branch mainline in revision 6646.
  • Revision ID: jelmer@jelmer.uk-20170601235212-twcndojyo32c5wkp
Bundle the stats plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
 
18
20
import os
19
21
import socket
21
23
import urllib
22
24
import xmlrpclib
23
25
 
24
 
from bzrlib import (
 
26
from ... import (
25
27
    config,
26
28
    errors,
27
29
    urlutils,
28
 
    __version__ as _bzrlib_version,
 
30
    __version__ as _breezy_version,
29
31
    )
30
 
from bzrlib.transport.http import _urllib2_wrappers
 
32
from ...transport.http import _urllib2_wrappers
31
33
 
32
34
 
33
35
# for testing, do
34
36
'''
35
 
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
 
37
export BRZ_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
36
38
'''
37
39
 
38
40
class InvalidLaunchpadInstance(errors.BzrError):
54
56
class XMLRPCTransport(xmlrpclib.Transport):
55
57
 
56
58
    def __init__(self, scheme):
57
 
        # In python2.4 xmlrpclib.Transport is a old-style class, and does not
58
 
        # define __init__, so we check first
59
 
        init = getattr(xmlrpclib.Transport, '__init__', None)
60
 
        if init is not None:
61
 
            init(self)
 
59
        xmlrpclib.Transport.__init__(self)
62
60
        self._scheme = scheme
63
61
        self._opener = _urllib2_wrappers.Opener()
64
62
        self.verbose = 0
81
79
class LaunchpadService(object):
82
80
    """A service to talk to Launchpad via XMLRPC.
83
81
 
84
 
    See http://wiki.bazaar.canonical.com/Specs/LaunchpadRpc for the methods we can call.
 
82
    See http://wiki.bazaar.canonical.com/Specs/LaunchpadRpc for the methods we
 
83
    can call.
85
84
    """
86
85
 
87
86
    LAUNCHPAD_DOMAINS = {
88
87
        'production': 'launchpad.net',
89
 
        'edge': 'edge.launchpad.net',
90
88
        'staging': 'staging.launchpad.net',
 
89
        'qastaging': 'qastaging.launchpad.net',
91
90
        'demo': 'demo.launchpad.net',
92
91
        'dev': 'launchpad.dev',
93
92
        }
98
97
    for instance, domain in LAUNCHPAD_DOMAINS.iteritems():
99
98
        LAUNCHPAD_INSTANCE[instance] = 'https://xmlrpc.%s/bazaar/' % domain
100
99
 
101
 
    # We use edge as the default because:
102
 
    # Beta users get redirected to it
103
 
    # All users can use it
104
 
    # There is a bug in the launchpad side where redirection causes an OOPS.
105
 
    DEFAULT_INSTANCE = 'edge'
 
100
    # We use production as the default because edge has been deprecated circa
 
101
    # 2010-11 (see bug https://bugs.launchpad.net/bzr/+bug/583667)
 
102
    DEFAULT_INSTANCE = 'production'
106
103
    DEFAULT_SERVICE_URL = LAUNCHPAD_INSTANCE[DEFAULT_INSTANCE]
107
104
 
108
105
    transport = None
117
114
            uri_type = urllib.splittype(self.service_url)[0]
118
115
            transport = XMLRPCTransport(uri_type)
119
116
            transport.user_agent = 'bzr/%s (xmlrpclib/%s)' \
120
 
                    % (_bzrlib_version, xmlrpclib.__version__)
 
117
                    % (_breezy_version, xmlrpclib.__version__)
121
118
        self.transport = transport
122
119
 
123
120
    @property
126
123
 
127
124
        This does not include the username/password credentials.
128
125
        """
129
 
        key = 'BZR_LP_XMLRPC_URL'
 
126
        key = 'BRZ_LP_XMLRPC_URL'
130
127
        if key in os.environ:
131
128
            return os.environ[key]
132
129
        elif self._lp_instance is not None:
168
165
            # the url?  perhaps a bit more secure against accidentally
169
166
            # revealing it.  std66 s3.2.1 discourages putting the
170
167
            # password in the url.
171
 
            hostinfo = '%s:%s@%s' % (urllib.quote(self.registrant_email),
172
 
                                     urllib.quote(self.registrant_password),
 
168
            hostinfo = '%s:%s@%s' % (urlutils.quote(self.registrant_email),
 
169
                                     urlutils.quote(self.registrant_password),
173
170
                                     hostinfo)
174
171
            url = urlunsplit((scheme, hostinfo, path, '', ''))
175
172
        else:
196
193
        method = getattr(proxy, method_name)
197
194
        try:
198
195
            result = method(*method_params)
199
 
        except xmlrpclib.ProtocolError, e:
 
196
        except xmlrpclib.ProtocolError as e:
200
197
            if e.errcode == 301:
201
198
                # TODO: This can give a ProtocolError representing a 301 error, whose
202
199
                # e.headers['location'] tells where to go and e.errcode==301; should
209
206
                # TODO: print more headers to help in tracking down failures
210
207
                raise errors.BzrError("xmlrpc protocol error connecting to %s: %s %s"
211
208
                        % (self.service_url, e.errcode, e.errmsg))
212
 
        except socket.gaierror, e:
 
209
        except socket.gaierror as e:
213
210
            raise errors.ConnectionError(
214
211
                "Could not resolve '%s'" % self.domain,
215
212
                orig_error=e)
231
228
            resolve = _request_factory(path)
232
229
            try:
233
230
                result = resolve.submit(self)
234
 
            except xmlrpclib.Fault, fault:
 
231
            except xmlrpclib.Fault as fault:
235
232
                raise errors.InvalidURL(branch_url, str(fault))
236
233
            branch_url = result['urls'][0]
237
234
            path = urlsplit(branch_url)[2]
289
286
 
290
287
 
291
288
class BranchRegistrationRequest(BaseRequest):
292
 
    """Request to tell Launchpad about a bzr branch."""
 
289
    """Request to tell Launchpad about a brz branch."""
293
290
 
294
291
    _methodname = 'register_branch'
295
292
 
330
327
 
331
328
 
332
329
class BranchBugLinkRequest(BaseRequest):
333
 
    """Request to link a bzr branch in Launchpad to a bug."""
 
330
    """Request to link a brz branch in Launchpad to a bug."""
334
331
 
335
332
    _methodname = 'link_branch_to_bug'
336
333