/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: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Branch opening with URL-based restrictions."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import threading
20
22
 
21
23
from . import (
22
24
    errors,
23
 
    trace,
24
25
    urlutils,
25
26
    )
26
27
from .branch import Branch
27
28
from .controldir import (
28
29
    ControlDir,
29
 
    ControlDirFormat,
30
 
    )
31
 
from .transport import (
32
 
    do_catching_redirections,
33
 
    get_transport,
34
30
    )
35
31
 
36
32
 
188
184
    checked against a policy object.
189
185
 
190
186
    The policy object is expected to have the following methods:
191
 
    * check_one_url
 
187
    * check_one_url 
192
188
    * should_follow_references
193
189
    * transform_fallback_location
194
190
    """
204
200
        """
205
201
        self.policy = policy
206
202
        self._seen_urls = set()
207
 
        if probers is None:
208
 
            probers = ControlDirFormat.all_probers()
209
203
        self.probers = probers
210
204
 
211
205
    @classmethod
254
248
    def transform_fallback_locationHook(cls, branch, url):
255
249
        """Installed as the 'transform_fallback_location' Branch hook.
256
250
 
257
 
        This method calls `transform_fallback_location` on the policy object
258
 
        and either returns the url it provides or passes it back to
 
251
        This method calls `transform_fallback_location` on the policy object and
 
252
        either returns the url it provides or passes it back to
259
253
        check_and_follow_branch_reference.
260
254
        """
261
255
        try:
282
276
            # spurious loop exceptions.
283
277
            self._seen_urls = set()
284
278
 
285
 
    def _open_dir(self, url):
286
 
        """Simple BzrDir.open clone that only uses specific probers.
287
 
 
288
 
        :param url: URL to open
289
 
        :return: ControlDir instance
290
 
        """
291
 
        def redirected(transport, e, redirection_notice):
292
 
            self.policy.check_one_url(e.target)
293
 
            redirected_transport = transport._redirected_to(
294
 
                e.source, e.target)
295
 
            if redirected_transport is None:
296
 
                raise errors.NotBranchError(e.source)
297
 
            trace.note(
298
 
                '%s is%s redirected to %s',
299
 
                transport.base, e.permanently, redirected_transport.base)
300
 
            return redirected_transport
301
 
 
302
 
        def find_format(transport):
303
 
            last_error = errors.NotBranchError(transport.base)
304
 
            for prober_kls in self.probers:
305
 
                prober = prober_kls()
306
 
                try:
307
 
                    return transport, prober.probe_transport(transport)
308
 
                except errors.NotBranchError as e:
309
 
                    last_error = e
310
 
            else:
311
 
                raise last_error
312
 
        transport = get_transport(url)
313
 
        transport, format = do_catching_redirections(
314
 
            find_format, transport, redirected)
315
 
        return format.open(transport)
316
 
 
317
279
    def follow_reference(self, url):
318
280
        """Get the branch-reference value at the specified url.
319
281
 
320
282
        This exists as a separate method only to be overriden in unit tests.
321
283
        """
322
 
        controldir = self._open_dir(url)
 
284
        controldir = ControlDir.open(url, probers=self.probers)
323
285
        return controldir.get_branch_reference()
324
286
 
325
 
    def open(self, url, ignore_fallbacks=False):
 
287
    def open(self, url):
326
288
        """Open the Bazaar branch at url, first checking it.
327
289
 
328
 
        What is acceptable means is defined by the policy's `follow_reference`
329
 
        and `check_one_url` methods.
 
290
        What is acceptable means is defined by the policy's `follow_reference` and
 
291
        `check_one_url` methods.
330
292
        """
331
293
        if not isinstance(url, str):
332
294
            raise TypeError
333
295
 
334
296
        url = self.check_and_follow_branch_reference(url)
335
297
 
336
 
        def open_branch(url, ignore_fallbacks):
337
 
            dir = self._open_dir(url)
338
 
            return dir.open_branch(ignore_fallbacks=ignore_fallbacks)
 
298
        def open_branch(url):
 
299
            dir = ControlDir.open(url, probers=self.probers)
 
300
            return dir.open_branch()
339
301
        return self.run_with_transform_fallback_location_hook_installed(
340
 
            open_branch, url, ignore_fallbacks)
 
302
            open_branch, url)
341
303
 
342
304
 
343
305
def open_only_scheme(allowed_scheme, url):