|
From: deepak v. <yes...@gm...> - 2013-12-31 10:08:41
|
Hi all,
The subject of this email may not seems obvious to some people but I could
resist myself from being asked this question. Please accept my apologies:
My Question is:
Is there any any support to raise Invalid exception for some values when
validation them ?
For e.g.
Suppose I have to validate email using email validatior.
Then want to raise Invalid exception to some emails like:
no...@ex... some emails like these.
example:
* from formencode import validators*
* from formencode.api import Invalid*
* invalid_emails = ['no...@ex... <no...@ex...>',
'bl...@gm... <bl...@gm...>']*
* email = 'no...@ex... <no...@ex...>'*
* try:*
* email_validator = validators.Email(invalidate=invalid_emails)*
* email_validator.to_python(email)*
* except Invalid, e:*
* logger.log("An Invalid Exception Occurred", e)*
* raise e*
In the above code, this should raise Invalid exception the we try to
validate invalid_emails.
Do we have support for this in future release.
In order to achieve this I have to do something like this:
* from formencode import validators*
* from formencode.api import Invalid*
* invalid_emails = ['no...@ex... <no...@ex...>',
'bl...@gm... <bl...@gm...>']*
* email = 'no...@ex... <no...@ex...>'*
* try:*
* if email in invalid_emails:*
* raise Invalid*
* email_validator = validators.Email(invalidate=invalid_emails)*
* email_validator.to_python(email)*
* except Invalid, e:*
* logger.log("An Invalid Exception Occurred", e)*
* raise e*
But I have to do this for all validators.
--
Thanks & Regards
Deepak Verma
|