Rev 3005: Fix 150860 by leaving port as user specified it. in file:///v/home/vila/src/bzr/bugs/150860/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Nov 19 13:44:28 GMT 2007


At file:///v/home/vila/src/bzr/bugs/150860/

------------------------------------------------------------
revno: 3005
revision-id:v.ladeuil+lp at free.fr-20071119134425-y74t0vh9ctpo8j9f
parent: pqm at pqm.ubuntu.com-20071116062543-dl3xkea5ri27qwnz
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 150860
timestamp: Mon 2007-11-19 14:44:25 +0100
message:
  Fix 150860 by leaving port as user specified it.
  
  * transport/remote.py:
  (BZR_DEFAULT_INTERFACE, BZR_DEFAULT_PORT): Moved to
  smart/medium.py.
  
  * transport/__init__.py:
  (TransportListRegistry.register_transport): Delete default_port.
  (TransportListRegistry.get_default_port): Deleted.
  (ConnectedTransport._split_url, ConnectedTransport._unsplit_url):
  Leave port untouched.
  
  * tests/test_transport.py: 
  Transports kept port as user specified it.
  (TestRemoteTCPTransport, SSHPortTestMixin, SFTPTransportPortTest,
  BzrSSHTransportPortTest): Deleted. Default port is set just before
  connection.
  
  * smart/medium.py:
  (SmartTCPClientMedium._ensure_connection): Set port to default
  *just* before connection.
  
  * builtins.py:
  (cmd_serve.run): Get interface and port default values from medium.
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
  bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-11-16 04:45:22 +0000
+++ b/bzrlib/builtins.py	2007-11-19 13:44:25 +0000
@@ -3652,7 +3652,6 @@
         from bzrlib.smart import medium, server
         from bzrlib.transport import get_transport
         from bzrlib.transport.chroot import ChrootServer
-        from bzrlib.transport.remote import BZR_DEFAULT_PORT, BZR_DEFAULT_INTERFACE
         if directory is None:
             directory = os.getcwd()
         url = urlutils.local_path_to_url(directory)
@@ -3665,9 +3664,9 @@
             smart_server = medium.SmartServerPipeStreamMedium(
                 sys.stdin, sys.stdout, t)
         else:
-            host = BZR_DEFAULT_INTERFACE
+            host = medium.BZR_DEFAULT_INTERFACE
             if port is None:
-                port = BZR_DEFAULT_PORT
+                port = medium.BZR_DEFAULT_PORT
             else:
                 if ':' in port:
                     host, port = port.split(':')

=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2007-10-05 14:52:02 +0000
+++ b/bzrlib/smart/medium.py	2007-11-19 13:44:25 +0000
@@ -510,6 +510,11 @@
         return self._read_from.read(count)
 
 
+# Port 4155 is the default port for bzr://, registered with IANA.
+BZR_DEFAULT_INTERFACE = '0.0.0.0'
+BZR_DEFAULT_PORT = 4155
+
+
 class SmartTCPClientMedium(SmartClientStreamMedium):
     """A client medium using TCP."""
     
@@ -540,10 +545,14 @@
             return
         self._socket = socket.socket()
         self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
-        result = self._socket.connect_ex((self._host, int(self._port)))
+        if self._port is None:
+            port = BZR_DEFAULT_PORT
+        else:
+            port = int(self._port)
+        result = self._socket.connect_ex((self._host, port))
         if result:
             raise errors.ConnectionError("failed to connect to %s:%d: %s" %
-                    (self._host, self._port, os.strerror(result)))
+                    (self._host, port, os.strerror(result)))
         self._connected = True
 
     def _flush(self):

=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py	2007-10-22 21:19:13 +0000
+++ b/bzrlib/tests/test_transport.py	2007-11-19 13:44:25 +0000
@@ -48,10 +48,6 @@
 from bzrlib.transport.memory import MemoryTransport
 from bzrlib.transport.local import (LocalTransport,
                                     EmulatedWin32LocalTransport)
