/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/url_policy_open.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-16 02:23:42 UTC
  • mfrom: (7340 work)
  • mto: This revision was merged to the branch mainline in revision 7350.
  • Revision ID: jelmer@jelmer.uk-20190616022342-ihxzayq04x5culzd
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from . import (
24
24
    errors,
 
25
    trace,
25
26
    urlutils,
26
27
    )
27
28
from .branch import Branch
28
29
from .controldir import (
29
30
    ControlDir,
 
31
    ControlDirFormat,
 
32
    )
 
33
from .transport import (
 
34
    do_catching_redirections,
 
35
    get_transport,
30
36
    )
31
37
 
32
38
 
200
206
        """
201
207
        self.policy = policy
202
208
        self._seen_urls = set()
 
209
        if probers is None:
 
210
            probers = ControlDirFormat.all_probers()
203
211
        self.probers = probers
204
212
 
205
213
    @classmethod
276
284
            # spurious loop exceptions.
277
285
            self._seen_urls = set()
278
286
 
 
287
    def _open_dir(self, url):
 
288
        """Simple BzrDir.open clone that only uses specific probers.
 
289
 
 
290
        :param url: URL to open
 
291
        :return: ControlDir instance
 
292
        """
 
293
        def redirected(transport, e, redirection_notice):
 
294
            self.policy.check_one_url(e.target)
 
295
            redirected_transport = transport._redirected_to(
 
296
                e.source, e.target)
 
297
            if redirected_transport is None:
 
298
                raise errors.NotBranchError(e.source)
 
299
            trace.note(
 
300
                '%s is%s redirected to %s',
 
301
                transport.base, e.permanently, redirected_transport.base)
 
302
            return redirected_transport
 
303
 
 
304
        def find_format(transport):
 
305
            last_error = errors.NotBranchError(transport.base)
 
306
            for prober_kls in self.probers:
 
307
                prober = prober_kls()
 
308
                try:
 
309
                    return transport, prober.probe_transport(transport)
 
310
                except errors.NotBranchError as e:
 
311
                    last_error = e
 
312
            else:
 
313
                raise last_error
 
314
        transport = get_transport(url)
 
315
        transport, format = do_catching_redirections(
 
316
            find_format, transport, redirected)
 
317
        return format.open(transport)
 
318
 
279
319
    def follow_reference(self, url):
280
320
        """Get the branch-reference value at the specified url.
281
321
 
282
322
        This exists as a separate method only to be overriden in unit tests.
283
323
        """
284
 
        controldir = ControlDir.open(url, probers=self.probers)
 
324
        controldir = self._open_dir(url)
285
325
        return controldir.get_branch_reference()
286
326
 
287
 
    def open(self, url):
 
327
    def open(self, url, ignore_fallbacks=False):
288
328
        """Open the Bazaar branch at url, first checking it.
289
329
 
290
330
        What is acceptable means is defined by the policy's `follow_reference`
295
335
 
296
336
        url = self.check_and_follow_branch_reference(url)
297
337
 
298
 
        def open_branch(url):
299
 
            dir = ControlDir.open(url, probers=self.probers)
300
 
            return dir.open_branch()
 
338
        def open_branch(url, ignore_fallbacks):
 
339
            dir = self._open_dir(url)
 
340
            return dir.open_branch(ignore_fallbacks=ignore_fallbacks)
301
341
        return self.run_with_transform_fallback_location_hook_installed(
302
 
            open_branch, url)
 
342
            open_branch, url, ignore_fallbacks)
303
343
 
304
344
 
305
345
def open_only_scheme(allowed_scheme, url):