commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7554 - in trunk/gnue-common/src/datasources: . drivers/DBSIG2


From: reinhard
Subject: [gnue] r7554 - in trunk/gnue-common/src/datasources: . drivers/DBSIG2
Date: Wed, 25 May 2005 08:49:08 -0500 (CDT)

Author: reinhard
Date: 2005-05-25 08:49:07 -0500 (Wed, 25 May 2005)
New Revision: 7554

Modified:
   trunk/gnue-common/src/datasources/GConditions.py
   trunk/gnue-common/src/datasources/GDataSource.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
Log:
Changed type checks to use new (Python 2.2+) type objects instead of the types
module.


Modified: trunk/gnue-common/src/datasources/GConditions.py
===================================================================
--- trunk/gnue-common/src/datasources/GConditions.py    2005-05-25 13:48:21 UTC 
(rev 7553)
+++ trunk/gnue-common/src/datasources/GConditions.py    2005-05-25 13:49:07 UTC 
(rev 7554)
@@ -26,7 +26,6 @@
 from gnue.common.apps import errors
 
 import mx.DateTime
-import types
 import string
 import sys
 import re
@@ -239,14 +238,14 @@
     @return: GCondition tree
     """
 
-    checktype (prefixList, types.ListType)
+    checktype (prefixList, list)
 
     if len (prefixList):
       item = prefixList [0]
 
       # be nice if there's a condition part missing
       offset = 1
-      if isinstance (item, types.ListType):
+      if isinstance (item, list):
         self.buildFromList (item)
         element = self
       else:
@@ -335,7 +334,7 @@
     method set's the fieldname.
     """
 
-    checktype (prefixList, [types.StringType, types.UnicodeType])
+    checktype (prefixList, basestring)
     self.name = prefixList
 
 
@@ -1333,13 +1332,12 @@
   @return: GCondition tree
   """
 
-  checktype (condition, [types.ListType, types.DictType, types.NoneType,
-                         GCondition])
+  checktype (condition, [list, dict, GCondition, None])
 
-  if isinstance (condition, types.ListType):
+  if isinstance (condition, list):
     return GCondition (prefixList = condition)
 
-  elif isinstance (condition, types.DictType):
+  elif isinstance (condition, dict):
     return buildConditionFromDict (condition, comparison, logic)
 
   elif isinstance (condition, GCondition):
@@ -1362,7 +1360,7 @@
   @return: GCondition tree
   """
 
-  checktype (prefixList, types.ListType)
+  checktype (prefixList, list)
 
   return GCondition (prefixList = prefixList)
 
@@ -1385,7 +1383,7 @@
   @return: GCondition tree
   """
 
-  checktype (dictionary, types.DictType)
+  checktype (dictionary, dict)
 
   c     = comparison ()._type [2:]
   pList = [[c, ['field', f], ['const', v]] for (f, v) in dictionary.items ()]
@@ -1422,10 +1420,10 @@
     return buildCondition (cond1)
 
   # make sure both parts are condition trees
-  if isinstance (cond1, types.DictType):
+  if isinstance (cond1, dict):
     cond1 = buildConditionFromDict (cond1)
 
-  if isinstance (cond2, types.DictType):
+  if isinstance (cond2, dict):
     cond2 = buildConditionFromDict (cond2)
 
   # if the master condition has no elements, assign the second condition's
@@ -1492,7 +1490,7 @@
   This function does the dirty work of 'unify ()'.
   """
 
-  checktype (values, types.ListType)
+  checktype (values, list)
 
   if not len (values):
     return
@@ -1501,9 +1499,9 @@
     result.append (values [0])
     return
 
-  if isinstance (values [0], types.StringType):
+  if isinstance (values [0], str):
     values [0] = unicode (values [0])
-  if isinstance (values [1], types.StringType):
+  if isinstance (values [1], str):
     values [1] = unicode (values [1])
 
   v1 = values [0]
@@ -1521,8 +1519,8 @@
 
   else:
     # String-Conversions
