{ "info": { "author": "Ihor Kolosha, Viktor Turstkiy", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": ".. image:: https://travis-ci.org/asholok/python-validator-livr.svg\r\n :target: https://travis-ci.org/asholok/python-validator-livr\r\n\r\n======\r\nREADME\r\n======\r\n\r\nNAME\r\n====\r\n\r\nLIVR.Validator - Lightweight validator supporting Language Independent Validation Rules Specification (LIVR)\r\n\r\n Python 2 and 3 compatible\r\n\r\nSYNOPSIS\r\n========\r\n\r\nCommon usage::\r\n\r\n from LIVR import Validator\r\n Validator.Validator.set_default_auto_trim(True)\r\n\r\n validator = Validator.Validator({\r\n 'name': 'required',\r\n 'email': [ 'required', 'email' ],\r\n 'gender': { 'one_of' : ['male', 'female'] },\r\n 'phone': { 'max_length' : 10 },\r\n 'password': [ 'required', {'min_length' : 10} ],\r\n 'password2': { 'equal_to_field' : 'password' }\r\n })\r\n\r\n valid_data = validator.validate(user_data)\r\n\r\n if valid_data:\r\n save_user_data(valid_data)\r\n else:\r\n some_error_hendler(validator.get_errors())\r\n\r\nYou can use filters separately or can combine them with validation::\r\n\r\n validator = Validator.Validator({\r\n 'email': [ 'required', 'trim', 'email', 'to_lc' ]\r\n })\r\n\r\n\r\n\r\nFeel free to register your own rules::\r\n\r\n validator = Validator.Validator({\r\n 'password': ['required', 'strong_password']\r\n })\r\n\r\n class StrongPassword(object):\r\n def __init__(self, *args):\r\n pass\r\n\r\n def __call__(self, value, unuse, unuse):\r\n value == None or value == '':\r\n return\r\n\r\n if len(value) < 6:\r\n return 'WEAK_PASSWORD'\r\n\r\n validator.registerRules({ 'strong_password': StrongPassword})\r\n\r\nAlso you can use aliases for some case, but you must ensure that in aliase dict present required kyes 'rules' and 'name'::\r\n\r\n validator = Validator.Validator({\r\n 'password': ['required', 'strong_password']\r\n })\r\n\r\n validator.register_aliased_rule({\r\n 'name': 'strong_password',\r\n 'rules': {'min_length' : 9},\r\n 'error': 'WEAK_PASSWORD'\r\n })\r\n\r\nDESCRIPTION\r\n===========\r\n\r\nSee http://livr-spec.org for detailed documentation and list of supported rules.\r\n\r\n\r\nFeatures:\r\n\r\n * Rules are declarative and language independent\r\n * Any number of rules for each field\r\n * Return together errors for all fields\r\n * Excludes all fields that do not have validation rules described\r\n * Has possibility to validatate complex hierarchical structures\r\n * Easy to describe and undersand rules\r\n * Returns understandable error codes(not error messages)\r\n * Easy to add own rules\r\n * Rules are be able to change results output (\"trim\", \"nested_object\", for example)\r\n * Multipurpose (user input validation, configs validation, contracts programming etc)\r\n\r\nINSTALL\r\n=======\r\nInstall LIVR from PyPI using PIP::\r\n\r\n sudo pip install LIVR\r\n\r\nCLASS METHODS\r\n=============\r\n\r\nValidator.Validator(livr, is_auto_trim)\r\n---------------------------------------\r\n\r\nContructor creates validator objects.\r\nlivr - validations rules. Rules description is available here - https://github.com/koorchik/LIVR\r\n\r\nis_auto_trim - asks validator to trim all values before validation. Output will be also trimmed.\r\n if is_auto_trim is undefined(or None) than default_auto_trim value will be used.\r\n\r\n\r\nValidator.Validator.registerDefaultRules({\"rule_name\": rule_builder })\r\n----------------------------------------------------------------------\r\n\r\nrule_builder - is a function reference which will be called for building single rule validator.\r\n::\r\n\r\n class MyRule(object):\r\n def __init__(self, *args):\r\n rule_builders = args[0]\r\n # rule_builders - are rules from original validator\r\n # to allow you create new validator with all supported rules\r\n # validator = Validator(livr)\r\n # validator.register_rules(rule_builders)\r\n # validator.prepare()\r\n\r\n def __call__(self, value, all_values, output_array):\r\n if not_valid:\r\n return \"SOME_ERROR_CODE\"\r\n else:\r\n # some usefull code\r\n\r\n Validator.Validator.register_default_rules( {\"my_rule\": MyRule} )\r\n\r\nThen you can use \"my_rule\" for validation::\r\n\r\n {\r\n 'name1': 'my_rule', # Call without parameters\r\n 'name2': { 'my_rule': arg1 }, # Call with one parameter.\r\n 'name3': { 'my_rule': [arg1] }, # Call with one parameter.\r\n 'name4': { 'my_rule': [ arg1, arg2, arg3 ] } # Call with many parameters.\r\n }\r\n\r\nHere is \"max_number\" implemenation::\r\n\r\n class MaxNumber(object):\r\n def __init__(self, *args):\r\n self._max_number = float(args[1])\r\n\r\n def __call__(self, number, unuse, unuse_):\r\n # We do not validate empty fields. We have \"required\" rule for this purpose\r\n if number == None or number == '':\r\n return\r\n\r\n #return error message\r\n if float(number) > self._max_number:\r\n return 'TOO_HIGH'\r\n\r\n Validator.Validator.register_default_rules({ \"max_number\": MaxNumber })\r\n\r\nAll rules for the validator are equal. It does not distinguish \"required\", \"list_of_different_objects\" and \"trim\" rules. So, you can extend validator with any rules you like.\r\n\r\nValidator.Validator.get_default_rules()\r\n---------------------------------------\r\nreturns object containing all default rule_builders for the validator. You can register new rule or update existing one with \"register_rules\" method.\r\n\r\nValidator.Validator.set_default_auto_trim(is_auto_trim)\r\n-------------------------------------------------------\r\nEnables or disables automatic trim for input data. If is on then every new validator instance will have auto trim option enabled\r\n\r\nOBJECT METHODS\r\n==============\r\n\r\nvalidator.validate(input)\r\n-------------------------\r\nValidates user input. On success returns valid_data (contains only data that has described validation rules). On error return false.\r\n::\r\n\r\n valida_data = validator.validate(input)\r\n\r\n if valida_data: \r\n #use valida_data\r\n else:\r\n errors = validator.get_errors()\r\n\r\n\r\nvalidator.get_errors()\r\n----------------------\r\nReturns errors object.\r\n::\r\n\r\n {\r\n \"field1\": \"ERROR_CODE\",\r\n \"field2\": \"ERROR_CODE\",\r\n ...\r\n }\r\n\r\nFor example::\r\n\r\n {\r\n \"country\": \"NOT_ALLOWED_VALUE\",\r\n \"zip\": \"NOT_POSITIVE_INTEGER\",\r\n \"street\": \"REQUIRED\",\r\n \"building\": \"NOT_POSITIVE_INTEGER\"\r\n }\r\n\r\n\r\nvalidator.register_rules({\"rule_name\": rule_builder})\r\n-----------------------------------------------------\r\n\r\nrule_builder - is a function reference which will be called for building single rule validator.\r\n\r\nSee \"Validator.Validator.register_default_rules\" for rules examples.\r\n\r\n\r\nvalidator.get_rules()\r\n---------------------\r\n\r\nreturns object containing all rule_builders for the validator. You can register new rule or update existing one with \"register_rules\" method.\r\n\r\n\r\nvalidator.register_aliased_rule(alias)\r\n--------------------------------------\r\n\r\nalias - is a composite validation rule.\r\n\r\nSee \"Validator.Validator.register_aliased_rule\" for rules examples.\r\n\r\nAUTHOR\r\n======\r\nkoorchik (Viktor Turskyi), asholok (Ihor Kolosha)\r\n\r\nBUGS\r\n====\r\nPlease report any bugs or feature requests to Github https://github.com/asholok/python-validator-livr\r\n\r\nLICENSE AND COPYRIGHT\r\n=====================\r\n\r\nCopyright 2012 Viktor Turskyi.\r\n\r\nThis program is free software, you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:\r\n\r\nhttp://www.perlfoundation.org/artistic_license_2_0\r\n\r\nAny use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.\r\n\r\nIf your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.\r\n\r\nThis license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.\r\n\r\nThis license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.\r\n\r\nDisclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS \"AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/asholok/python-validator-livr", "keywords": "", "license": "look into README", "maintainer": "", "maintainer_email": "", "name": "LIVR", "package_url": "https://pypi.org/project/LIVR/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/LIVR/", "project_urls": { "Homepage": "https://github.com/asholok/python-validator-livr" }, "release_url": "https://pypi.org/project/LIVR/2.0.1/", "requires_dist": null, "requires_python": null, "summary": "LIVR validator.", "version": "2.0.1" }, "last_serial": 2822358, "releases": { "0.4": [ { "comment_text": "LIVR vertion 0.4.1 (python 3 compatible)", "digests": { "md5": "0815234e958b8a70757ee33b3114f769", "sha256": "890c6a684dbd7d17e10a78b9c2d182d55187cac4f0d92aeeaca20dc7b7ad7f2f" }, "downloads": -1, "filename": "LIVR-0.4.1.tar.gz", "has_sig": false, "md5_digest": "0815234e958b8a70757ee33b3114f769", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8996, "upload_time": "2015-06-27T11:23:03", "url": "https://files.pythonhosted.org/packages/70/1b/9f65d1c66aceb5dd01dd3bebe3a13ab35163fbebad56e8b9b57336ea4e71/LIVR-0.4.1.tar.gz" }, { "comment_text": "LIVR vertion 0.4.22 (python 2.7+)", "digests": { "md5": "38df8b713078cfccc7f9b968c21892c0", "sha256": "8c08a3de11d4eb3faaafc24030a7e4b169dbc53f9ac5d88dee2175082c8d0bf4" }, "downloads": -1, "filename": "LIVR-0.4.22.tar.gz", "has_sig": false, "md5_digest": "38df8b713078cfccc7f9b968c21892c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12584, "upload_time": "2015-10-03T08:33:12", "url": "https://files.pythonhosted.org/packages/56/f2/db0572abdb16a3f7851aa6ad772f72791f02d738d3fde27f92a6cf37c1c2/LIVR-0.4.22.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "829fd8f48279b2bbf5c0c0661face5cf", "sha256": "dbd226cb77ea3725fe17c5d24a7f945ae9a1eb810bc849cd1463dce908a2a24e" }, "downloads": -1, "filename": "LIVR-0.4.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "829fd8f48279b2bbf5c0c0661face5cf", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 17907, "upload_time": "2015-06-28T09:53:32", "url": "https://files.pythonhosted.org/packages/5f/2d/527455138884bd15af9d0d80b276472006ce7a0329fa0eb5208f01d45130/LIVR-0.4.1-py2.py3-none-any.whl" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "87872bbc143ade14d565ad0e829c73d2", "sha256": "f438a68225d9ce338ce96fd1bfed818b56a32d84f9848d075656049a4d389017" }, "downloads": -1, "filename": "LIVR-0.4.22-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "87872bbc143ade14d565ad0e829c73d2", "packagetype": "bdist_wheel", "python_version": "any", "requires_python": null, "size": 18460, "upload_time": "2015-08-03T14:11:32", "url": "https://files.pythonhosted.org/packages/46/ba/4d5357ce17fb33cf58be47225666eee8217e0c10c1c190dff75fddbc0cc9/LIVR-0.4.22-py2.py3-none-any.whl" } ], "0.4.31": [ { "comment_text": "", "digests": { "md5": "e41e54168da2924f34df479ce13e2d9c", "sha256": "58f530f0e89ced203329507af0ea2548a41216f0a3e8d979f7955a2fd3868dc0" }, "downloads": -1, "filename": "LIVR-0.4.31-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e41e54168da2924f34df479ce13e2d9c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 17837, "upload_time": "2015-10-03T09:05:54", "url": "https://files.pythonhosted.org/packages/bd/04/4f6faef17668caf60c3b18f527207505d106d86b31877ab7b1f29cdbf5f0/LIVR-0.4.31-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "15d6cd232df7cb1bb71912e93005600e", "sha256": "ac84d586f014d5871124fd39c9ae1c1c6dc913d5976cad4bd6c0c7374a9fe366" }, "downloads": -1, "filename": "LIVR-0.4.31.tar.gz", "has_sig": false, "md5_digest": "15d6cd232df7cb1bb71912e93005600e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12554, "upload_time": "2015-10-03T09:05:58", "url": "https://files.pythonhosted.org/packages/f4/a5/f6260e4824045560d92d2ed6322a194d4450f95da0673b8afbbba3879239/LIVR-0.4.31.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "ac69465acb72c4b723f328fe50950008", "sha256": "f3e5a389783bd631e0fef13fa5a9222bed9649eb6b7b6293605a83ee71758f02" }, "downloads": -1, "filename": "LIVR-2.0-py2-none-any.whl", "has_sig": false, "md5_digest": "ac69465acb72c4b723f328fe50950008", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 20811, "upload_time": "2017-03-08T22:13:57", "url": "https://files.pythonhosted.org/packages/4b/c7/73e5d3667d169d46bc78263aee8afbc5aa34a123bcab04f3608c26383e92/LIVR-2.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b0487356410ba48ee9d8a1a75c55e403", "sha256": "f979f5bbabd34b9db49dc963f81799877d806b9210c420d248ef38fa696bf482" }, "downloads": -1, "filename": "LIVR-2.0.tar.gz", "has_sig": false, "md5_digest": "b0487356410ba48ee9d8a1a75c55e403", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13397, "upload_time": "2017-03-08T22:14:00", "url": "https://files.pythonhosted.org/packages/72/f1/9a83f41c47487db2f218e94efa41ee7bc4c184599ca7c3ae2e0a7a74f782/LIVR-2.0.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "c128baecb3382d0d76f08240d3fe6394", "sha256": "bf1b2f93585332702b427d4998dde0604c01673404685ef6dd4f2dc7a9c54868" }, "downloads": -1, "filename": "LIVR-2.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c128baecb3382d0d76f08240d3fe6394", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 20885, "upload_time": "2017-04-22T20:12:28", "url": "https://files.pythonhosted.org/packages/ee/c7/4d38dcffeb1422520d951aca1da4cb2775a791d314f8ca34ac8f8d4ad54c/LIVR-2.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8c328a967d6425f23b1f10ef80fb16bf", "sha256": "ef5f04955fae1064fc9df3a5bd37229ea9efc470b37c89237dec58bdaa37feaf" }, "downloads": -1, "filename": "LIVR-2.0.1.tar.gz", "has_sig": false, "md5_digest": "8c328a967d6425f23b1f10ef80fb16bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13433, "upload_time": "2017-04-22T20:13:48", "url": "https://files.pythonhosted.org/packages/ce/bf/a1f2d38e4207688c1334834a876884d140e3257a4a16d2ddf540eded8afd/LIVR-2.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c128baecb3382d0d76f08240d3fe6394", "sha256": "bf1b2f93585332702b427d4998dde0604c01673404685ef6dd4f2dc7a9c54868" }, "downloads": -1, "filename": "LIVR-2.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c128baecb3382d0d76f08240d3fe6394", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 20885, "upload_time": "2017-04-22T20:12:28", "url": "https://files.pythonhosted.org/packages/ee/c7/4d38dcffeb1422520d951aca1da4cb2775a791d314f8ca34ac8f8d4ad54c/LIVR-2.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8c328a967d6425f23b1f10ef80fb16bf", "sha256": "ef5f04955fae1064fc9df3a5bd37229ea9efc470b37c89237dec58bdaa37feaf" }, "downloads": -1, "filename": "LIVR-2.0.1.tar.gz", "has_sig": false, "md5_digest": "8c328a967d6425f23b1f10ef80fb16bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13433, "upload_time": "2017-04-22T20:13:48", "url": "https://files.pythonhosted.org/packages/ce/bf/a1f2d38e4207688c1334834a876884d140e3257a4a16d2ddf540eded8afd/LIVR-2.0.1.tar.gz" } ] }