Rev 3884: Fix bug #270863 by preserving 'bzr+http[s]' decorator. in lp:~vila/bzr/303959-redirection
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Dec 4 17:12:50 GMT 2008
At lp:~vila/bzr/303959-redirection
------------------------------------------------------------
revno: 3884
revision-id: v.ladeuil+lp at free.fr-20081204171246-p28b3u0e2alz53iv
parent: v.ladeuil+lp at free.fr-20081204160251-37f920alwn9t0i4p
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 303959-redirection
timestamp: Thu 2008-12-04 18:12:46 +0100
message:
Fix bug #270863 by preserving 'bzr+http[s]' decorator.
* bzrlib/transport/remote.py:
(RemoteHTTPTransport._redirected_to): Specific implementation to
handle the redirections.
* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.__init__): Fix parameter order.
* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport.__init__): Fix parameter order.
* bzrlib/transport/http/__init__.py:
(HttpTransportBase.external_url): Semi drive-by fix, external_url
shouldn't expose the implementation qualifier (it's private to bzr
not externally usable).
* bzrlib/transport/decorator.py:
(TransportDecorator._redirected_to): Cleanup.
* bzrlib/tests/test_smart_transport.py:
(RemoteHTTPTransportTestCase): Add specific tests for
_redirected_to.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
bzrlib/transport/decorator.py decorator.py-20060402223305-e913a0f25319ab42
bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
bzrlib/transport/remote.py ssh.py-20060608202016-c25gvf1ob7ypbus6-1
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2008-12-04 11:50:30 +0000
+++ b/NEWS 2008-12-04 17:12:46 +0000
@@ -24,7 +24,7 @@
(Marius Kruger, #301969)
* Preserve transport decorators while following redirections.
- (Vincent Ladeuil, #245964)
+ (Vincent Ladeuil, #245964, #270863)
* Provides a finer and more robust filter for accepted redirections.
(Vincent Ladeuil, #303959, #265070)
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2008-10-17 06:01:10 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2008-12-04 17:12:46 +0000
@@ -3357,8 +3357,8 @@
# requests for child URLs of that to the original URL. i.e., we want to
# POST to "bzr+http://host/foo/.bzr/smart" and never something like
# "bzr+http://host/foo/.bzr/branch/.bzr/smart". So, a cloned
- # RemoteHTTPTransport remembers the initial URL, and adjusts the relpaths
- # it sends in smart requests accordingly.
+ # RemoteHTTPTransport remembers the initial URL, and adjusts the
+ # relpaths it sends in smart requests accordingly.
base_transport = remote.RemoteHTTPTransport('bzr+http://host/path')
new_transport = base_transport.clone('child_dir')
self.assertEqual(base_transport._http_transport,
@@ -3384,7 +3384,34 @@
'c/',
new_transport._client.remote_path_from_transport(new_transport))
-
+ def test__redirect_to(self):
+ t = remote.RemoteHTTPTransport('bzr+http://www.example.com/foo')
+ r = t._redirected_to('http://www.example.com/foo',
+ 'http://www.example.com/bar')
+ self.assertEquals(type(r), type(t))
+
+ def test__redirect_sibling_protocol(self):
+ t = remote.RemoteHTTPTransport('bzr+http://www.example.com/foo')
+ r = t._redirected_to('http://www.example.com/foo',
+ 'https://www.example.com/bar')
+ self.assertEquals(type(r), type(t))
+ self.assertStartsWith(r.base, 'bzr+https')
+
+ def test__redirect_to_with_user(self):
+ t = remote.RemoteHTTPTransport('bzr+http://joe@www.example.com/foo')
+ r = t._redirected_to('http://www.example.com/foo',
+ 'http://www.example.com/bar')
+ self.assertEquals(type(r), type(t))
+ self.assertEquals('joe', t._user)
+ self.assertEquals(t._user, r._user)
+
+ def test_redirected_to_same_host_different_protocol(self):
+ t = remote.RemoteHTTPTransport('bzr+http://joe@www.example.com/foo')
+ r = t._redirected_to('http://www.example.com/foo',
+ 'ftp://www.example.com/foo')
+ self.assertNotEquals(type(r), type(t))
+
+
# TODO: Client feature that does get_bundle and then installs that into a
# branch; this can be used in place of the regular pull/fetch operation when
# coming from a smart server.
=== modified file 'bzrlib/transport/decorator.py'
--- a/bzrlib/transport/decorator.py 2008-12-04 16:02:51 +0000
+++ b/bzrlib/transport/decorator.py 2008-12-04 17:12:46 +0000
@@ -173,6 +173,8 @@
if redirected is not None:
return self.__class__(self._get_url_prefix() + redirected.base,
redirected)
+ else:
+ return None
class DecoratorServer(Server):
=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py 2008-12-04 16:02:51 +0000
+++ b/bzrlib/transport/http/__init__.py 2008-12-04 17:12:46 +0000
@@ -412,8 +412,12 @@
def external_url(self):
"""See bzrlib.transport.Transport.external_url."""
- # HTTP URL's are externally usable.
- return self.base
+ # HTTP URL's are externally usable as long as they don't mention their
+ # implementation qualifier
+ return self._unsplit_url(self._unqualified_scheme,
+ self._user, self._password,
+ self._host, self._port,
+ self._path)
def is_readonly(self):
"""See Transport.is_readonly."""
=== modified file 'bzrlib/transport/http/_pycurl.py'
--- a/bzrlib/transport/http/_pycurl.py 2008-12-04 15:53:40 +0000
+++ b/bzrlib/transport/http/_pycurl.py 2008-12-04 17:12:46 +0000
@@ -105,9 +105,8 @@
"""
def __init__(self, base, _from_transport=None):
- super(PyCurlTransport, self).__init__(base,
- _from_transport=_from_transport,
- _impl_name='pycurl')
+ super(PyCurlTransport, self).__init__(base, 'pycurl',
+ _from_transport=_from_transport)
if self._unqualified_scheme == 'https':
# Check availability of https into pycurl supported
# protocols
=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py 2008-12-04 15:53:40 +0000
+++ b/bzrlib/transport/http/_urllib.py 2008-12-04 17:12:46 +0000
@@ -43,7 +43,7 @@
def __init__(self, base, _from_transport=None):
super(HttpTransport_urllib, self).__init__(
- base, _from_transport=_from_transport, _impl_name='urllib')
+ base, 'urllib', _from_transport=_from_transport)
if _from_transport is not None:
self._opener = _from_transport._opener
else:
=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py 2008-12-01 23:20:22 +0000
+++ b/bzrlib/transport/remote.py 2008-12-04 17:12:46 +0000
@@ -568,6 +568,17 @@
_from_transport=self,
http_transport=self._http_transport)
+ def _redirected_to(self, source, target):
+ """See transport._redirected_to"""
+ redirected = self._http_transport._redirected_to(source, target)
+ if (redirected is not None
+ and isinstance(redirected, type(self._http_transport))):
+ return RemoteHTTPTransport('bzr+' + redirected.external_url(),
+ http_transport=redirected)
+ else:
+ # Either None or a transport for a different protocol
+ return redirected
+
def get_test_permutations():
"""Return (transport, server) permutations for testing."""
More information about the bazaar-commits
mailing list