-from bzrlib.transport.remote import (
-    BZR_DEFAULT_PORT,
-    RemoteTCPTransport
-    )
 
 
 # TODO: Should possibly split transport-specific tests into their own files.
@@ -78,10 +74,13 @@
         try:
             _clear_protocol_handlers()
             register_transport_proto('foo')
-            register_lazy_transport('foo', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
+            register_lazy_transport('foo', 'bzrlib.tests.test_transport',
+                                    'TestTransport.SampleHandler')
             register_transport_proto('bar')
-            register_lazy_transport('bar', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
-            self.assertEqual([SampleHandler.__module__, 'bzrlib.transport.chroot'],
+            register_lazy_transport('bar', 'bzrlib.tests.test_transport',
+                                    'TestTransport.SampleHandler')
+            self.assertEqual([SampleHandler.__module__,
+                              'bzrlib.transport.chroot'],
                              _get_transport_modules())
         finally:
             _set_protocol_handlers(handlers)
@@ -619,7 +618,7 @@
     def test_parse_url(self):
         t = ConnectedTransport('http://simple.example.com/home/source')
         self.assertEquals(t._host, 'simple.example.com')
-        self.assertEquals(t._port, 80)
+        self.assertEquals(t._port, None)
         self.assertEquals(t._path, '/home/source/')
         self.failUnless(t._user is None)
         self.failUnless(t._password is None)
@@ -716,123 +715,6 @@
         self.assertIsNot(t1, t2)
 
 
-class TestRemoteTCPTransport(TestCase):
-    """Tests for bzr:// transport (RemoteTCPTransport)."""
-
-    def test_relpath_with_implicit_port(self):
-        """Connected transports with the same URL are the same, even if the
-        port is implicit.
-
-        So t.relpath(url) should always be '' if t.base is the same as url, or
-        if the only difference is that one explicitly specifies the default
-        port and the other doesn't specify a port.
-        """
-        t_implicit_port = RemoteTCPTransport('bzr://host.com/')
-        self.assertEquals('', t_implicit_port.relpath('bzr://host.com/'))
-        self.assertEquals('', t_implicit_port.relpath('bzr://host.com:4155/'))
-        t_explicit_port = RemoteTCPTransport('bzr://host.com:4155/')
-        self.assertEquals('', t_explicit_port.relpath('bzr://host.com/'))
-        self.assertEquals('', t_explicit_port.relpath('bzr://host.com:4155/'))
-
-    def test_construct_uses_default_port(self):
-        """If no port is specified, then RemoteTCPTransport uses
-        BZR_DEFAULT_PORT.
-        """
-        t = get_transport('bzr://host.com/')
-        self.assertEquals(BZR_DEFAULT_PORT, t._port)
-
-    def test_url_omits_default_port(self):
-        """If a RemoteTCPTransport uses the default port, then its base URL
-        will omit the port.
-
-        This is like how ":80" is omitted from "http://example.com/".
-        """
-        t = get_transport('bzr://host.com:4155/')
-        self.assertEquals('bzr://host.com/', t.base)
-
-    def test_url_includes_non_default_port(self):
-        """Non-default ports are included in the transport's URL.
-
-        Contrast this to `test_url_omits_default_port`.
-        """
-        t = get_transport('bzr://host.com:666/')
-        self.assertEquals('bzr://host.com:666/', t.base)
-
-
-class SSHPortTestMixin(object):
-    """Mixin class for testing SSH-based transports' use of ports in URLs.
-    
-    Unlike other connected transports, SSH-based transports (sftp, bzr+ssh)
-    don't have a default port, because the user may have OpenSSH configured to
-    use a non-standard port.
-    """
-
-    def make_url(self, netloc):
-        """Make a url for the given netloc, using the scheme defined on the
-        TestCase.
-        """
-        return '%s://%s/' % (self.scheme, netloc)
-
-    def test_relpath_with_implicit_port(self):
-        """SSH-based transports with the same URL are the same.
-        
-        Note than an unspecified port number is different to port 22 (because
-        OpenSSH may be configured to use a non-standard port).
-
-        So t.relpath(url) should always be '' if t.base is the same as url, but
-        raise PathNotChild if the ports in t and url are not both specified (or
-        both unspecified).
-        """
-        url_implicit_port = self.make_url('host.com')
-        url_explicit_port = self.make_url('host.com:22')
-
-        t_implicit_port = get_transport(url_implicit_port)
-        self.assertEquals('', t_implicit_port.relpath(url_implicit_port))
-        self.assertRaises(
-            PathNotChild, t_implicit_port.relpath, url_explicit_port)
-        
-        t_explicit_port = get_transport(url_explicit_port)
-        self.assertRaises(
-            PathNotChild, t_explicit_port.relpath, url_implicit_port)
-        self.assertEquals('', t_explicit_port.relpath(url_explicit_port))
-
-    def test_construct_with_no_port(self):
-        """If no port is specified, then the SSH-based transport's _port will
-        be None.
-        """
-        t = get_transport(self.make_url('host.com'))
-        self.assertEquals(None, t._port)
-
-    def test_url_with_no_port(self):
-        """If no port was specified, none is shown in the base URL."""
-        t = get_transport(self.make_url('host.com'))
-        self.assertEquals(self.make_url('host.com'), t.base)
-
-    def test_url_includes_port(self):
-        """An SSH-based transport's base will show the port if one was
-        specified, even if that port is 22, because we do not assume 22 is the
-        default port.
-        """
-        # 22 is the "standard" port for SFTP.
-        t = get_transport(self.make_url('host.com:22'))
-        self.assertEquals(self.make_url('host.com:22'), t.base)
-        # 666 is not a standard port.
-        t = get_transport(self.make_url('host.com:666'))
-        self.assertEquals(self.make_url('host.com:666'), t.base)
-
-
-class SFTPTransportPortTest(TestCase, SSHPortTestMixin):
-    """Tests for sftp:// transport (SFTPTransport)."""
-
-    scheme = 'sftp'
-
-
-class BzrSSHTransportPortTest(TestCase, SSHPortTestMixin):
-    """Tests for bzr+ssh:// transport (RemoteSSHTransport)."""
-
-    scheme = 'bzr+ssh'
-
-
 class TestTransportTrace(TestCase):
 
     def test_get(self):

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2007-11-14 08:05:32 +0000
+++ b/bzrlib/transport/__init__.py	2007-11-19 13:44:25 +0000
@@ -128,27 +128,20 @@
         self.get(key).insert(0,
                 registry._LazyObjectGetter(module_name, member_name))
 
-    def register_transport(self, key, help=None, default_port=None):
-        self.register(key, [], help, default_port)
+    def register_transport(self, key, help=None):
+        self.register(key, [], help)
 
     def set_default_transport(self, key=None):
         """Return either 'key' or the default key if key is None"""
         self._default_key = key
 
-    def get_default_port(self, scheme):
-        """Return the registered default port for this protocol scheme."""
-        try:
-            return self.get_info(scheme + '://')
-        except LookupError:
-            return None
-
 
 transport_list_registry = TransportListRegistry()
 
 
-def register_transport_proto(prefix, help=None, info=None, default_port=None,
+def register_transport_proto(prefix, help=None, info=None,
                              register_netloc=False):
-    transport_list_registry.register_transport(prefix, help, default_port)
+    transport_list_registry.register_transport(prefix, help)
     if register_netloc:
         assert prefix.endswith('://')
         register_urlparse_netloc_protocol(prefix[:-3])
@@ -1362,10 +1355,6 @@
         host = urllib.unquote(host)
         path = urllib.unquote(path)
 
-        if port is None:
-            # The port isn't explicitly specified, so return the default (if
-            # there is one).
-            port = transport_list_registry.get_default_port(scheme)
         return (scheme, user, password, host, port, path)
 
     @staticmethod
@@ -1396,10 +1385,7 @@
             # have one so that it doesn't get accidentally
             # exposed.
             netloc = '%s@%s' % (urllib.quote(user), netloc)
-        if (port is not None and 
-            port != transport_list_registry.get_default_port(scheme)):
-            # Include the port in the netloc (unless it's the same as the
-            # default, in which case we omit it as it is redundant).
+        if port is not None:
             netloc = '%s:%d' % (netloc, port)
         path = urllib.quote(path)
         return urlparse.urlunparse((scheme, netloc, path, None, None, None))
@@ -1456,7 +1442,7 @@
         """Get the object shared amongst cloned transports.
 
         This should be used only by classes that needs to extend the sharing
-        with other objects than tramsports.
+        with objects other than transports.
 
         Use _get_connection to get the connection itself.
         """
@@ -1721,8 +1707,6 @@
 register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
 transport_list_registry.set_default_transport("file://")
 
-# Note that sftp:// has no default_port, because the user's ~/.ssh/config
-# can set it to arbitrary values based on hostname.
 register_transport_proto('sftp://',
             help="Access using SFTP (most SSH servers provide SFTP).",
             register_netloc=True)
@@ -1730,49 +1714,46 @@
 # Decorated http transport
 register_transport_proto('http+urllib://',
 #                help="Read-only access of branches exported on the web."
-            default_port=80, register_netloc=True)
+                         register_netloc=True)
 register_lazy_transport('http+urllib://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
 register_transport_proto('https+urllib://',
 #                help="Read-only access of branches exported on the web using SSL."
-            default_port=443, register_netloc=True)
+                         register_netloc=True)
 register_lazy_transport('https+urllib://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
 register_transport_proto('http+pycurl://',
 #                help="Read-only access of branches exported on the web."
-            default_port=80, register_netloc=True)
+                         register_netloc=True)
 register_lazy_transport('http+pycurl://', 'bzrlib.transport.http._pycurl',
                         'PyCurlTransport')
 register_transport_proto('https+pycurl://',
 #                help="Read-only access of branches exported on the web using SSL."
-            default_port=443, register_netloc=True)
+                         register_netloc=True)
 register_lazy_transport('https+pycurl://', 'bzrlib.transport.http._pycurl',
                         'PyCurlTransport')
 # Default http transports (last declared wins (if it can be imported))
 register_transport_proto('http://',
-            help="Read-only access of branches exported on the web.",
-            default_port=80)
+                 help="Read-only access of branches exported on the web.")
 register_transport_proto('https://',
-            help="Read-only access of branches exported on the web using SSL.",
-            default_port=443)
+            help="Read-only access of branches exported on the web using SSL.")
 register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
 register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
                         'HttpTransport_urllib')
