Author: ianb
Date: 2006-10-10 14:18:56 -0600 (Tue, 10 Oct 2006)
New Revision: 2004

Modified:
   FormEncode/trunk/formencode/validators.py
Log:
Make validators.Regex accept unicode

Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py   2006-10-10 20:14:22 UTC (rev 
2003)
+++ FormEncode/trunk/formencode/validators.py   2006-10-10 20:18:56 UTC (rev 
2004)
@@ -505,13 +505,13 @@
     
     def __init__(self, *args, **kw):
         FancyValidator.__init__(self, *args, **kw)
-        if isinstance(self.regex, str):
+        if isinstance(self.regex, basestring):
             ops = 0
-            assert not isinstance(self.regexOps, str), (
+            assert not isinstance(self.regexOps, basestring), (
                 "regexOps should be a list of options from the re module "
                 "(names, or actual values)")
             for op in self.regexOps:
-                if isinstance(op, str):
+                if isinstance(op, basestring):
                     ops |= getattr(re, op)
                 else:
                     ops |= op
@@ -519,15 +519,14 @@
 
     def validate_python(self, value, state):
         self.assert_string(value, state)
-        if self.strip and (isinstance(value, str) or isinstance(value, 
unicode)):
+        if self.strip and isinstance(value, basestring):
             value = value.strip()
         if not self.regex.search(value):
             raise Invalid(self.message('invalid', state),
                           value, state)
 
     def _to_python(self, value, state):
-        if self.strip and \
-               (isinstance(value, str) or isinstance(value, unicode)):
+        if self.strip and isinstance(value, basestring):
             return value.strip()
         return value
 
@@ -1160,6 +1159,8 @@
         Traceback (most recent call last):
             ...
         Invalid: The domain of the email address does not exist (the portion 
after the @: thisdomaindoesnotexistithinkforsure.com)
+        >>> e = Email(not_empty=False)
+        >>> e.to_python('')
         
     """ 
 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to