[Zope3-checkins] SVN: Zope3/trunk/ Make port an optional option when specifying the host in a DSN.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Sep 24 09:02:10 EDT 2004


Log message for revision 27673:
  Make port an optional option when specifying the host in a DSN.
  


Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/rdb/__init__.py
  U   Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py


-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-09-24 12:35:38 UTC (rev 27672)
+++ Zope3/trunk/doc/CHANGES.txt	2004-09-24 13:02:09 UTC (rev 27673)
@@ -10,6 +10,8 @@
 
     New features
 
+      - When parsing a DSN, allow the host to be specified without a port.
+
       - Removed Browser Menu Service and implemented menus as subscriber
         adapters. Menu Item Types (in other words, menus) are now utilities
         that provide `IMenuItemType`. 

Modified: Zope3/trunk/src/zope/app/rdb/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/__init__.py	2004-09-24 12:35:38 UTC (rev 27672)
+++ Zope3/trunk/src/zope/app/rdb/__init__.py	2004-09-24 13:02:09 UTC (rev 27673)
@@ -173,6 +173,7 @@
        dbi://dbname;param1=value...
        dbi://user:passwd/dbname
        dbi://user:passwd/dbname;param1=value...
+       dbi://user:passwd@host/dbname
        dbi://user:passwd@host:port/dbname
        dbi://user:passwd@host:port/dbname;param1=value...
 
@@ -215,7 +216,12 @@
     # Get host and port from DSN
     if dsn and dsn.find('@') > 0:
         dsn, host_port = dsn.split('@')
-        host, port = host_port.split(':')
+        host_port = host_port.split(':')
+        if len(host_port) == 2:
+            host, port = host_port
+        else:
+            host = host_port[0]
+            port = ''
     else:
         host, port = '', ''
 

Modified: Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py	2004-09-24 12:35:38 UTC (rev 27672)
+++ Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py	2004-09-24 13:02:09 UTC (rev 27673)
@@ -53,6 +53,13 @@
                   'host': '', 'port': ''}
         self.assertEqual(result, parseDSN(dsn))
 
+
+    def testUserPasswordAndHostWithoutPort(self):
+        dsn = 'dbi://mike:muster@bohr/test'
+        result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',
+                  'password': 'muster', 'host': 'bohr', 'port': ''}
+        self.assertEqual(result, parseDSN(dsn))
+
     def testAllOptions(self):
         dsn = 'dbi://mike:muster@bohr:5432/test'
         result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',



More information about the Zope3-Checkins mailing list