-register_lazy_transport('http://', 'bzrlib.transport.http._pycurl', 'PyCurlTransport')
-register_lazy_transport('https://', 'bzrlib.transport.http._pycurl', 'PyCurlTransport')
+register_lazy_transport('http://', 'bzrlib.transport.http._pycurl',
+                        'PyCurlTransport')
+register_lazy_transport('https://', 'bzrlib.transport.http._pycurl',
+                        'PyCurlTransport')
 
-register_transport_proto('ftp://',
-            help="Access using passive FTP.",
-            default_port=21)
+register_transport_proto('ftp://', help="Access using passive FTP.")
 register_lazy_transport('ftp://', 'bzrlib.transport.ftp', 'FtpTransport')
-register_transport_proto('aftp://',
-            help="Access using active FTP.",
-            default_port=21)
+register_transport_proto('aftp://', help="Access using active FTP.")
 register_lazy_transport('aftp://', 'bzrlib.transport.ftp', 'FtpTransport')
 
 register_transport_proto('memory://')
-register_lazy_transport('memory://', 'bzrlib.transport.memory', 'MemoryTransport')
+register_lazy_transport('memory://', 'bzrlib.transport.memory',
+                        'MemoryTransport')
 
 # chroots cannot be implicitly accessed, they must be explicitly created:
 register_transport_proto('chroot+')
