codec validator for diagra
authorandy
Thu, 18 May 2006 07:00:16 +0000
changeset 2616 e3f68f895246
parent 2615 b35875cd55bc
child 2617 57aa248308ad
codec validator for diagra
reportlab/lib/validators.py
--- a/reportlab/lib/validators.py	Wed May 17 13:07:13 2006 +0000
+++ b/reportlab/lib/validators.py	Thu May 18 07:00:16 2006 +0000
@@ -7,7 +7,7 @@
 used in an attribute map.
 """
 
-import string, sys
+import string, sys, codecs
 from types import *
 _SequenceTypes = (ListType,TupleType)
 _NumberTypes = (FloatType,IntType)
@@ -66,6 +66,16 @@
     def test(self,x):
         return type(x) in (StringType, UnicodeType)
 
+class _isCodec(Validator):
+    def test(self,x):
+        if type(x) not in (StringType, UnicodeType):
+            return False
+        try:
+            a,b,c,d = codecs.lookup(x)
+            return True
+        except LookupError:
+            return False
+
 class _isNumber(Validator):
     def test(self,x):
         if type(x) in _NumberTypes: return True
@@ -283,6 +293,7 @@
 isAuto = Auto()
 isBoolean = _isBoolean()
 isString = _isString()
+isCodec = _isCodec()
 isNumber = _isNumber()
 isInt = _isInt()
 isNoneOrInt = NoneOr(isInt,'isNoneOrInt')