Can formencode raise invalid for some valid value:
deepak verma <[email protected]> Tue, 31 Dec 2013 15:38:33 +0530
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <CAPEOZDbyiCTCtMV-fWMAB2EMhVtFnMaHU=arMVSkkYtdpTG2og@mail.gmail.com> |
--===============1170848700757782505== Content-Type: multipart/alternative; boundary=047d7b15aeb13c7d6c04eed1bedd --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: [email protected] some emails like these. example: * from formencode import validators* * from formencode.api import Invalid* * invalid_emails = ['[email protected] <[email protected]>', '[email protected] <[email protected]>']* * email = '[email protected] <[email protected]>'* * 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 = ['[email protected] <[email protected]>', '[email protected] <[email protected]>']* * email = '[email protected] <[email protected]>'* * 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=3D"ltr"><br clear=3D"all"><div>Hi all,</div><div><br></div><div>Th= e subject of this email may not seems obvious to some people but I could re= sist myself from being asked this question. Please accept my apologies:</di= v> <div><br></div><div>My Question is:</div><div><br></div><div>Is there any a= ny 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=3D"m= ailto:[email protected]">[email protected]</a> or some emails like these.= </div><div><br></div><div><br></div><div>example:</div><div><div><i><font c= olor=3D"#6fa8dc">=C2=A0 =C2=A0 from formencode import validators</font></i>= </div> <div><i><font color=3D"#6fa8dc">=C2=A0 =C2=A0 from formencode.api import In= valid</font></i></div><div><i><font color=3D"#6fa8dc">=C2=A0 =C2=A0 invalid= _emails =3D ['<a href=3D"mailto:[email protected]">[email protected]<= /a>', '<a href=3D"mailto:[email protected]">[email protected]</a>&#= 39;]</font></i></div> <div><i><font color=3D"#6fa8dc">=C2=A0 =C2=A0 email =3D '<a href=3D"mai= lto:[email protected]">[email protected]</a>'</font></i></div><div><i= ><font color=3D"#6fa8dc">=C2=A0 =C2=A0 try:</font></i></div><div><i><font c= olor=3D"#6fa8dc">=C2=A0 =C2=A0 =C2=A0 =C2=A0 email_validator =3D validators= .Email(invalidate=3Dinvalid_emails)</font></i></div> <div><i><font color=3D"#6fa8dc">=C2=A0 =C2=A0 =C2=A0 =C2=A0 email_validator= .to_python(email)</font></i></div><div><i><font color=3D"#6fa8dc">=C2=A0 = =C2=A0 except Invalid, e:</font></i></div><div><i><font color=3D"#6fa8dc">= =C2=A0 =C2=A0 =C2=A0 =C2=A0 logger.log("An Invalid Exception Occurred&= quot;, e)</font></i></div> <div><i><font color=3D"#6fa8dc">=C2=A0 =C2=A0 =C2=A0 =C2=A0 raise e</font><= /i></div></div><div><br></div><div>In the above code, this should raise Inv= alid 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 th= is:</div><div><div><i><font face=3D"courier new, monospace">=C2=A0 =C2=A0 <= font color=3D"#3d85c6">from formencode import validators</font></font></i><= /div><div> <i><font face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2=A0 fr= om formencode.api import Invalid</font></i></div><div><i><font face=3D"cour= ier new, monospace" color=3D"#3d85c6">=C2=A0 =C2=A0 invalid_emails =3D [= 9;<a href=3D"mailto:[email protected]">[email protected]</a>', '<= a href=3D"mailto:[email protected]">[email protected]</a>']</font></i><= /div> <div><i><font face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2= =A0 email =3D '<a href=3D"mailto:[email protected]">[email protected]= </a>'</font></i></div><div><i><font face=3D"courier new, monospace" col= or=3D"#3d85c6">=C2=A0 =C2=A0 try:</font></i></div> <div><i><font face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2= =A0 =C2=A0 =C2=A0 if email in invalid_emails:</font></i></div><div><i><font= face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0raise Invalid</font></i></div><div><i><font face=3D= "courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2=A0 =C2=A0 =C2=A0 emai= l_validator =3D validators.Email(invalidate=3Dinvalid_emails)</font></i></d= iv> <div><i><font face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2= =A0 =C2=A0 =C2=A0 email_validator.to_python(email)</font></i></div><div><i>= <font face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2=A0 excep= t Invalid, e:</font></i></div><div> <i><font face=3D"courier new, monospace" color=3D"#3d85c6">=C2=A0 =C2=A0 = =C2=A0 =C2=A0 logger.log("An Invalid Exception Occurred", e)</fon= t></i></div><div><i><font face=3D"courier new, monospace" color=3D"#3d85c6"= >=C2=A0 =C2=A0 =C2=A0 =C2=A0 raise e</font></i></div> </div><div><br></div><div>But I have to do this for all validators.</div><d= iv><br></div>-- <br><div dir=3D"ltr"><div><font face=3D"arial, helvetica, s= ans-serif"><br></font></div><font face=3D"arial, helvetica, sans-serif"><di= v> <font face=3D"arial, helvetica, sans-serif"><br></font></div>Thanks & R= egards</font><div><font face=3D"arial, helvetica, sans-serif"><br></font></= div><div><font face=3D"arial, helvetica, sans-serif">Deepak Verma</font></d= iv> <div><font face=3D"arial, helvetica, sans-serif"><br></font></div></div> </div> --047d7b15aeb13c7d6c04eed1bedd-- --===============1170848700757782505== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk --===============1170848700757782505== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ FormEncode-discuss mailing list FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/formencode-discuss --===============1170848700757782505==--