@@ -1780,20 +1761,24 @@
 register_transport_proto('readonly+',
 #              help="This modifier converts any transport to be readonly."
             )
-register_lazy_transport('readonly+', 'bzrlib.transport.readonly', 'ReadonlyTransportDecorator')
+register_lazy_transport('readonly+', 'bzrlib.transport.readonly',
+                        'ReadonlyTransportDecorator')
 
 register_transport_proto('fakenfs+')
-register_lazy_transport('fakenfs+', 'bzrlib.transport.fakenfs', 'FakeNFSTransportDecorator')
+register_lazy_transport('fakenfs+', 'bzrlib.transport.fakenfs',
+                        'FakeNFSTransportDecorator')
 
 register_transport_proto('trace+')
-register_lazy_transport('trace+', 'bzrlib.transport.trace', 'TransportTraceDecorator')
+register_lazy_transport('trace+', 'bzrlib.transport.trace',
+                        'TransportTraceDecorator')
 
 register_transport_proto('unlistable+')
-register_lazy_transport('unlistable+', 'bzrlib.transport.unlistable', 'UnlistableTransportDecorator')
+register_lazy_transport('unlistable+', 'bzrlib.transport.unlistable',
+                        'UnlistableTransportDecorator')
 
 register_transport_proto('brokenrename+')
 register_lazy_transport('brokenrename+', 'bzrlib.transport.brokenrename',
-        'BrokenRenameTransportDecorator')
+                        'BrokenRenameTransportDecorator')
 
 register_transport_proto('vfat+')
 register_lazy_transport('vfat+',
@@ -1808,28 +1793,23 @@
 
 register_transport_proto('bzr://',
             help="Fast access using the Bazaar smart server.",
-            default_port=4155, register_netloc=True)
+                         register_netloc=True)
 
