email validator can now handle strings and lists devel
authorSandro Knauß <knauss@netzguerilla.net>
Thu, 23 Feb 2012 16:53:32 +0100
branchdevel
changeset 181 8a5be61f34c5
parent 180 55ab949cf0f8
child 182 e6af45edff5a
email validator can now handle strings and lists
iro/validate.py
tests/email_validate.py
--- a/iro/validate.py	Thu Feb 23 16:52:06 2012 +0100
+++ b/iro/validate.py	Thu Feb 23 16:53:32 2012 +0100
@@ -3,6 +3,7 @@
 import re
 from decorator import decorator
 from inspect import getcallargs
+import types
 
 from .error import ValidateException, InvalidTel, InvalidMail
 from .telnumber import Telnumber
@@ -76,6 +77,10 @@
     this\\ still\\"not\\allowed@example.com
     '''
     ret = []
+    str_=False
+    if type(value) is types.StringType:
+        str_=True
+        value=[value]
     for v in value:
         parts= re.match(r'^(.*)@(.+?)$',v)
         if not parts:
@@ -118,6 +123,8 @@
             raise InvalidMail(v,field)
         if v not in ret:
             ret.append(v)
+    if str_:
+        ret=ret[0]
     return ret
 
 def validate(kwd,func, need=True,*args,**kargs):
--- a/tests/email_validate.py	Thu Feb 23 16:52:06 2012 +0100
+++ b/tests/email_validate.py	Thu Feb 23 16:53:32 2012 +0100
@@ -49,8 +49,10 @@
 
     def testInvalidDomain(self):
         '''invalid Domainname'''
-        with self.assertRaises(InvalidMail) as e:
+        with self.assertRaises(InvalidMail):
             vEmail(['x@&.de'],None)
+    def testString(self):
+        self.assertEqual(vEmail('x@test.de', None),"x@test.de")
 
     def testDoubles(self):
         self.assertEqual(vEmail(['x@test.de','x@test.de'],None),["x@test.de"])