Rev 2482: Cherry-pick from bug #111702 fix. in file:///v/home/vila/src/experimental/bzr.reuse.transports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri May 4 16:33:29 BST 2007
At file:///v/home/vila/src/experimental/bzr.reuse.transports/
------------------------------------------------------------
revno: 2482
revision-id: v.ladeuil+lp at free.fr-20070504153326-a71s8jtpww8ed0nx
parent: pqm at pqm.ubuntu.com-20070504034556-wzcw478l7qkppkq0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: bzr.reuse.transports
timestamp: Fri 2007-05-04 17:33:26 +0200
message:
Cherry-pick from bug #111702 fix.
modified:
bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
bzrlib/transport/ftp.py ftp.py-20051116161804-58dc9506548c2a53
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
bzrlib/transport/sftp.py sftp.py-20051019050329-ab48ce71b7e32dfe
-------------- next part --------------
=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py 2007-04-26 09:07:38 +0000
+++ b/bzrlib/tests/test_transport.py 2007-05-04 15:33:26 +0000
@@ -592,3 +592,16 @@
# make sure we reach the root
t = t.clone('..')
self.assertEquals(t.base, 'file://HOST/')
+
+
+class TestReusedTransports(TestCase):
+
+ def test_reuse_same_transport(self):
+ t = get_transport('http://foo/')
+ t2 = get_transport('http://foo/', possible_transports=[t])
+ self.assertIs(t, t2)
+
+ def test_don_t_reuse_different_transport(self):
+ t = get_transport('http://foo/')
+ t2 = get_transport('http://bar/', possible_transports=[t])
+ self.assertIsNot(t, t2)
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-05-02 14:36:55 +0000
+++ b/bzrlib/transport/__init__.py 2007-05-04 15:33:26 +0000
@@ -1038,13 +1038,12 @@
urlunescape = urlutils.unescape
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<path>.*)$')
-
-def get_transport(base):
+def get_transport(base, possible_transports=None):
"""Open a transport to access a URL or directory.
- base is either a URL or a directory name.
+ :param base: either a URL or a directory name.
+ :param transports: optional reusable transports list.
"""
-
if base is None:
base = '.'
last_err = None
@@ -1067,21 +1066,32 @@
# Only local paths can be Unicode
base = convert_path_to_url(base,
'URLs must be properly escaped (protocol: %s)')
-
- for proto, factory_list in transport_list_registry.iteritems():
- if proto is not None and base.startswith(proto):
- t, last_err = _try_transport_factories(base, factory_list)
- if t:
- return t
-
- # We tried all the different protocols, now try one last time
- # as a local protocol
- base = convert_path_to_url(base, 'Unsupported protocol: %s')
-
- # The default handler is the filesystem handler, stored as protocol None
- return _try_transport_factories(base,
- transport_list_registry.get(None))[0]
-
+
+ transport = None
+ if possible_transports:
+ for t in possible_transports:
+ if t.base == base:
+ transport = t
+ break
+ if transport is None:
+ for proto, factory_list in transport_list_registry.iteritems():
+ if proto is not None and base.startswith(proto):
+ transport, last_err = _try_transport_factories(base,
+ factory_list)
+ if transport:
+ break
+ if transport is None:
+ # We tried all the different protocols, now try one last
+ # time as a local protocol
+ base = convert_path_to_url(base, 'Unsupported protocol: %s')
+
+ # The default handler is the filesystem handler, stored
+ # as protocol None
+ factory_list = transport_list_registry.get(None)
+ transport, last_err = _try_transport_factories(base, factory_list)
+ return transport
+
+
def do_catching_redirections(action, transport, redirected):
"""Execute an action with given transport catching redirections.
=== modified file 'bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py 2007-04-18 14:06:46 +0000
+++ b/bzrlib/transport/ftp.py 2007-05-04 15:33:26 +0000
@@ -69,6 +69,7 @@
mutter("Constructing FTP instance against %r" % (alt_key,))
conn = ftplib.FTP()
+ # FIXME: instrument or refactor to allow testing for mutiple connections
conn.connect(host=hostname, port=port)
if username and username != 'anonymous' and not password:
password = bzrlib.ui.ui_factory.get_password(
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2007-04-22 16:32:04 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2007-05-04 15:33:26 +0000
@@ -235,6 +235,7 @@
handler_order = 1000 # after all pre-processings
+ # FIXME: instrument or refactor to allow testing for mutiple connections
def create_connection(self, request, http_connection_class):
host = request.get_host()
if not host:
=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py 2007-04-16 04:24:11 +0000
+++ b/bzrlib/transport/sftp.py 2007-05-04 15:33:26 +0000
@@ -824,6 +824,7 @@
# that we have taken the lock.
return SFTPLock(relpath, self)
+ # FIXME: instrument or refactor to allow testing for mutiple connections
def _sftp_connect(self):
"""Connect to the remote sftp server.
After this, self._sftp should have a valid connection (or
More information about the bazaar-commits
mailing list