[Zope-Checkins] CVS: Products/DCOracle2/DCOracle2 - DCOracle2.py:1.78

Matthew T. Kromer matt@zope.com
Tue, 27 Nov 2001 11:35:22 -0500


Update of /cvs-repository/Products/DCOracle2/DCOracle2
In directory cvs.zope.org:/tmp/cvs-serv6680/DCOracle2

Modified Files:
	DCOracle2.py 
Log Message:
Handle type coercion differently; when used from Zope the issubclass test is
busted.


=== Products/DCOracle2/DCOracle2/DCOracle2.py 1.77 => 1.78 ===
             if p is None and self._nullmap is not _nonullmap:
                 self._nullmap[i] = 1
-            #print "binding %d with %s" % (i, p)
-            if type(p) == types.InstanceType and issubclass(p.__class__,
-                TypeCoercion):
+            #print "binding %d as %s" % (i, p)
+            if isTypeCoercion(p):
                 self._cursor.bindbypos(i, p.value, p.type)
             else:
                 self._cursor.bindbypos(i, p)
@@ -791,8 +790,7 @@
             p = kw[key]
             if p is None and self._nullmap is not _nonullmap:
                 self._nullmap[key] = 1
-            if type(p) == types.InstanceType and issubclass(p.__class__,
-                TypeCoercion):
+            if isTypeCoercion(p):
                 self._cursor.bindbyname(ck, p.value, p.type)
             else:
                 self._cursor.bindbyname(ck, p)
@@ -850,8 +848,7 @@
                 p = params[r][c]
                 if p is not None: notnull[c] = 1
                 try:
-                    if type(p) == types.InstanceType and issubclass(p.__class__,                        TypeCoercion):
-                        # Allow type override
+                    if isTypeCoercion(p):
                         l = len(p.value) + 1
                     else:
                         l = len(p) + 1
@@ -881,8 +878,7 @@
             for i in xrange(rows):
                 p = params[i][c]
                 if p is not None: break
-            if type(p) == types.InstanceType and issubclass(p.__class__,
-                TypeCoercion):
+            if isTypeCoercion(p):
 
                 p = p.value
                 t = p.type
@@ -927,8 +923,7 @@
                 for c in xrange(columns):
                     p = params[r][c]
                     #print p
-                    if type(p) == types.InstanceType and issubclass(p.__class__,
-                        TypeCoercion):
+                    if isTypeCoercion(p):
 
                         baoa[c][br] = p.value
                     else:
@@ -1455,6 +1450,7 @@
     def __init__(self, value, type):
         self.value = value
         self.type = type
+        self._is_type_coercion_ = 1
 
     def __repr__(self):
         return repr(self.value)
@@ -1462,6 +1458,12 @@
     def __str__(self):
         return str(self.value)
 
+def isTypeCoercion(ob):
+    if type(ob) is not types.InstanceType: return 0
+    if issubclass(ob.__class__, TypeCoercion): return 1
+    if getattr(ob, '_is_type_coercion_', 0): return 1
+    return 0
+
 # Set up the type objects: note that dco2 represents a lot of things as
 # strings -- may be required to patch it to use buffers for things (silly)
 # to better match the expected types; i.e. if we claim someting is BINARY
@@ -1519,4 +1521,3 @@
 # API 1.0 dbiRaw column
 def dbiRaw(string):
     return TypeCoercion(string, 'SQLT_LBI') # Make it a long binary
-