commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9448 - trunk/gnue-common/src/utils


From: reinhard
Subject: [gnue] r9448 - trunk/gnue-common/src/utils
Date: Tue, 27 Mar 2007 13:09:58 -0500 (CDT)

Author: reinhard
Date: 2007-03-27 13:09:57 -0500 (Tue, 27 Mar 2007)
New Revision: 9448

Modified:
   trunk/gnue-common/src/utils/datatypes.py
Log:
Added new object type to handle temporary invalid values.


Modified: trunk/gnue-common/src/utils/datatypes.py
===================================================================
--- trunk/gnue-common/src/utils/datatypes.py    2007-03-24 10:55:19 UTC (rev 
9447)
+++ trunk/gnue-common/src/utils/datatypes.py    2007-03-27 18:09:57 UTC (rev 
9448)
@@ -24,7 +24,7 @@
 Helper functions for datatype conversion.
 """
 
-__all__ = ['convert', 'ConversionError']
+__all__ = ['convert', 'InvalidValueType', 'ConversionError']
 
 import datetime
 import mx.DateTime
@@ -58,6 +58,9 @@
         # "None" is always valid, independent of data type
         result = None
 
+    elif isinstance(value, InvalidValueType):
+        result = value
+
     elif datatype == "raw":
         result = value
 
@@ -156,6 +159,29 @@
 
 
 # =============================================================================
+# Singleton to represent an invalid value
+# =============================================================================
+
+class InvalidValueType(object):
+    """
+    An invalid value, connected with an exception that defines why it is
+    invalid.
+
+    An instance of this class represents an invalid value. Like None, it is
+    passed unchanged through type conversion.
+    """
+    def __init__(self, exception):
+        #: The exception that explains why this value is invalid.
+        self.exception = exception
+    def __str__(self):
+        return "InvalidValue (%s)" % type(self.exception)
+    def __unicode__(self):
+        return u"InvalidValue (%s)" % type(self.exception)
+    def __repr__(self):
+        return "InvalidValue (%s)" % type(self.exception)
+
+
+# =============================================================================
 # Exceptions
 # =============================================================================
 





reply via email to

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