17
17
"""Branch opening with URL-based restrictions."""
19
from __future__ import absolute_import
27
26
from .branch import Branch
28
27
from .controldir import (
31
from .transport import (
32
do_catching_redirections,
276
282
# spurious loop exceptions.
277
283
self._seen_urls = set()
285
def _open_dir(self, url):
286
"""Simple BzrDir.open clone that only uses specific probers.
288
:param url: URL to open
289
:return: ControlDir instance
291
def redirected(transport, e, redirection_notice):
292
self.policy.check_one_url(e.target)
293
redirected_transport = transport._redirected_to(
295
if redirected_transport is None:
296
raise errors.NotBranchError(e.source)
298
'%s is%s redirected to %s',
299
transport.base, e.permanently, redirected_transport.base)
300
return redirected_transport
302
def find_format(transport):
303
last_error = errors.NotBranchError(transport.base)
304
for prober_kls in self.probers:
305
prober = prober_kls()
307
return transport, prober.probe_transport(transport)
308
except errors.NotBranchError as e:
312
transport = get_transport(url)
313
transport, format = do_catching_redirections(
314
find_format, transport, redirected)
315
return format.open(transport)
279
317
def follow_reference(self, url):
280
318
"""Get the branch-reference value at the specified url.
282
320
This exists as a separate method only to be overriden in unit tests.
284
controldir = ControlDir.open(url, probers=self.probers)
322
controldir = self._open_dir(url)
285
323
return controldir.get_branch_reference()
325
def open(self, url, ignore_fallbacks=False):
288
326
"""Open the Bazaar branch at url, first checking it.
290
328
What is acceptable means is defined by the policy's `follow_reference`
296
334
url = self.check_and_follow_branch_reference(url)
298
def open_branch(url):
299
dir = ControlDir.open(url, probers=self.probers)
300
return dir.open_branch()
336
def open_branch(url, ignore_fallbacks):
337
dir = self._open_dir(url)
338
return dir.open_branch(ignore_fallbacks=ignore_fallbacks)
301
339
return self.run_with_transform_fallback_location_hook_installed(
340
open_branch, url, ignore_fallbacks)
305
343
def open_only_scheme(allowed_scheme, url):