commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9244 - trunk/gnue-common/src/datasources


From: reinhard
Subject: [gnue] r9244 - trunk/gnue-common/src/datasources
Date: Tue, 9 Jan 2007 13:25:56 -0600 (CST)

Author: reinhard
Date: 2007-01-09 13:25:54 -0600 (Tue, 09 Jan 2007)
New Revision: 9244

Modified:
   trunk/gnue-common/src/datasources/GConditions.py
Log:
Updated conversion rules to support Decimal if available.


Modified: trunk/gnue-common/src/datasources/GConditions.py
===================================================================
--- trunk/gnue-common/src/datasources/GConditions.py    2007-01-09 19:02:48 UTC 
(rev 9243)
+++ trunk/gnue-common/src/datasources/GConditions.py    2007-01-09 19:25:54 UTC 
(rev 9244)
@@ -28,6 +28,8 @@
 import sys
 import mx.DateTime
 import datetime
+if sys.hexversion >= 0x02040000:
+    import decimal
 
 from gnue.common.apps import errors
 from gnue.common.definitions import GObjects
@@ -1704,6 +1706,14 @@
         else:
           newValue = 0L
   
+      # Boolean to Decimal
+      elif sys.hexversion >= 0x02040000 \
+              and isinstance (chkValue, decimal.Decimal):
+        if oldValue:
+          newValue = decimal.Decimal(1)
+        else:
+          newValue = decimal.Decimal(0)
+
       else:
         raise ConversionRuleError, (oldValue, chkValue)
   
@@ -1720,9 +1730,14 @@
       if isinstance (chkValue, float):
         newValue = float (oldValue)
 
+      # Integer to Long
       elif isinstance (chkValue, long):
         newValue = long (oldValue)
   
+      # Integer to Decimal
+      elif sys.hexversion >= 0x02040000 \
+              and isinstance (chkValue, decimal.Decimal):
+        newValue = decimal.Decimal (oldValue)
       else:
         raise ConversionRuleError, (oldValue, chkValue)
   
@@ -1735,12 +1750,35 @@
         oldValue = v2
         chkValue = v1
   
-      # Long into Float
+      # Long to Float
       if isinstance (chkValue, float):
         newValue = float (oldValue)
+  
+      # Long to Decimal
+      elif sys.hexversion >= 0x02040000 \
+              and isinstance (chkValue, decimal.Decimal):
+        newValue = decimal.Decimal (oldValue)
       else:
         raise ConversionRuleError, (oldValue, chkValue)
   
+    # Decimal conversion (Python 2.4 or later)
+    elif sys.hexversion >= 0x02040000 \
+            and (isinstance (v1, decimal.Decimal) \
+                or isinstance (v2, decimal.Decimal)):
+
+      if isinstance (v1, decimal.Decimal):
+        oldValue = v1
+        chkValue = v2
+      else:
+        oldValue = v2
+        chkValue = v1
+
+      # Decimal into Float
+      if isinstance (chkValue, float):
+        newValue = float (oldValue)
+      else:
+        raise ConversionRuleError, (oldValue, chkValue)
+  
     elif isinstance (v1, datetime.datetime) or \
          isinstance (v2, datetime.datetime):
 





reply via email to

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