~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-01-15 03:58:20 UTC
  • mfrom: (4963 +trunk)
  • mto: (4973.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4975.
  • Revision ID: andrew.bennetts@canonical.com-20100115035820-ilb3t36swgzq6v1l
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import urllib
22
22
import xmlrpclib
23
23
 
24
 
from bzrlib.lazy_import import lazy_import
25
 
lazy_import(globals(), """
26
 
from bzrlib import urlutils
27
 
""")
28
 
 
29
24
from bzrlib import (
30
25
    config,
31
26
    errors,
 
27
    urlutils,
32
28
    __version__ as _bzrlib_version,
33
29
    )
34
30
from bzrlib.transport.http import _urllib2_wrappers
35
31
 
 
32
 
36
33
# for testing, do
37
34
'''
38
35
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
123
120
                    % (_bzrlib_version, xmlrpclib.__version__)
124
121
        self.transport = transport
125
122
 
126
 
 
127
123
    @property
128
124
    def service_url(self):
129
125
        """Return the http or https url for the xmlrpc server.
141
137
        else:
142
138
            return self.DEFAULT_SERVICE_URL
143
139
 
 
140
    @classmethod
 
141
    def for_url(cls, url, **kwargs):
 
142
        """Return the Launchpad service corresponding to the given URL."""
 
143
        result = urlsplit(url)
 
144
        lp_instance = result[1]
 
145
        if lp_instance == '':
 
146
            lp_instance = None
 
147
        elif lp_instance not in cls.LAUNCHPAD_INSTANCE:
 
148
            raise errors.InvalidURL(path=url)
 
149
        return cls(lp_instance=lp_instance, **kwargs)
 
150
 
144
151
    def get_proxy(self, authenticated):
145
152
        """Return the proxy for XMLRPC requests."""
146
153
        if authenticated:
216
223
            instance = self._lp_instance
217
224
        return self.LAUNCHPAD_DOMAINS[instance]
218
225
 
219
 
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
220
 
        """Get the Launchpad web URL for the given branch URL.
221
 
 
222
 
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
223
 
            Launchpad branch URL.
224
 
        :return: The URL of the branch on Launchpad.
225
 
        """
 
226
    def _guess_branch_path(self, branch_url, _request_factory=None):
226
227
        scheme, hostinfo, path = urlsplit(branch_url)[:3]
227
228
        if _request_factory is None:
228
229
            _request_factory = ResolveLaunchpadPathRequest
240
241
                for domain in self.LAUNCHPAD_DOMAINS.itervalues())
241
242
            if hostinfo not in domains:
242
243
                raise NotLaunchpadBranch(branch_url)
 
244
        return path.lstrip('/')
 
245
 
 
246
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
 
247
        """Get the Launchpad web URL for the given branch URL.
 
248
 
 
249
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
 
250
            Launchpad branch URL.
 
251
        :return: The URL of the branch on Launchpad.
 
252
        """
 
253
        path = self._guess_branch_path(branch_url, _request_factory)
243
254
        return urlutils.join('https://code.%s' % self.domain, path)
244
255
 
245
256