/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Robert Collins
  • Date: 2007-04-04 05:19:38 UTC
  • mfrom: (2395 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2401.
  • Revision ID: robertc@robertcollins.net-20070404051938-2lnvpsm2tbo5a6g2
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        zero_eight,
59
59
        zero_eleven,
60
60
        )
61
 
from bzrlib.trace import mutter, warning
 
61
from bzrlib.trace import (
 
62
    note,
 
63
    mutter,
 
64
    warning,
 
65
    )
62
66
 
63
67
# {prefix: [transport_classes]}
64
68
# Transports are inserted onto the list LIFO and tried in order; as a result
107
111
    register_transport(scheme, _loader)
108
112
 
109
113
 
 
114
def unregister_transport(scheme, factory):
 
115
    """Unregister a transport."""
 
116
    _protocol_handlers[scheme].remove(factory)
 
117
    if _protocol_handlers[scheme] == []:
 
118
        del _protocol_handlers[scheme]
 
119
 
 
120
 
110
121
def _get_protocol_handlers():
111
122
    """Return a dictionary of {urlprefix: [factory]}"""
112
123
    return _protocol_handlers
133
144
        for factory in factory_list:
134
145
            if factory.__module__ == "bzrlib.transport":
135
146
                # this is a lazy load transport, because no real ones
136
 
                # are directlry in bzrlib.transport
 
147
                # are directly in bzrlib.transport
137
148
                modules.add(factory.module)
138
149
            else:
139
150
                modules.add(factory.__module__)
 
151
    # Add chroot directly, because there is not handler registered for it.
 
152
    modules.add('bzrlib.transport.chroot')
140
153
    result = list(modules)
141
154
    result.sort()
142
155
    return result
1044
1057
    return _try_transport_factories(base, _protocol_handlers[None])[0]
1045
1058
 
1046
1059
 
 
1060
def do_catching_redirections(action, transport, redirected):
 
1061
    """Execute an action with given transport catching redirections.
 
1062
 
 
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.
 
1067
 
 
1068
    :param action: A callable, what the caller want to do while catching
 
1069
                  redirections.
 
1070
    :param transport: The initial transport used.
 
1071
    :param redirected: A callable receiving the redirected transport and the 
 
1072
                  RedirectRequested exception.
 
1073
 
 
1074
    :return: Whatever 'action' returns
 
1075
    """
 
1076
    MAX_REDIRECTIONS = 8
 
1077
 
 
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):
 
1082
        try:
 
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)
 
1088
    else:
 
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
 
1098
        # occurred).
 
1099
        raise errors.TooManyRedirections
 
1100
 
 
1101
 
1047
1102
def _try_transport_factories(base, factory_list):
1048
1103
    last_err = None
1049
1104
    for factory in factory_list:
1089
1144
        raise NotImplementedError
1090
1145
 
1091
1146
    def get_bogus_url(self):
1092
 
        """Return a url for this protocol, that will fail to connect."""
 
1147
        """Return a url for this protocol, that will fail to connect.
 
1148
        
 
1149
        This may raise NotImplementedError to indicate that this server cannot
 
1150
        provide bogus urls.
 
1151
        """
1093
1152
        raise NotImplementedError
1094
1153
 
1095
1154
 
1165
1224
register_lazy_transport(None, 'bzrlib.transport.local', 'LocalTransport')
1166
1225
register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
1167
1226
register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
 
1227
# Decorated http transport
1168
1228
register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
1169
1229
                        'HttpTransport_urllib')
1170
1230
register_lazy_transport('https+urllib://', 'bzrlib.transport.http._urllib',
1173
1233
                        'PyCurlTransport')
1174
1234
register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
1175
1235
                        'PyCurlTransport')
 
1236
# Default http transports (last declared wins (if it can be imported))
1176
1237
register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
1177
1238
                        'HttpTransport_urllib')
1178
1239
register_lazy_transport('https://', 'bzrlib.transport.http._urllib',