~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib2_wrappers.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-13 17:37:07 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20061213173707-a1gflgoke6b3eboc
First rough http branch redirection implementation.

* bzrlib/transport/http/_urllib2_wrappers.py:
(Request.__init__): Unless told otherwise, redirections are
followed silently.
(HTTPRedirectHandler.http_error_30x): Follow redirection or return
a 30x error.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib._perform): Raises RedirectRequested if the
request requires it.
(HttpTransport_urllib._get): Update the request from the hints
parameter if needed.

* bzrlib/errors.py:
 (RedirectRequested): New TransportError.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport): Catch RedirectRequested and retry
with the redirected url until we get to the final destination.
(BzrDirFormat.probe_transport): Hints get to not follow the
redirections but instead tell us where this branch is redirected.

* bzrlib/transport/smart.py:
(SmartTransport.get): Add a 'hint' parameter.

* bzrlib/transport/sftp.py:
(SFTPTransport.get): Add a 'hint' parameter.

* bzrlib/transport/memory.py:
(MemoryTransport.get): Add a 'hint' parameter.

* bzrlib/transport/local.py:
(LocalTransport.get): Add a 'hint' parameter.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._get): Add a 'hint' parameter and pass it to
_get_full.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase.get): Add a 'hint' parameter and pass
it to _get.

* bzrlib/transport/ftp.py:
(FtpTransport.get): Add a 'hint' parameter.

* bzrlib/transport/fakevfat.py:
(FakeVFATTransportDecorator.get): Add a 'hint' parameter and pass
it to the decorated transport.

* bzrlib/transport/decorator.py:
(TransportDecorator.get): Add a 'hint' parameter and pass it to the
decorated transport.

* bzrlib/transport/chroot.py:
(ChrootTransportDecorator.get): Add a 'hint' parameter. Delete a
duplicated definition of the method.

* bzrlib/transport/__init__.py:
(Transport.get): Add a 'hint' parameter.
(TransportLogger.get): Add a 'hint' parameter and pass it to the
        

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
        # To handle redirections
156
156
        self.parent = parent
157
157
        self.redirected_to = None
 
158
        # Unless told otherwise, redirections are followed
 
159
        # silently
 
160
        self.follow_redirections = True
158
161
 
159
162
    def extract_auth(self, url):
160
163
        """Extracts authentification information from url.
504
507
        # reference to the following request in the redirect
505
508
        # chain.
506
509
 
507
 
        # Some codes make no sense on out context and are treated
 
510
        # Some codes make no sense in our context and are treated
508
511
        # as errors:
509
512
 
510
513
        # 300: Multiple choices for different representations of
519
522
 
520
523
        # 306: Unused (if the RFC says so...)
521
524
 
522
 
        # FIXME: If the code is 302 and the request is HEAD, we
523
 
        # MAY avoid following the redirections if the intent is
524
 
        # to check the existence, we have a hint that the file
525
 
        # exist, now if we want to be sure, we must follow the
526
 
        # redirection. Let's do that for now.
 
525
        # If the code is 302 and the request is HEAD, some may
 
526
        # think that it is a sufficent hint that the file exists
 
527
        # and that we MAY avoid following the redirections. But
 
528
        # if we want to be sure, we MUST follow them.
527
529
 
528
530
        if code in (301, 302, 303, 307):
529
531
            return Request(req.get_method(),newurl,
560
562
        else:
561
563
            return
562
564
        if self._debuglevel > 0:
563
 
            print 'Redirected to: %s' % newurl
 
565
            print 'Redirected to: %s (followed: %r)' % (newurl,
 
566
                                                        req.follow_redirections)
 
567
        if req.follow_redirections is False:
 
568
            req.redirected_to = newurl
 
569
            return fp
 
570
 
564
571
        newurl = urlparse.urljoin(req.get_full_url(), newurl)
565
572
 
566
573
        # This call succeeds or raise an error. urllib2 returns