Discussion:
[FE-discuss] Can formencode raise invalid for some valid value:
unknown
1970-01-01 00:00:00 UTC
Permalink
--047d7b15aeb13c7d6c04eed1bedd
Content-Type: text/plain; charset=UTF-8

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:
***@example.comor some emails like these.


example:
* from formencode import validators*
* from formencode.api import Invalid*
* invalid_emails = ['***@example.com <***@example.com>',
'***@gmail.com <***@gmail.com>']*
* email = '***@example.com <***@example.com>'*
* 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 = ['***@example.com <***@example.com>',
'***@gmail.com <***@gmail.com>']*
* email = '***@example.com <***@example.com>'*
* 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

--047d7b15aeb13c7d6c04eed1bedd
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir="ltr"><br clear="all"><div>Hi all,</div><div><br></div><div>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:</div>
<div><br></div><div>My Question is:</div><div><br></div><div>Is there any any support to raise Invalid exception for some values when validation them ?</div><div><br></div><div><br></div><div>For e.g.</div><div>Suppose I have to validate email using email validatior.</div>
<div>Then want to raise Invalid exception to some emails like: <a href="mailto:***@example.com">***@example.com</a> or some emails like these.</div><div><br></div><div><br></div><div>example:</div><div><div><i><font color="#6fa8dc">    from formencode import validators</font></i></div>
<div><i><font color="#6fa8dc">    from formencode.api import Invalid</font></i></div><div><i><font color="#6fa8dc">    invalid_emails = [&#39;<a href="mailto:***@example.com">***@example.com</a>&#39;, &#39;<a href="mailto:***@gmail.com">***@gmail.com</a>&#39;]</font></i></div>
<div><i><font color="#6fa8dc">    email = &#39;<a href="mailto:***@example.com">***@example.com</a>&#39;</font></i></div><div><i><font color="#6fa8dc">    try:</font></i></div><div><i><font color="#6fa8dc">        email_validator = validators.Email(invalidate=invalid_emails)</font></i></div>
<div><i><font color="#6fa8dc">        email_validator.to_python(email)</font></i></div><div><i><font color="#6fa8dc">    except Invalid, e:</font></i></div><div><i><font color="#6fa8dc">        logger.log(&quot;An Invalid Exception Occurred&quot;, e)</font></i></div>
<div><i><font color="#6fa8dc">        raise e</font></i></div></div><div><br></div><div>In the above code, this should raise Invalid exception the we try to validate invalid_emails.</div><div>Do we have support for this in future release.</div>
<div><br></div><div>In order to achieve this I have to do something like this:</div><div><div><i><font face="courier new, monospace">    <font color="#3d85c6">from formencode import validators</font></font></i></div><div>
<i><font face="courier new, monospace" color="#3d85c6">    from formencode.api import Invalid</font></i></div><div><i><font face="courier new, monospace" color="#3d85c6">    invalid_emails = [&#39;<a href="mailto:***@example.com">***@example.com</a>&#39;, &#39;<a href="mailto:***@gmail.com">***@gmail.com</a>&#39;]</font></i></div>
<div><i><font face="courier new, monospace" color="#3d85c6">    email = &#39;<a href="mailto:***@example.com">***@example.com</a>&#39;</font></i></div><div><i><font face="courier new, monospace" color="#3d85c6">    try:</font></i></div>
<div><i><font face="courier new, monospace" color="#3d85c6">        if email in invalid_emails:</font></i></div><div><i><font face="courier new, monospace" color="#3d85c6">             raise Invalid</font></i></div><div><i><font face="courier new, monospace" color="#3d85c6">        email_validator = validators.Email(invalidate=invalid_emails)</font></i></div>
<div><i><font face="courier new, monospace" color="#3d85c6">        email_validator.to_python(email)</font></i></div><div><i><font face="courier new, monospace" color="#3d85c6">    except Invalid, e:</font></i></div><div>
<i><font face="courier new, monospace" color="#3d85c6">        logger.log(&quot;An Invalid Exception Occurred&quot;, e)</font></i></div><div><i><font face="courier new, monospace" color="#3d85c6">        raise e</font></i></div>
</div><div><br></div><div>But I have to do this for all validators.</div><div><br></div>-- <br><div dir="ltr"><div><font face="arial, helvetica, sans-serif"><br></font></div><font face="arial, helvetica, sans-serif"><div>
<font face="arial, helvetica, sans-serif"><br></font></div>Thanks &amp; Regards</font><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Deepak Verma</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div></div>
</div>

--047d7b15aeb13c7d6c04eed1bedd--
Loading...