1048
1048
return _try_transport_factories(base, _protocol_handlers[None])[0]
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.
1054
1054
This is a facility provided for callers needing to follow redirections
1068
1068
MAX_REDIRECTIONS = 8
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
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)
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
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
1091
raise errors.TooManyRedirections
1092
1094
def _try_transport_factories(base, factory_list):