61
from bzrlib.trace import mutter, warning
61
from bzrlib.trace import (
63
67
# {prefix: [transport_classes]}
64
68
# Transports are inserted onto the list LIFO and tried in order; as a result
140
144
for factory in factory_list:
141
145
if factory.__module__ == "bzrlib.transport":
142
146
# this is a lazy load transport, because no real ones
143
# are directlry in bzrlib.transport
147
# are directly in bzrlib.transport
144
148
modules.add(factory.module)
146
150
modules.add(factory.__module__)
1053
1057
return _try_transport_factories(base, _protocol_handlers[None])[0]
1060
def do_catching_redirections(action, transport, redirected):
1061
"""Execute an action with given transport catching redirections.
1063
This is a facility provided for callers needing to follow redirections
1064
silently. The silence is relative: it is the caller responsability to
1065
inform the user about each redirection or only inform the user of a user
1066
via the exception parameter.
1068
:param action: A callable, what the caller want to do while catching
1070
:param transport: The initial transport used.
1071
:param redirected: A callable receiving the redirected transport and the
1072
RedirectRequested exception.
1074
:return: Whatever 'action' returns
1076
MAX_REDIRECTIONS = 8
1078
# If a loop occurs, there is little we can do. So we don't try to detect
1079
# them, just getting out if too much redirections occurs. The solution
1080
# is outside: where the loop is defined.
1081
for redirections in range(MAX_REDIRECTIONS):
1083
return action(transport)
1084
except errors.RedirectRequested, e:
1085
redirection_notice = '%s is%s redirected to %s' % (
1086
e.source, e.permanently, e.target)
1087
transport = redirected(transport, e, redirection_notice)
1089
# Loop exited without resolving redirect ? Either the
1090
# user has kept a very very very old reference or a loop
1091
# occurred in the redirections. Nothing we can cure here:
1092
# tell the user. Note that as the user has been informed
1093
# about each redirection (it is the caller responsibility
1094
# to do that in redirected via the provided
1095
# redirection_notice). The caller may provide more
1096
# information if needed (like what file or directory we
1097
# were trying to act upon when the redirection loop
1099
raise errors.TooManyRedirections
1056
1102
def _try_transport_factories(base, factory_list):
1057
1103
last_err = None
1058
1104
for factory in factory_list:
1178
1224
register_lazy_transport(None, 'bzrlib.transport.local', 'LocalTransport')
1179
1225
register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
1180
1226
register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
1227
# Decorated http transport
1181
1228
register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
1182
1229
'HttpTransport_urllib')
1183
1230
register_lazy_transport('https+urllib://', 'bzrlib.transport.http._urllib',
1186
1233
'PyCurlTransport')
1187
1234
register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
1188
1235
'PyCurlTransport')
1236
# Default http transports (last declared wins (if it can be imported))
1189
1237
register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
1190
1238
'HttpTransport_urllib')
1191
1239
register_lazy_transport('https://', 'bzrlib.transport.http._urllib',