43
43
_protocol_handlers[prefix] = klass
46
def _get_protocol_handlers():
47
"""Return a dictionary of prefix:transport-factories."""
48
return _protocol_handlers
51
def _set_protocol_handlers(new_handlers):
52
"""Replace the current protocol handlers dictionary.
54
WARNING this will remove all build in protocols. Use with care.
56
global _protocol_handlers
57
_protocol_handlers = new_handlers
60
def _get_transport_modules():
61
"""Return a list of the modules providing transports."""
63
for prefix, factory in _protocol_handlers.items():
64
if factory.__module__ == "bzrlib.transport":
65
# this is a lazy load transport, because no real ones
66
# are directlry in bzrlib.transport
67
modules.add(factory.module)
69
modules.add(factory.__module__)
46
73
class Transport(object):
47
74
"""This class encapsulates methods for retrieving or putting a file
48
75
from/to a storage location.
425
452
mod = __import__(module, globals(), locals(), [classname])
426
453
klass = getattr(mod, classname)
427
454
return klass(base)
455
_loader.module = module
428
456
register_transport(scheme, _loader)
476
504
result.addTest(new_test)
507
def get_transport_test_permutations(self, module):
508
"""Get the permutations module wants to have tested."""
509
return module.get_test_permutations()
479
511
def _test_permutations(self):
480
512
"""Return a list of the klass, server_factory pairs to test."""
481
from bzrlib.transport.local import (LocalTransport,
486
from bzrlib.transport.sftp import (SFTPTransport,
489
SFTPSiblingAbsoluteServer,
491
from bzrlib.transport.http import (HttpTransport,
494
from bzrlib.transport.ftp import FtpTransport
495
from bzrlib.transport.memory import (MemoryTransport,
498
return [(LocalTransport, LocalRelpathServer),
499
(LocalTransport, LocalAbspathServer),
500
(LocalTransport, LocalURLServer),
501
(SFTPTransport, SFTPAbsoluteServer),
502
(SFTPTransport, SFTPHomeDirServer),
503
(SFTPTransport, SFTPSiblingAbsoluteServer),
504
(HttpTransport, HttpServer),
505
(MemoryTransport, MemoryServer),
514
for module in _get_transport_modules():
515
result.extend(self.get_transport_test_permutations(reduce(getattr,
516
(module).split('.')[1:],
517
__import__(module))))
509
521
# None is the default transport, for things with no url scheme
514
526
register_lazy_transport('https://', 'bzrlib.transport.http', 'HttpTransport')
515
527
register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
516
528
register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
529
register_lazy_transport('memory://', 'bzrlib.transport.memory', 'MemoryTransport')