# HG changeset patch # User Sandro Knauß # Date 1330377682 -3600 # Node ID e5ec4bfa4929751f483eb05d65103516687a6713 # Parent 6c708c334f3754d417a917b4c994e0ccfd1a13bf adding allowString and allowList to vEmail to make sure, if a list is allowd or a string. diff -r 6c708c334f37 -r e5ec4bfa4929 iro/model/message.py --- a/iro/model/message.py Mon Feb 27 22:20:19 2012 +0100 +++ b/iro/model/message.py Mon Feb 27 22:21:22 2012 +0100 @@ -46,8 +46,8 @@ if len(self.attachments) != len(other.attachments): return False - for i in range(len(self.attachments)): - if self.attachments[i] != other.attachments[i]: + for a in self.attachments: + if a not in other.attachments: return False return True diff -r 6c708c334f37 -r e5ec4bfa4929 iro/validate.py --- a/iro/validate.py Mon Feb 27 22:20:19 2012 +0100 +++ b/iro/validate.py Mon Feb 27 22:21:22 2012 +0100 @@ -63,7 +63,7 @@ raise e return ret -def vEmail(value, field): +def vEmail(value, field, allowString=True, allowList=True): '''validator for emailadresses (see wikipeda for strange mailadresses and RFC3696) valid: "very.(),:;<>[]\\".VERY.\\"very@\\\ \\"very\\".unusual"@strange.example.com @@ -79,8 +79,12 @@ ret = [] str_=False if type(value) is types.StringType: + if not allowString: + raise ValidateException('%s must be a list of email addresses.'%field) str_=True value=[value] + elif not allowList: + raise ValidateException('%s must be a email address - No list of email addresses.'%field) for v in value: parts= re.match(r'^(.*)@(.+?)$',v) if not parts: diff -r 6c708c334f37 -r e5ec4bfa4929 tests/email_validate.py --- a/tests/email_validate.py Mon Feb 27 22:20:19 2012 +0100 +++ b/tests/email_validate.py Mon Feb 27 22:21:22 2012 +0100 @@ -1,7 +1,7 @@ import unittest from iro.validate import vEmail -from iro.error import InvalidMail +from iro.error import InvalidMail, ValidateException class testEmail(unittest.TestCase): @@ -57,3 +57,9 @@ def testString(self): self.assertEqual(vEmail('x@test.de', None),"x@test.de") + + def testAllowString(self): + self.assertRaises(ValidateException,vEmail, 'x@test.de', None, allowString=False) + + def testAllowList(self): + self.assertRaises(ValidateException,vEmail, ['x@test.de'], None, allowList=False)