/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-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from . import (
24
24
    errors,
25
 
    trace,
26
25
    urlutils,
27
26
    )
28
27
from .branch import Branch
29
28
from .controldir import (
30
29
    ControlDir,
31
 
    ControlDirFormat,
32
 
    )
33
 
from .transport import (
34
 
    do_catching_redirections,
35
 
    get_transport,
36
30
    )
37
31
 
38
32
 
190
184
    checked against a policy object.
191
185
 
192
186
    The policy object is expected to have the following methods:
193
 
    * check_one_url
 
187
    * check_one_url 
194
188
    * should_follow_references
195
189
    * transform_fallback_location
196
190
    """
206
200
        """
207
201
        self.policy = policy
208
202
        self._seen_urls = set()
209
 
        if probers is None:
210
 
            probers = ControlDirFormat.all_probers()
211
203
        self.probers = probers
212
204
 
213
205
    @classmethod
256
248
    def transform_fallback_locationHook(cls, branch, url):
257
249
        """Installed as the 'transform_fallback_location' Branch hook.
258
250
 
259
 
        This method calls `transform_fallback_location` on the policy object
260
 
        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
261
253
        check_and_follow_branch_reference.
262
254
        """
263
255
        try:
284
276
            # spurious loop exceptions.
285
277
            self._seen_urls = set()
286
278
 
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
 
 
319
279
    def follow_reference(self, url):
320
280
        """Get the branch-reference value at the specified url.
321
281
 
322
282
        This exists as a separate method only to be overriden in unit tests.
323
283
        """
324
 
        controldir = self._open_dir(url)
 
284
        controldir = ControlDir.open(url, probers=self.probers)
325
285
        return controldir.get_branch_reference()
326
286
 
327
 
    def open(self, url, ignore_fallbacks=False):
 
287
    def open(self, url):
328
288
        """Open the Bazaar branch at url, first checking it.
329
289
 
330
 
        What is acceptable means is defined by the policy's `follow_reference`
331
 
        and `check_one_url` methods.
 
290
        What is acceptable means is defined by the policy's `follow_reference` and
 
291
        `check_one_url` methods.
332
292
        """
333
293
        if not isinstance(url, str):
334
294
            raise TypeError
335
295
 
336
296
        url = self.check_and_follow_branch_reference(url)
337
297
 
338
 
        def open_branch(url, ignore_fallbacks):
339
 
            dir = self._open_dir(url)
340
 
            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()
341
301
        return self.run_with_transform_fallback_location_hook_installed(
342
 
            open_branch, url, ignore_fallbacks)
 
302
            open_branch, url)
343
303
 
344
304
 
345
305
def open_only_scheme(allowed_scheme, url):