128
120
self.get(key).insert(0,
129
121
registry._LazyObjectGetter(module_name, member_name))
131
def register_transport(self, key, help=None, default_port=None):
132
self.register(key, [], help, default_port)
123
def register_transport(self, key, help=None):
124
self.register(key, [], help)
134
126
def set_default_transport(self, key=None):
135
127
"""Return either 'key' or the default key if key is None"""
136
128
self._default_key = key
138
def get_default_port(self, scheme):
139
"""Return the registered default port for this protocol scheme."""
141
return self.get_info(scheme + '://')
146
131
transport_list_registry = TransportListRegistry()
149
def register_transport_proto(prefix, help=None, info=None, default_port=None):
150
transport_list_registry.register_transport(prefix, help, default_port)
134
def register_transport_proto(prefix, help=None, info=None,
135
register_netloc=False):
136
transport_list_registry.register_transport(prefix, help)
138
assert prefix.endswith('://')
139
register_urlparse_netloc_protocol(prefix[:-3])
153
142
def register_lazy_transport(prefix, module, classname):
664
659
if adjust_for_latency:
665
660
# Design note: We may wish to have different algorithms for the
666
661
# expansion of the offsets per-transport. E.g. for local disk to
667
# use page-aligned expansion. If that is the case consider the following structure:
668
# - a test that transport.readv uses self._offset_expander or some similar attribute, to do the expansion
669
# - a test for each transport that it has some known-good offset expander
662
# use page-aligned expansion. If that is the case consider the
663
# following structure:
664
# - a test that transport.readv uses self._offset_expander or some
665
# similar attribute, to do the expansion
666
# - a test for each transport that it has some known-good offset
670
668
# - unit tests for each offset expander
671
669
# - a set of tests for the offset expander interface, giving
672
670
# baseline behaviour (which the current transport
797
795
Turns [(15, 10), (25, 10)] => [(15, 20, [(0, 10), (10, 10)])]
799
797
:param offsets: A list of (start, length) pairs
800
:param limit: Only combine a maximum of this many pairs
801
Some transports penalize multiple reads more than
802
others, and sometimes it is better to return early.
799
:param limit: Only combine a maximum of this many pairs Some transports
800
penalize multiple reads more than others, and sometimes it is
801
better to return early.
804
804
:param fudge_factor: All transports have some level of 'it is
805
805
better to read some more data and throw it away rather
806
806
than seek', so collapse if we are 'close enough'
808
:param max_size: Create coalesced offsets no bigger than this size.
809
When a single offset is bigger than 'max_size', it will keep
810
its size and be alone in the coalesced offset.
811
0 means no maximum size.
807
813
:return: yield _CoalescedOffset objects, which have members for where
808
814
to start, how much to read, and how to split those
1389
1396
# have one so that it doesn't get accidentally
1391
1398
netloc = '%s@%s' % (urllib.quote(user), netloc)
1392
if (port is not None and
1393
port != transport_list_registry.get_default_port(scheme)):
1394
# Include the port in the netloc (unless it's the same as the
1395
# default, in which case we omit it as it is redundant).
1399
if port is not None:
1396
1400
netloc = '%s:%d' % (netloc, port)
1397
1401
path = urllib.quote(path)
1398
1402
return urlparse.urlunparse((scheme, netloc, path, None, None, None))
1707
1720
register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
1708
1721
transport_list_registry.set_default_transport("file://")
1710
# Note that sftp:// has no default_port, because the user's ~/.ssh/config
1711
# can set it to arbitrary values based on hostname.
1712
1723
register_transport_proto('sftp://',
1713
help="Access using SFTP (most SSH servers provide SFTP).")
1724
help="Access using SFTP (most SSH servers provide SFTP).",
1725
register_netloc=True)
1714
1726
register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
1715
1727
# Decorated http transport
1716
1728
register_transport_proto('http+urllib://',
1717
1729
# help="Read-only access of branches exported on the web."
1730
register_netloc=True)
1719
1731
register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
1720
1732
'HttpTransport_urllib')
1721
1733
register_transport_proto('https+urllib://',
1722
1734
# help="Read-only access of branches exported on the web using SSL."
1735
register_netloc=True)
1724
1736
register_lazy_transport('https+urllib://', 'bzrlib.transport.http._urllib',
1725
1737
'HttpTransport_urllib')
1726
1738
register_transport_proto('http+pycurl://',
1727
1739
# help="Read-only access of branches exported on the web."
1740
register_netloc=True)
1729
1741
register_lazy_transport('http+pycurl://', 'bzrlib.transport.http._pycurl',
1730
1742
'PyCurlTransport')
1731
1743
register_transport_proto('https+pycurl://',
1732
1744
# help="Read-only access of branches exported on the web using SSL."
1745
register_netloc=True)
1734
1746
register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
1735
1747
'PyCurlTransport')
1736
1748
# Default http transports (last declared wins (if it can be imported))
1737
1749
register_transport_proto('http://',
1738
help="Read-only access of branches exported on the web.",
1750
help="Read-only access of branches exported on the web.")
1740
1751
register_transport_proto('https://',
1741
help="Read-only access of branches exported on the web using SSL.",
1752
help="Read-only access of branches exported on the web using SSL.")
1743
1753
register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
1744
1754
'HttpTransport_urllib')
1745
1755
register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
1746
1756
'HttpTransport_urllib')
1747
register_lazy_transport('http://', 'bzrlib.transport.http._pycurl', 'PyCurlTransport')
1748
register_lazy_transport('https://', 'bzrlib.transport.http._pycurl', 'PyCurlTransport')
1757
register_lazy_transport('http://', 'bzrlib.transport.http._pycurl',
1759
register_lazy_transport('https://', 'bzrlib.transport.http._pycurl',
1750
register_transport_proto('ftp://',
1751
help="Access using passive FTP.",
1762
register_transport_proto('ftp://', help="Access using passive FTP.")
1753
1763
register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
1754
register_transport_proto('aftp://',
1755
help="Access using active FTP.",
1764
register_transport_proto('aftp://', help="Access using active FTP.")
1757
1765
register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
1759
1767
register_transport_proto('memory://')
1760
register_lazy_transport('memory://', 'bzrlib.transport.memory', 'MemoryTransport')
1768
register_lazy_transport('memory://', 'bzrlib.transport.memory',
1762
1771
# chroots cannot be implicitly accessed, they must be explicitly created:
1763
1772
register_transport_proto('chroot+')
1765
1774
register_transport_proto('readonly+',
1766
1775
# help="This modifier converts any transport to be readonly."
1768
register_lazy_transport('readonly+', 'bzrlib.transport.readonly', 'ReadonlyTransportDecorator')
1777
register_lazy_transport('readonly+', 'bzrlib.transport.readonly',
1778
'ReadonlyTransportDecorator')
1770
1780
register_transport_proto('fakenfs+')
1771
register_lazy_transport('fakenfs+', 'bzrlib.transport.fakenfs', 'FakeNFSTransportDecorator')
1781
register_lazy_transport('fakenfs+', 'bzrlib.transport.fakenfs',
1782
'FakeNFSTransportDecorator')
1773
1784
register_transport_proto('trace+')
1774
register_lazy_transport('trace+', 'bzrlib.transport.trace', 'TransportTraceDecorator')
1785
register_lazy_transport('trace+', 'bzrlib.transport.trace',
1786
'TransportTraceDecorator')
1776
1788
register_transport_proto('unlistable+')
1777
register_lazy_transport('unlistable+', 'bzrlib.transport.unlistable', 'UnlistableTransportDecorator')
1789
register_lazy_transport('unlistable+', 'bzrlib.transport.unlistable',
1790
'UnlistableTransportDecorator')
1779
1792
register_transport_proto('brokenrename+')
1780
1793
register_lazy_transport('brokenrename+', 'bzrlib.transport.brokenrename',
1781
'BrokenRenameTransportDecorator')
1794
'BrokenRenameTransportDecorator')
1783
1796
register_transport_proto('vfat+')
1784
1797
register_lazy_transport('vfat+',
1785
1798
'bzrlib.transport.fakevfat',
1786
1799
'FakeVFATTransportDecorator')
1801
register_transport_proto('nosmart+')
1802
register_lazy_transport('nosmart+', 'bzrlib.transport.nosmart',
1803
'NoSmartTransportDecorator')
1805
# These two schemes were registered, but don't seem to have an actual transport
1806
# protocol registered
1807
for scheme in ['ssh', 'bzr+loopback']:
1808
register_urlparse_netloc_protocol(scheme)
1787
1811
register_transport_proto('bzr://',
1788
1812
help="Fast access using the Bazaar smart server.",
1813
register_netloc=True)
1791
register_lazy_transport('bzr://',
1792
'bzrlib.transport.remote',
1815
register_lazy_transport('bzr://', 'bzrlib.transport.remote',
1793
1816
'RemoteTCPTransport')
1794
1817
register_transport_proto('bzr+http://',
1795
1818
# help="Fast access using the Bazaar smart server over HTTP."
1797
register_lazy_transport('bzr+http://',
1798
'bzrlib.transport.remote',
1819
register_netloc=True)
1820
register_lazy_transport('bzr+http://', 'bzrlib.transport.remote',
1799
1821
'RemoteHTTPTransport')
1800
1822
register_transport_proto('bzr+https://',
1801
1823
# help="Fast access using the Bazaar smart server over HTTPS."
1824
register_netloc=True)
1803
1825
register_lazy_transport('bzr+https://',
1804
1826
'bzrlib.transport.remote',
1805
1827
'RemoteHTTPTransport')
1806
# Note that bzr+ssh:// has no default_port, because the user's ~/.ssh/config
1807
# can set it to arbitrary values based on hostname.
1808
1828
register_transport_proto('bzr+ssh://',
1809
help="Fast access using the Bazaar smart server over SSH.")
1810
register_lazy_transport('bzr+ssh://',
1811
'bzrlib.transport.remote',
1829
help="Fast access using the Bazaar smart server over SSH.",
1830
register_netloc=True)
1831
register_lazy_transport('bzr+ssh://', 'bzrlib.transport.remote',
1812
1832
'RemoteSSHTransport')