~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2007-03-01 21:26:57 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-20070301212657-bclmihdfnxgfy0sw
Take Aaron's review comments into account.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPRedirectHandler.http_error_301): Fix bug #88780.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._get): Fix doc string.

* bzrlib/transport/__init__.py:
(do_catching_redirections): Raise TooManyRedirections instead of
requiring an exception as a parameter.

* bzrlib/tests/test_http.py:
(TestHTTPRedirections.setUp): Simplified.
(TestHTTPRedirections.test_read_redirected_bundle_from_url): New test.
(TestDoCatchRedirections): New tests.

* bzrlib/tests/HTTPTestUtil.py:
(TestCaseWithRedirectedWebserver): New class factored out from
test_http.TestHTTPRedirections.

* bzrlib/errors.py:
(TooManyRedirections): New exception.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport.redirected): Catch TooManyRedirections.

* bzrlib/bundle/__init__.py:
(read_bundle_from_url.redirected_transport): Catch TooManyRedirections.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1048
1048
    return _try_transport_factories(base, _protocol_handlers[None])[0]
1049
1049
 
1050
1050
 
1051
 
def do_catching_redirections(action, transport, redirected, exception):
 
1051
def do_catching_redirections(action, transport, redirected):
1052
1052
    """Execute an action with given transport catching redirections.
1053
1053
 
1054
1054
    This is a facility provided for callers needing to follow redirections
1067
1067
    """
1068
1068
    MAX_REDIRECTIONS = 8
1069
1069
 
1070
 
    t = transport
1071
1070
    # If a loop occurs, there is little we can do. So we don't try to detect
1072
1071
    # them, just getting out if too much redirections occurs. The solution
1073
1072
    # is outside: where the loop is defined.
1074
1073
    for redirections in range(MAX_REDIRECTIONS):
1075
1074
        try:
1076
 
            return action(t)
 
1075
            return action(transport)
1077
1076
        except errors.RedirectRequested, e:
1078
1077
            redirection_notice = '%s is%s redirected to %s' % (
1079
 
                e.get_source_url(), e.permanently, e.get_target_url())
1080
 
            t = redirected(t, e, redirection_notice)
 
1078
                e.source, e.permanently, e.target)
 
1079
            transport = redirected(transport, e, redirection_notice)
1081
1080
    else:
1082
 
        # Loop exited without resolving redirect ? Either the user has kept
1083
 
        # a very very very old reference or a loop occured in the
1084
 
        # redirections.  Nothing we can cure here: tell the user. Note that
1085
 
        # as the user has been informed about each redirection (it is the
1086
 
        # caller responsibility to do that in redirected via the provided
1087
 
        # redirection_notice), there is no need to issue an additional error
1088
 
        # message.
1089
 
        raise exception
 
1081
        # Loop exited without resolving redirect ? Either the
 
1082
        # user has kept a very very very old reference or a loop
 
1083
        # occured in the redirections.  Nothing we can cure here:
 
1084
        # tell the user. Note that as the user has been informed
 
1085
        # about each redirection (it is the caller responsibility
 
1086
        # to do that in redirected via the provided
 
1087
        # redirection_notice). The caller may provide more
 
1088
        # informations if needed (like what file or directory we
 
1089
        # were trying to act upon when the redirection loop
 
1090
        # occured).
 
1091
        raise errors.TooManyRedirections
1090
1092
 
1091
1093
 
1092
1094
def _try_transport_factories(base, factory_list):