Rev 3883: Don't use the exception as a parameter for _redirected_to. in lp:~vila/bzr/303959-redirection
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Dec 4 16:03:02 GMT 2008
At lp:~vila/bzr/303959-redirection
------------------------------------------------------------
revno: 3883
revision-id: v.ladeuil+lp at free.fr-20081204160251-37f920alwn9t0i4p
parent: v.ladeuil+lp at free.fr-20081204155340-atj2k9w0cbcuob2k
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 303959-redirection
timestamp: Thu 2008-12-04 17:02:51 +0100
message:
Don't use the exception as a parameter for _redirected_to.
* bzrlib/transport/http/__init__.py:
(HttpTransportBase._redirected_to): Update prototype.
* bzrlib/transport/decorator.py:
(TransportDecorator._redirected_to): Update prototype.
* bzrlib/tests/blackbox/test_push.py:
(RedirectingMemoryTransport): Update prototype.
modified:
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/push.py push.py-20080606021927-5fe39050e8xne9un-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
bzrlib/transport/decorator.py decorator.py-20060402223305-e913a0f25319ab42
bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
-------------- next part --------------
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2008-12-03 16:40:38 +0000
+++ b/bzrlib/bzrdir.py 2008-12-04 16:02:51 +0000
@@ -781,7 +781,7 @@
transport, _server_formats=_server_formats)
def redirected(transport, e, redirection_notice):
- redirected_transport = transport._redirected_to(e)
+ redirected_transport = transport._redirected_to(e.source, e.target)
if redirected_transport is None:
raise errors.NotBranchError(base)
note('%s is%s redirected to %s',
=== modified file 'bzrlib/push.py'
--- a/bzrlib/push.py 2008-12-04 15:53:40 +0000
+++ b/bzrlib/push.py 2008-12-04 16:02:51 +0000
@@ -76,7 +76,7 @@
def redirected(transport, e, redirection_notice):
note(redirection_notice)
- return transport._redirected_to(e)
+ return transport._redirected_to(e.source, e.target)
try:
to_transport = transport.do_catching_redirections(
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2008-12-04 15:53:40 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2008-12-04 16:02:51 +0000
@@ -368,9 +368,9 @@
return super(RedirectingMemoryTransport, self).mkdir(
relpath, mode)
- def _redirected_to(self, exception):
+ def _redirected_to(self, source, target):
# We do accept redirections
- return transport.get_transport(exception.target)
+ return transport.get_transport(target)
class RedirectingMemoryServer(MemoryServer):
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2008-12-04 15:53:40 +0000
+++ b/bzrlib/tests/test_http.py 2008-12-04 16:02:51 +0000
@@ -1748,18 +1748,16 @@
def test_redirected_to_subdir(self):
t = self._transport('http://www.example.com/foo')
- e = errors.RedirectRequested('http://www.example.com/foo',
- 'http://www.example.com/foo/subdir')
- r = t._redirected_to(e)
+ r = t._redirected_to('http://www.example.com/foo',
+ 'http://www.example.com/foo/subdir')
self.assertIsInstance(r, type(t))
# Both transports share the some connection
self.assertEquals(t._get_connection(), r._get_connection())
def test_redirected_to_self_with_slash(self):
t = self._transport('http://www.example.com/foo')
- e = errors.RedirectRequested('http://www.example.com/foo',
- 'http://www.example.com/foo/')
- r = t._redirected_to(e)
+ r = t._redirected_to('http://www.example.com/foo',
+ 'http://www.example.com/foo/')
self.assertIsInstance(r, type(t))
# Both transports share the some connection (one can argue that we
# should return the exact same transport here, but that seems
@@ -1768,30 +1766,25 @@
def test_redirected_to_host(self):
t = self._transport('http://www.example.com/foo')
- e = errors.RedirectRequested('http://www.example.com/foo',
- 'http://foo.example.com/foo/subdir',
- self._qualified_prefix)
- r = t._redirected_to(e)
+ r = t._redirected_to('http://www.example.com/foo',
+ 'http://foo.example.com/foo/subdir')
self.assertIsInstance(r, type(t))
def test_redirected_to_same_host_sibling_protocol(self):
t = self._transport('http://www.example.com/foo')
- e = errors.RedirectRequested('http://www.example.com/foo',
- 'https://www.example.com/foo')
- r = t._redirected_to(e)
+ r = t._redirected_to('http://www.example.com/foo',
+ 'https://www.example.com/foo')
self.assertIsInstance(r, type(t))
def test_redirected_to_same_host_different_protocol(self):
t = self._transport('http://www.example.com/foo')
- e = errors.RedirectRequested('http://www.example.com/foo',
- 'ftp://www.example.com/foo')
- r = t._redirected_to(e)
+ r = t._redirected_to('http://www.example.com/foo',
+ 'ftp://www.example.com/foo')
self.assertNotEquals(type(r), type(t))
def test_redirected_to_different_host_same_user(self):
t = self._transport('http://joe@www.example.com/foo')
- e = errors.RedirectRequested('http://www.example.com/foo',
- 'https://foo.example.com/foo')
- r = t._redirected_to(e)
+ r = t._redirected_to('http://www.example.com/foo',
+ 'https://foo.example.com/foo')
self.assertIsInstance(r, type(t))
self.assertEquals(t._user, r._user)
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2008-12-03 16:40:38 +0000
+++ b/bzrlib/transport/__init__.py 2008-12-04 16:02:51 +0000
@@ -1249,10 +1249,11 @@
# should be asked to ConnectedTransport only.
return None
- def _redirected_to(self, exception):
+ def _redirected_to(self, source, target):
"""Returns a transport suitable to re-issue a redirected request.
- :param exception: A RedirectRequested exception.
+ :param source: The source url as returned by the server.
+ :param target: The target url as returned by the server.
The redirection can be handled only if the relpath involved is not
renamed by the redirection.
=== modified file 'bzrlib/transport/decorator.py'
--- a/bzrlib/transport/decorator.py 2008-12-03 16:40:38 +0000
+++ b/bzrlib/transport/decorator.py 2008-12-04 16:02:51 +0000
@@ -168,8 +168,8 @@
"""See Transport.lock_write."""
return self._decorated.lock_write(relpath)
- def _redirected_to(self, exception):
- redirected = self._decorated._redirected_to(exception)
+ def _redirected_to(self, source, target):
+ redirected = self._decorated._redirected_to(source, target)
if redirected is not None:
return self.__class__(self._get_url_prefix() + redirected.base,
redirected)
=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py 2008-12-04 11:25:56 +0000
+++ b/bzrlib/transport/http/__init__.py 2008-12-04 16:02:51 +0000
@@ -504,10 +504,11 @@
return ','.join(strings)
- def _redirected_to(self, exception):
+ def _redirected_to(self, source, target):
"""Returns a transport suitable to re-issue a redirected request.
- :param exception: A RedirectRequested exception.
+ :param source: The source url as returned by the server.
+ :param target: The target url as returned by the server.
The redirection can be handled only if the relpath involved is not
renamed by the redirection.
@@ -530,8 +531,8 @@
pl = len(self._path)
return path[pl:].strip('/')
- relpath = relpath(exception.source)
- if not exception.target.endswith(relpath):
+ relpath = relpath(source)
+ if not target.endswith(relpath):
# The final part of the url has been renamed, we can't handle the
# redirection.
return None
@@ -539,7 +540,7 @@
(scheme,
user, password,
host, port,
- path) = self._split_url(exception.target)
+ path) = self._split_url(target)
# Recalculate base path. This is needed to ensure that when the
# redirected tranport will be used to re-try whatever request was
# redirected, we end up with the same url
More information about the bazaar-commits
mailing list