/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

Upgraded to the latest 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
from bzrlib import registry
63
67
 
 
68
 
64
69
def _get_protocol_handlers():
65
70
    """Return a dictionary of {urlprefix: [factory]}"""
66
71
    return transport_list_registry
87
92
        for factory in factory_list:
88
93
            if hasattr(factory, "_module_name"):
89
94
                modules.add(factory._module_name)
 
95
<Merge Conflict>
 
96
 
90
97
            else:
91
98
                modules.add(factory._obj.__module__)
92
99
    # Add chroot directly, because there is not handler registered for it.
406
413
        This function will only be defined for Transports which have a
407
414
        physical local filesystem representation.
408
415
        """
409
 
        # TODO: jam 20060426 Should this raise NotLocalUrl instead?
410
 
        raise errors.TransportNotPossible('This is not a LocalTransport,'
411
 
            ' so there is no local representation for a path')
 
416
        raise errors.NotLocalUrl(self.abspath(relpath))
 
417
 
412
418
 
413
419
    def has(self, relpath):
414
420
        """Does the file relpath exist?
621
627
        :param mode: Create the file with the given mode.
622
628
        :return: None
623
629
        """
624
 
        assert isinstance(bytes, str), \
625
 
            'bytes must be a plain string, not %s' % type(bytes)
 
630
        if not isinstance(bytes, str):
 
631
            raise AssertionError(
 
632
                'bytes must be a plain string, not %s' % type(bytes))
626
633
        return self.put_file(relpath, StringIO(bytes), mode=mode)
627
634
 
628
635
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
643
650
                        create it, and then try again.
644
651
        :param dir_mode: Possible access permissions for new directories.
645
652
        """
646
 
        assert isinstance(bytes, str), \
647
 
            'bytes must be a plain string, not %s' % type(bytes)
 
653
        if not isinstance(bytes, str):
 
654
            raise AssertionError(
 
655
                'bytes must be a plain string, not %s' % type(bytes))
648
656
        self.put_file_non_atomic(relpath, StringIO(bytes), mode=mode,
649
657
                                 create_parent_dir=create_parent_dir,
650
658
                                 dir_mode=dir_mode)
1022
1030
 
1023
1031
    base is either a URL or a directory name.  
1024
1032
    """
 
1033
 
1025
1034
    if base is None:
1026
1035
        base = '.'
1027
1036
    last_err = None
1059
1068
    return _try_transport_factories(base,
1060
1069
                    transport_list_registry.get(None))[0]
1061
1070
                                                   
 
1071
def do_catching_redirections(action, transport, redirected):
 
1072
    """Execute an action with given transport catching redirections.
 
1073
 
 
1074
    This is a facility provided for callers needing to follow redirections
 
1075
    silently. The silence is relative: it is the caller responsability to
 
1076
    inform the user about each redirection or only inform the user of a user
 
1077
    via the exception parameter.
 
1078
 
 
1079
    :param action: A callable, what the caller want to do while catching
 
1080
                  redirections.
 
1081
    :param transport: The initial transport used.
 
1082
    :param redirected: A callable receiving the redirected transport and the 
 
1083
                  RedirectRequested exception.
 
1084
 
 
1085
    :return: Whatever 'action' returns
 
1086
    """
 
1087
    MAX_REDIRECTIONS = 8
 
1088
 
 
1089
    # If a loop occurs, there is little we can do. So we don't try to detect
 
1090
    # them, just getting out if too much redirections occurs. The solution
 
1091
    # is outside: where the loop is defined.
 
1092
    for redirections in range(MAX_REDIRECTIONS):
 
1093
        try:
 
1094
            return action(transport)
 
1095
        except errors.RedirectRequested, e:
 
1096
            redirection_notice = '%s is%s redirected to %s' % (
 
1097
                e.source, e.permanently, e.target)
 
1098
            transport = redirected(transport, e, redirection_notice)
 
1099
    else:
 
1100
        # Loop exited without resolving redirect ? Either the
 
1101
        # user has kept a very very very old reference or a loop
 
1102
        # occurred in the redirections.  Nothing we can cure here:
 
1103
        # tell the user. Note that as the user has been informed
 
1104
        # about each redirection (it is the caller responsibility
 
1105
        # to do that in redirected via the provided
 
1106
        # redirection_notice). The caller may provide more
 
1107
        # information if needed (like what file or directory we
 
1108
        # were trying to act upon when the redirection loop
 
1109
        # occurred).
 
1110
        raise errors.TooManyRedirections
 
1111
 
1062
1112
 
1063
1113
def _try_transport_factories(base, factory_list):
1064
1114
    last_err = None
1180
1230
        self._calls.append((name, offsets))
1181
1231
        return self._adapted.readv(name, offsets)
1182
1232
 
 
1233
 
1183
1234
# None is the default transport, for things with no url scheme
1184
1235
register_transport_proto('file://')
1185
1236
register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
1187
1238
 
1188
1239
register_transport_proto('sftp://')
1189
1240
register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
1190
 
 
 
1241
# Decorated http transport
1191
1242
register_transport_proto('http+urllib://')
1192
1243
register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
1193
1244
                        'HttpTransport_urllib')
1200
1251
register_transport_proto('https+pycurl://')
1201
1252
register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
1202
1253
                        'PyCurlTransport')
 
1254
# Default http transports (last declared wins (if it can be imported))
1203
1255
register_transport_proto('http://')
1204
1256
register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
1205
1257
                        'HttpTransport_urllib')
1217
1269
register_transport_proto('memory://')
1218
1270
register_lazy_transport('memory://', 'bzrlib.transport.memory', 'MemoryTransport')
1219
1271
register_transport_proto('chroot+')
1220
 
register_lazy_transport('chroot+', 'bzrlib.transport.chroot',
1221
 
                        'ChrootTransportDecorator')
 
1272
 
1222
1273
register_transport_proto('readonly+')
1223
1274
register_lazy_transport('readonly+', 'bzrlib.transport.readonly', 'ReadonlyTransportDecorator')
1224
1275
register_transport_proto('fakenfs+')
1229
1280
                        'FakeVFATTransportDecorator')
1230
1281
register_transport_proto('bzr://')
1231
1282
register_lazy_transport('bzr://',
1232
 
                        'bzrlib.transport.smart',
1233
 
                        'SmartTCPTransport')
 
1283
                        'bzrlib.transport.remote',
 
1284
                        'RemoteTCPTransport')
1234
1285
register_transport_proto('bzr+http://')
1235
1286
register_lazy_transport('bzr+http://',
1236
 
                        'bzrlib.transport.smart',
1237
 
                        'SmartHTTPTransport')
 
1287
                        'bzrlib.transport.remote',
 
1288
                        'RemoteHTTPTransport')
1238
1289
register_transport_proto('bzr+ssh://')
1239
1290
register_lazy_transport('bzr+ssh://',
1240
 
                        'bzrlib.transport.smart',
1241
 
                        'SmartSSHTransport')
 
1291
                        'bzrlib.transport.remote',
 
1292
                        'RemoteSSHTransport')