-    if isinstance (v1, types.UnicodeType) or isinstance (v2, 
types.UnicodeType):
-      if isinstance (v1, types.UnicodeType):
+    if isinstance (v1, unicode) or isinstance (v2, unicode):
+      if isinstance (v1, unicode):
         oldValue = v1
         chkValue = v2
       else:
@@ -1530,8 +1528,7 @@
         chkValue = v1
 
       # String to Boolean
-      if hasattr (types, "BooleanType") and \
-         isinstance (chkValue, types.BooleanType):
+      if isinstance (chkValue, bool):
         if oldValue.upper () in ['TRUE', 'T']:
           newValue = True
         elif oldValue.upper () in ['FALSE', 'F']:
@@ -1540,9 +1537,9 @@
           raise ConversionError, (oldValue, chkValue)
   
       # String to Integer, Long or Float
-      elif isinstance (chkValue, types.IntType) or \
-           isinstance (chkValue, types.LongType) or \
-           isinstance (chkValue, types.FloatType):
+      elif isinstance (chkValue, int) or \
+           isinstance (chkValue, long) or \
+           isinstance (chkValue, float):
         try:
           if oldValue.upper () in ['TRUE', 'T']:
             newValue = 1
@@ -1573,10 +1570,8 @@
         raise ConversionRuleError, (oldValue, chkValue)
   
     # Boolean conversions
-    elif hasattr (types, "BooleanType") and \
-         (isinstance (v1, types.BooleanType) or \
-          isinstance (v2, types.BooleanType)):
-      if isinstance (v1, types.BooleanType):
+    elif isinstance (v1, bool) or isinstance (v2, bool):
+      if isinstance (v1, bool):
         oldValue = v1
         chkValue = v2
       else:
@@ -1584,14 +1579,14 @@
         chkValue = v1
 
       # Boolean to Integer
-      if isinstance (chkValue, types.IntType):
+      if isinstance (chkValue, int):
         if oldValue:
           newValue = 1
         else:
           newValue = 0
   
       # Boolean to Long
-      elif isinstance (chkValue, types.LongType):
+      elif isinstance (chkValue, long):
         if oldValue:
           newValue = 1L
         else:
@@ -1601,8 +1596,8 @@
         raise ConversionRuleError, (oldValue, chkValue)
   
     # Integer conversions
-    elif isinstance (v1, types.IntType) or isinstance (v2, types.IntType):
-      if isinstance (v1, types.IntType):
+    elif isinstance (v1, int) or isinstance (v2, int):
+      if isinstance (v1, int):
         oldValue = v1
         chkValue = v2
       else:
@@ -1610,18 +1605,18 @@
         chkValue = v1
   
       # Integer to Float
-      if isinstance (chkValue, types.FloatType):
+      if isinstance (chkValue, float):
         newValue = float (oldValue)
 
-      elif isinstance (chkValue, types.LongType):
+      elif isinstance (chkValue, long):
         newValue = long (oldValue)
   
       else:
         raise ConversionRuleError, (oldValue, chkValue)
   
     # Long conversions
-    elif isinstance (v1, types.LongType) or isinstance (v2, types.LongType):
-      if isinstance (v1, types.LongType):
+    elif isinstance (v1, long) or isinstance (v2, long):
+      if isinstance (v1, long):
         oldValue = v1
         chkValue = v2
       else:
@@ -1629,7 +1624,7 @@
         chkValue = v1
   
       # Long into Float
-      if isinstance (chkValue, types.FloatType):
+      if isinstance (chkValue, float):
         newValue = float (oldValue)
       else:
         raise ConversionRuleError, (oldValue, chkValue)

Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2005-05-25 13:48:21 UTC 
(rev 7553)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2005-05-25 13:49:07 UTC 
(rev 7554)
@@ -26,7 +26,6 @@
 
 import cStringIO
 import string
-import types
 
 from gnue.common.apps import errors
 from gnue.common.definitions import GObjects, GParser, GParserHelpers
@@ -397,8 +396,7 @@
 
   def referenceFields (self, fields):
     for field in fields:
