[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/sqlexpr/ Compressed error handling in SQLExpr.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 24 18:06:52 EDT 2004


Log message for revision 27256:
  Compressed error handling in SQLExpr.
  
  Compressed test code by removing unused methods in stub implementations.
  


Changed:
  U   Zope3/trunk/src/zope/app/sqlexpr/sqlexpr.py
  U   Zope3/trunk/src/zope/app/sqlexpr/tests.py


-=-
Modified: Zope3/trunk/src/zope/app/sqlexpr/sqlexpr.py
===================================================================
--- Zope3/trunk/src/zope/app/sqlexpr/sqlexpr.py	2004-08-24 21:18:55 UTC (rev 27255)
+++ Zope3/trunk/src/zope/app/sqlexpr/sqlexpr.py	2004-08-24 22:06:52 UTC (rev 27256)
@@ -41,28 +41,25 @@
                 raise ConnectionError, \
                       ("The RDB DA name, '%s' you specified is not "
                        "valid." %conn_name)
-            connection = adapter()
         elif econtext.vars.has_key('rdb') and econtext.vars.has_key('dsn'):
             rdb = econtext.vars['rdb']
             dsn = econtext.vars['dsn']
             try:
-                connection = zapi.createObject(None, rdb, dsn)()
+                adapter = zapi.createObject(None, rdb, dsn)
             except ComponentLookupError:
                 raise ConnectionError, \
                       ("The factory id, '%s', you specified in the `rdb` "
                        "attribute did not match any registered factory." %rdb)
-            except TypeError:
+
+            if not IZopeDatabaseAdapter.providedBy(adapter):
                 raise ConnectionError, \
                       ("The factory id, '%s', you specifed did not create a "
                        "Zope Database Adapter component." %rdb)
-            if not IZopeConnection.providedBy(connection):
-                raise ConnectionError, \
-                      ("The factory id, '%s', you specifed did not create a "
-                       "Zope Database Adapter component." %rdb)
         else:
             raise ConnectionError, \
                   'You did not specify a RDB connection.'
 
+        connection = adapter()
         vvals = []
         for var in self._vars:
             v = var(econtext)

Modified: Zope3/trunk/src/zope/app/sqlexpr/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/sqlexpr/tests.py	2004-08-24 21:18:55 UTC (rev 27255)
+++ Zope3/trunk/src/zope/app/sqlexpr/tests.py	2004-08-24 22:06:52 UTC (rev 27256)
@@ -15,6 +15,9 @@
 
 $Id: test_sqlexpr.py 26878 2004-08-03 16:25:34Z jim $
 """
+
+
+
 import unittest
 
 from zope.interface import implements
@@ -48,19 +51,6 @@
     def cursor(self):
         return CursorStub()
 
-    def answer(self):
-        return 42
-
-    def commit(self, *ignored):
-        v = self._called.setdefault('commit',0)
-        v += 1
-        self._called['commit'] = v
-
-    def rollback(self, *ignored):
-        v = self._called.setdefault('rollback',0)
-        v += 1
-        self._called['rollback'] = v
-
 class CursorStub(object):
 
     description = (('id', 0, 0, 0, 0, 0, 0),
@@ -77,13 +67,6 @@
             raise AssertionError(operation, 'SELECT num FROM hitchhike')
 
 
-class TypeInfoStub(object):
-    paramstyle = 'pyformat'
-    threadsafety = 0
-    def getConverter(self, type):
-        return lambda x: x
-
-
 class SQLExprTest(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):



More information about the Zope3-Checkins mailing list