~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib.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:
16
16
 
17
17
from cStringIO import StringIO
18
18
 
19
 
from bzrlib import ui
20
 
from bzrlib.errors import NoSuchFile
 
19
from bzrlib import (
 
20
    ui,
 
21
    errors,
 
22
    )
21
23
from bzrlib.trace import mutter
22
24
from bzrlib.transport import register_urlparse_netloc_protocol
23
25
from bzrlib.transport.http import HttpTransportBase
107
109
            self._user = request.user
108
110
            self._password = request.password
109
111
 
 
112
        code = response.code
 
113
        if request.follow_redirections is False and code in (301, 302, 303, 307):
 
114
            raise errors.RedirectRequested(request.get_full_url(),
 
115
                                           request.redirected_to,
 
116
                                           is_permament=(code == 301))
 
117
 
110
118
        if request.redirected_to is not None:
111
119
            # TODO: Update the transport so that subsequent
112
120
            # requests goes directly to the right host
115
123
 
116
124
        return response
117
125
 
118
 
    def _get(self, relpath, ranges, tail_amount=0):
 
126
    def _get(self, relpath, ranges, tail_amount=0, hints={}):
119
127
        """See HttpTransport._get"""
120
128
 
121
129
        abspath = self._real_abspath(relpath)
127
135
                headers = {'Range': bytes}
128
136
 
129
137
        request = Request('GET', abspath, None, headers)
 
138
        request.follow_redirections = getattr(hints, 'follow_redirections', True)
130
139
        response = self._perform(request)
131
140
 
132
141
        code = response.code
133
142
        if code == 404: # not found
134
143
            self._connection.fake_close()
135
 
            raise NoSuchFile(abspath)
 
144
            raise errors.NoSuchFile(abspath)
136
145
 
137
146
        data = handle_response(abspath, code, response.headers, response)
138
147
        # Close response to free the httplib.HTTPConnection pipeline