Latest recipes tagged "validation"http://code.activestate.com/recipes/tags/validation/new/2013-08-12T14:11:25-07:00ActiveState Code RecipesValidate XML with schemaLocation (Python)
2013-03-28T10:24:55-07:00Mathias Loeschhttp://code.activestate.com/recipes/users/4185910/http://code.activestate.com/recipes/578503-validate-xml-with-schemalocation/
<p style="color: grey">
Python
recipe 578503
by <a href="/recipes/users/4185910/">Mathias Loesch</a>
(<a href="/recipes/tags/schema/">schema</a>, <a href="/recipes/tags/schemalocation/">schemalocation</a>, <a href="/recipes/tags/validation/">validation</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 3.
</p>
<p>Addresses problems described at:</p>
<p><a href="http://stackoverflow.com/questions/2979824/in-document-schema-declarations-and-lxml" rel="nofollow">http://stackoverflow.com/questions/2979824/in-document-schema-declarations-and-lxml</a>
<a href="https://mailman-mail5.webfaction.com/pipermail/lxml/2011-September/006153.html" rel="nofollow">https://mailman-mail5.webfaction.com/pipermail/lxml/2011-September/006153.html</a></p>
Credit card number check (Python)
2013-08-12T14:11:25-07:00Matt Joneshttp://code.activestate.com/recipes/users/4182764/http://code.activestate.com/recipes/578202-credit-card-number-check/
<p style="color: grey">
Python
recipe 578202
by <a href="/recipes/users/4182764/">Matt Jones</a>
(<a href="/recipes/tags/validation/">validation</a>).
Revision 2.
</p>
<p>Pass in the credit card number and the card type and get back a result with an explanation.</p>
Credit Card Validation (Python)
2011-08-11T19:06:58-07:00Stijn de Graafhttp://code.activestate.com/recipes/users/4178055/http://code.activestate.com/recipes/577838-credit-card-validation/
<p style="color: grey">
Python
recipe 577838
by <a href="/recipes/users/4178055/">Stijn de Graaf</a>
(<a href="/recipes/tags/card/">card</a>, <a href="/recipes/tags/credit/">credit</a>, <a href="/recipes/tags/false/">false</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/testing/">testing</a>, <a href="/recipes/tags/true/">true</a>, <a href="/recipes/tags/validating/">validating</a>, <a href="/recipes/tags/validation/">validation</a>).
</p>
<p>Test validity of any credit card number using the LUHN method (mod 10).
Starting at the last digit and moving backwards, you add up every other digit.
Then, you double the left-out digits, and add the digits of these results to the original sum.
If this satisfies sum mod 10 == 0 then the card is valid.</p>
<p>This is also explained at <a href="http://www.beachnet.com/%7Ehstiles/cardtype.html" rel="nofollow">http://www.beachnet.com/~hstiles/cardtype.html</a></p>
Validating classes and objects against an Abstract Base Class (Python)
2011-05-21T19:14:19-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577711-validating-classes-and-objects-against-an-abstract/
<p style="color: grey">
Python
recipe 577711
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/validation/">validation</a>).
Revision 4.
</p>
<p>Abstract Bases Classes in Python provide great features for describing interfaces programmatically. By default a subclass is validated against all its ABC parents at instantiation time (in object.__new__). This recipe aims to provide for validation against an ABC of:</p>
<ul>
<li>any class at definition time (including subclasses and registered classes),</li>
<li>any object at any time.</li>
</ul>
<p>I have included an example of the reason I did all this. It allows you to implement an ABC in the instance rather than the class.</p>
<p>If the classes argument to validate is None then it tries to build the list of classes from the object's MRO. If the ABCMeta.register method facilitated an __implements__ list on classes, we could also use that to validate against the registered "base" classes.</p>
<p>The code I have provided is for Python 3, but it should work in 2.7 with a little modification.</p>
<p>This code borrows from Lib/abc.py and objects/typeobject.c</p>
Validate ABNs (Australian Business Numbers) (Python)
2011-05-13T03:22:12-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577692-validate-abns-australian-business-numbers/
<p style="color: grey">
Python
recipe 577692
by <a href="/recipes/users/4172944/">Steven D'Aprano</a>
(<a href="/recipes/tags/abn/">abn</a>, <a href="/recipes/tags/validation/">validation</a>).
</p>
<p>This is a validation function for Australian Business Numbers (ABNs). It tests whether an integer or string is a valid ABN (but not whether it is a <em>legal</em> ABN, i.e. if it belongs to the person or business entity that is quoting it).</p>
Validate ACNs (Australian Company Numbers) (Python)
2011-05-13T03:15:35-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577691-validate-acns-australian-company-numbers/
<p style="color: grey">
Python
recipe 577691
by <a href="/recipes/users/4172944/">Steven D'Aprano</a>
(<a href="/recipes/tags/acn/">acn</a>, <a href="/recipes/tags/validation/">validation</a>).
</p>
<p>This is a validation function for Australian Company Numbers (ACNs). It tests whether the integer or string is a valid ACN (but not whether it is a <em>legal</em> ACN, i.e. if it belongs to the company that is quoting it).</p>
HTTPS httplib Client Connection with Certificate Validation (Python)
2011-01-18T18:30:45-08:00Marcelo Fernándezhttp://code.activestate.com/recipes/users/4173551/http://code.activestate.com/recipes/577548-https-httplib-client-connection-with-certificate-v/
<p style="color: grey">
Python
recipe 577548
by <a href="/recipes/users/4173551/">Marcelo Fernández</a>
(<a href="/recipes/tags/certificate/">certificate</a>, <a href="/recipes/tags/client/">client</a>, <a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/httplib/">httplib</a>, <a href="/recipes/tags/https/">https</a>, <a href="/recipes/tags/networking/">networking</a>, <a href="/recipes/tags/ssl/">ssl</a>, <a href="/recipes/tags/validation/">validation</a>).
</p>
<p>Despite httplib.HTTPSConnection lets the programmer specify the client's pair of certificates, it doesn't force the underlying SSL library to check the server certificate against the client keys (from the client point of view).</p>
<p>This class allows to force this check, to ensure the python client is connecting to the right server.</p>
Simple Validation decorator (Python)
2010-03-26T06:54:47-07:00Shekhar Tiwatnehttp://code.activestate.com/recipes/users/2071240/http://code.activestate.com/recipes/577149-simple-validation-decorator/
<p style="color: grey">
Python
recipe 577149
by <a href="/recipes/users/2071240/">Shekhar Tiwatne</a>
(<a href="/recipes/tags/validation/">validation</a>).
</p>
<p>Validation decorator based on formencode package. It uses validation schemas.</p>