-      if isinstance (field, types.StringType) or \
-         isinstance (field, types.UnicodeType):
+      if isinstance (field, basestring):
         self.referenceField(field)
       else:
         self.referenceField(*field)
@@ -650,8 +648,7 @@
 
     # If it's a string or a unicode string, we transform it into a tuple
     # sequence, where all items are treated to be in 'ascending' order
-    if isinstance (order_by, types.StringType) or \
-       isinstance (order_by, types.UnicodeType):
+    if isinstance (order_by, basestring):
       gDebug (1, "DEPRECIATION WARNING: use of 'order_by' attribute is " \
                  "depreciated. Please use <sortorder> instead.")
       for field in string.split (order_by, ','):
@@ -665,13 +662,12 @@
 
     # Well, order_by is already a sequence. So we've to make sure it's a
     # sequence of tuples with fieldname and direction.
-    elif isinstance (order_by, types.ListType):
+    elif isinstance (order_by, list):
       for item in order_by:
-        if isinstance (item, types.StringType) or \
-           isinstance (item, types.UnicodeType):
+        if isinstance (item, basestring):
           result.append ({'name':item})
 
-        elif isinstance (item, types.DictType):
+        elif isinstance (item, dict):
           result.append (item)
 
         else:

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2005-05-25 13:48:21 UTC (rev 7553)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2005-05-25 13:49:07 UTC (rev 7554)
@@ -23,8 +23,6 @@
 
 __all__ = ['Connection']
 
-from types import *
-
 import string
 import sys
 import mx.DateTime
@@ -108,11 +106,11 @@
 
     Descendants may override this function to to different type conversions.
     """
-    if isinstance (value, UnicodeType):
+    if isinstance (value, unicode):
       # Unicode: return encoded string
       return value.encode (self._encoding)
 
-    elif isinstance (value, BooleanType):
+    elif isinstance (value, bool):
       # Booleans
       if value:
         return self._boolean_true
@@ -224,16 +222,16 @@
       point numbers, booleans or mx.DateTime values.
     @return: A DBSIG2 cursor object holding the result of the query.
     """
-    checktype (statement, [StringType, UnicodeType])
-    checktype (parameters, [DictionaryType, NoneType])
+    checktype (statement, basestring)
+    checktype (parameters, [dict, None])
 
     if parameters:
       for (parameters_key, parameters_value) in parameters.items ():
-        checktype (parameters_key, [StringType, UnicodeType])
+        checktype (parameters_key, basestring)
         # checktype (parameters_value, .....) -- too many valid types :-)
 
     # Convert to encoded string for database
-    if isinstance (statement, UnicodeType):
+    if isinstance (statement, unicode):
       s = statement.encode (self._encoding)
     else:
       s = statement
@@ -242,7 +240,7 @@
       # convert parameter dictionary to encoded strings
       p = {}
       for (key, value) in parameters.items ():
-        if isinstance (key, UnicodeType):
+        if isinstance (key, unicode):
           k = key.encode (self._encoding)
         else:
           k = key
@@ -470,7 +468,7 @@
       row = rows [0]
       result = {}
       for i in range (len (fields)):
-        if isinstance (row [i], StringType):
+        if isinstance (row [i], str):
           result [fields [i]] = unicode (row [i], self._encoding)
         else:
           result [fields [i]] = row [i]

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2005-05-25 13:48:21 UTC (rev 7553)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2005-05-25 13:49:07 UTC (rev 7554)
@@ -24,7 +24,6 @@
 __all__ = ['ResultSet']
 
 import string
-import types
 
 from gnue.common.datasources.drivers import Base
 
@@ -164,7 +163,7 @@
       for row in rows:
         result = {}
         for (fieldname, value) in zip (self.__fieldnames, row):
-          if isinstance (value, types.StringType):
+          if isinstance (value, str):
             value = unicode (value, self.__connection._encoding)
           result [fieldname] = value
         yield result





reply via email to

[Prev in Thread] Current Thread [Next in Thread]