[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/rdb/ Sprinting with Claudia Albisetti.

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Oct 9 12:12:23 EDT 2004


Log message for revision 27852:
  Sprinting with Claudia Albisetti.
  
  Improved the DSN parser to only accepts users without password and 
  improved hostname without port implementation. Both of these cases seem 
  common in MySQL (which we are about to fix).
  
  


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


-=-
Modified: Zope3/trunk/src/zope/app/rdb/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/__init__.py	2004-10-09 16:06:02 UTC (rev 27851)
+++ Zope3/trunk/src/zope/app/rdb/__init__.py	2004-10-09 16:12:23 UTC (rev 27852)
@@ -171,8 +171,10 @@
 
        dbi://dbname
        dbi://dbname;param1=value...
+       dbi://user/dbname
        dbi://user:passwd/dbname
        dbi://user:passwd/dbname;param1=value...
+       dbi://user@host/dbname
        dbi://user:passwd@host/dbname
        dbi://user:passwd@host:port/dbname
        dbi://user:passwd@host:port/dbname;param1=value...
@@ -216,12 +218,10 @@
     # Get host and port from DSN
     if dsn and dsn.find('@') > 0:
         dsn, host_port = dsn.split('@')
-        host_port = host_port.split(':')
-        if len(host_port) == 2:
-            host, port = host_port
+        if host_port.find(':') > 0:
+            host, port = host_port.split(':')
         else:
-            host = host_port[0]
-            port = ''
+            host, port = host_port, ''
     else:
         host, port = '', ''
 
@@ -230,7 +230,10 @@
 
     # Get username and password from DSN
     if dsn:
-        username, password = dsn.split(':', 1)
+        if dsn.find(':') > 0:
+            username, password = dsn.split(':', 1)
+        else:
+             username, password = dsn, ''
     else:
         username, password = '', ''
 

Modified: Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py	2004-10-09 16:06:02 UTC (rev 27851)
+++ Zope3/trunk/src/zope/app/rdb/tests/test_dsnparser.py	2004-10-09 16:12:23 UTC (rev 27852)
@@ -34,6 +34,12 @@
                   'host': '', 'port': ''}
         self.assertEqual(result, parseDSN(dsn))
 
+    def testUser(self):
+        dsn = 'dbi://mike/test'
+        result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',
+                  'password': '', 'host': '', 'port': ''}
+        self.assertEqual(result, parseDSN(dsn))
+
     def testUserPassword(self):
         dsn = 'dbi://mike:muster/test'
         result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',
@@ -54,6 +60,12 @@
         self.assertEqual(result, parseDSN(dsn))
 
 
+    def testUserAndHostWithoutPort(self):
+        dsn = 'dbi://mike@bohr/test'
+        result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',
+                  'password': '', 'host': 'bohr', 'port': ''}
+        self.assertEqual(result, parseDSN(dsn))
+
     def testUserPasswordAndHostWithoutPort(self):
         dsn = 'dbi://mike:muster@bohr/test'
         result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',



More information about the Zope3-Checkins mailing list