-register_lazy_transport('bzr://',
-                        'bzrlib.transport.remote',
+register_lazy_transport('bzr://', 'bzrlib.transport.remote',
                         'RemoteTCPTransport')
 register_transport_proto('bzr+http://',
 #                help="Fast access using the Bazaar smart server over HTTP."
-            default_port=80, register_netloc=True)
-register_lazy_transport('bzr+http://',
-                        'bzrlib.transport.remote',
+                         register_netloc=True)
+register_lazy_transport('bzr+http://', 'bzrlib.transport.remote',
                         'RemoteHTTPTransport')
 register_transport_proto('bzr+https://',
 #                help="Fast access using the Bazaar smart server over HTTPS."
-             register_netloc=True)
+                         register_netloc=True)
 register_lazy_transport('bzr+https://',
                         'bzrlib.transport.remote',
                         'RemoteHTTPTransport')
-# Note that bzr+ssh:// has no default_port, because the user's ~/.ssh/config
-# can set it to arbitrary values based on hostname.
 register_transport_proto('bzr+ssh://',
             help="Fast access using the Bazaar smart server over SSH.",
             register_netloc=True)
-register_lazy_transport('bzr+ssh://',
-                        'bzrlib.transport.remote',
+register_lazy_transport('bzr+ssh://', 'bzrlib.transport.remote',
                         'RemoteSSHTransport')

=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py	2007-10-24 18:19:51 +0000
+++ b/bzrlib/transport/remote.py	2007-11-19 13:44:25 +0000
@@ -37,11 +37,6 @@
 from bzrlib.smart import client, medium, protocol
 
 
-# Port 4155 is the default port for bzr://, registered with IANA.
-BZR_DEFAULT_INTERFACE = '0.0.0.0'
-BZR_DEFAULT_PORT = 4155
-
-
 class _SmartStat(object):
 
     def __init__(self, size, mode):



More information about the bazaar-commits mailing list