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__)
1052
1056
return _try_transport_factories(base, _protocol_handlers[None])[0]
1059
def do_catching_redirections(action, transport, redirected):
1060
"""Execute an action with given transport catching redirections.
1062
This is a facility provided for callers needing to follow redirections
1063
silently. The silence is relative: it is the caller responsability to
1064
inform the user about each redirection or only inform the user of a user
1065
via the exception parameter.
1067
:param action: A callable, what the caller want to do while catching
1069
:param transport: The initial transport used.
1070
:param redirected: A callable receiving the redirected transport and the
1071
RedirectRequested exception.
1073
:return: Whatever 'action' returns
1075
MAX_REDIRECTIONS = 8
1077
# If a loop occurs, there is little we can do. So we don't try to detect
1078
# them, just getting out if too much redirections occurs. The solution
1079
# is outside: where the loop is defined.
1080
for redirections in range(MAX_REDIRECTIONS):
1082
return action(transport)
1083
except errors.RedirectRequested, e:
1084
redirection_notice = '%s is%s redirected to %s' % (
1085
e.source, e.permanently, e.target)
1086
transport = redirected(transport, e, redirection_notice)
1088
# Loop exited without resolving redirect ? Either the
1089
# user has kept a very very very old reference or a loop
1090
# occurred in the redirections. Nothing we can cure here:
1091
# tell the user. Note that as the user has been informed
1092
# about each redirection (it is the caller responsibility
1093
# to do that in redirected via the provided
1094
# redirection_notice). The caller may provide more
1095
# information if needed (like what file or directory we
1096
# were trying to act upon when the redirection loop
1098
raise errors.TooManyRedirections
1055
1101
def _try_transport_factories(base, factory_list):
1056
1102
last_err = None
1057
1103
for factory in factory_list:
1177
1223
register_lazy_transport(None, 'bzrlib.transport.local', 'LocalTransport')
1178
1224
register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
1179
1225
register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
1226
# Decorated http transport
1180
1227
register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
1181
1228
'HttpTransport_urllib')
1182
1229
register_lazy_transport('https+urllib://', 'bzrlib.transport.http._urllib',
1185
1232
'PyCurlTransport')
1186
1233
register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
1187
1234
'PyCurlTransport')
1235
# Default http transports (last declared wins (if it can be imported))
1188
1236
register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
1189
1237
'HttpTransport_urllib')
1190
1238
register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
1201
1249
'FakeVFATTransportDecorator')
1202
1250
register_lazy_transport('bzr://',
1203
1251
'bzrlib.transport.remote',
1204
'SmartTCPTransport')
1252
'RemoteTCPTransport')
1205
1253
register_lazy_transport('bzr+http://',
1206
1254
'bzrlib.transport.remote',
1207
'SmartHTTPTransport')
1255
'RemoteHTTPTransport')
1208
1256
register_lazy_transport('bzr+ssh://',
1209
1257
'bzrlib.transport.remote',
1210
'SmartSSHTransport')
1258
'RemoteSSHTransport')