~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jonathan Lange
  • Date: 2009-07-04 09:28:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4907.
  • Revision ID: jml@canonical.com-20090704092823-0019150j6xx274hx
Factor out some code that guesses a branch's URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    __version__ as _bzrlib_version,
28
28
    )
29
29
 
 
30
 
30
31
# for testing, do
31
32
'''
32
33
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
192
193
            instance = self._lp_instance
193
194
        return self.LAUNCHPAD_DOMAINS[instance]
194
195
 
195
 
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
196
 
        """Get the Launchpad web URL for the given branch URL.
197
 
 
198
 
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
199
 
            Launchpad branch URL.
200
 
        :return: The URL of the branch on Launchpad.
201
 
        """
 
196
    def _guess_branch_path(self, branch_url, _request_factory=None):
202
197
        scheme, hostinfo, path = urlsplit(branch_url)[:3]
203
198
        if _request_factory is None:
204
199
            _request_factory = ResolveLaunchpadPathRequest
216
211
                for domain in self.LAUNCHPAD_DOMAINS.itervalues())
217
212
            if hostinfo not in domains:
218
213
                raise NotLaunchpadBranch(branch_url)
 
214
        return path.lstrip('/')
 
215
 
 
216
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
 
217
        """Get the Launchpad web URL for the given branch URL.
 
218
 
 
219
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
 
220
            Launchpad branch URL.
 
221
        :return: The URL of the branch on Launchpad.
 
222
        """
 
223
        path = self._guess_branch_path(branch_url, _request_factory)
219
224
        return urlutils.join('https://code.%s' % self.domain, path)
220
225
 
221
226