{ "info": { "author": "Ben Meier", "author_email": "benmeier@fastmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development" ], "description": "validoot - 1.3\n==============\n\nThis module is designed to solve the most basic of argument validations:\ntypes, clauses, and combinations of clauses. It is meant to remove some\nof the boiler plate code used to check the input types and checks such\nas between, or string lengths.\n\nGithub url: https://github.com/AstromechZA/validoot\n\nPypi url: https://pypi.python.org/pypi/validoot/1.3\n\nDefinitions\n^^^^^^^^^^^\n\n- Clause - A function that takes in the value as a parameter and\n returns ``True`` or ``False``.\n- Operator - Allows you to \u201cand\u201d and \u201cor\u201d clauses together.\n\nBasic example:\n^^^^^^^^^^^^^^\n\n.. code:: python\n\n from validoot import validates, inst, typ, between\n\n @validates(inst(basestring), typ(int), between(0, 100))\n def do_something(name, id, age):\n pass\n\nIn the code above, a ``validoot.ValidationError`` will be thrown if the\n``name`` is not a string or unicode, if the ``id`` is not an integer, or\nif the ``age`` is not between 0 and 100.\n\n.. code:: python\n\n >>> do_something('Darth Vader', 0, 42)\n >>> do_something('Boba Fett', 1, 123)\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"validoot/decorators.py\", line 25, in __call__\n self.positional_validators[i], args[i], i))\n validoot.exceptions.ValidationError: Validation failed for value 123 ( arg[2] )\n\nOperators:\n^^^^^^^^^^\n\nWe can extend the first example by adding an additional check for the\n``name``: it must be between 5 and 40 characters. For this we use the\n``validoot.And`` operator to combine the clauses.\n\n.. code:: python\n\n from validoot import validates, inst, typ, between, len_between, And\n\n @validates(And(inst(basestring), len_between(5, 40)), typ(int), between(0, 100))\n def do_something(name, id, age):\n pass\n\nAn ``Or`` operator also exists. Both ``And`` and ``Or`` take in a\nvariable number of clauses and can be nested further.\n\nOperator shortcuts are provided for joining clauses in a different\nmanner which reads differently (``._and(...)``, ``._or(...)``). So our\nprevious example can be changed to look like this:\n\n.. code:: python\n\n from validoot import validates, inst, typ, between, len_between\n\n @validates(inst(basestring)._and(len_between(5, 40)), typ(int), between(0, 100))\n def do_something(name, id, age):\n pass\n\nOperators can also be combined in more complicated ways:\n\n.. code:: python\n\n inst(basestring)._and(len_between(5, 40))._or(typ(int))\n\nKeyword arguments:\n^^^^^^^^^^^^^^^^^^\n\nThere is also support for keyword arguments:\n\n.. code:: python\n\n from validoot import validates, inst, typ\n\n @validates(inst(basestring), something=typ(float))\n def do_something(name, something=1.0, anotherthing=2):\n pass\n\nHere the ``something`` value must pass the validation checks as\nspecified in the decorator. No checks exist for ``anotherthing`` so it\nhas no restrictions.\n\nDecorating Class/Static/Instance methods or Constructors:\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nMethods belonging to classes can be validated as well in exactly the same way\nas the examples above. Please make note of the order of the ``@validates``\ndecorator and other decorators such as ``@classmethod`` or ``@staticmethod``.\n\n.. code:: python\n\n class SomeClass(object):\n\n # classmethod MUST be the innermost decorator!\n @validates(typ(int))\n @classmethod\n def some_class_method(cls, an_integer):\n return an_integer\n\n # staticmethod can be outer or inner decorator\n @staticmethod\n @validates(typ(float))\n def some_static_method(a_floater):\n return a_floater\n\n @validates(typ(string))\n def some_instance_method(self, a_string):\n return a_string\n\nIn order to validate arguments passed through to a constructor, the validates\ndecorator should be places on the class itself:\n\n.. code:: python\n\n @validates(typ(string))\n class SomeClass(object):\n\n def __init__(self, username):\n self.username = username\n\nAdditional Clauses:\n^^^^^^^^^^^^^^^^^^^\n\nThere are some more complex clauses included with the package:\n\n- ``_`` : The underscore only allows ``NoneType``.\n- ``numeric`` : Only accepts ``int``, ``float``, or ``long`` types.\n- ``text`` : Only accepts instances of ``basestring`` (Python 2) or\n ``str`` (Python 3).\n- ``positive`` : Only positive numbers\n- ``negative`` : Only positive numbers\n- ``email_address`` : Simple regex email check (covers most basic examples)\n- ``ip_address`` : Only accept an IPv4 address\n- ``url`` : Simple regex url check (covers most basic examples)\n\nThese can be found in the ``validoot.builtins`` module.\n\nFAQ:\n^^^^\n\nWhat if I don\u2019t want validation for one of the position arguments?\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSimple. Just use ``None``.\n\n.. code:: python\n\n from validoot import validates, inst, between\n\n @validates(inst(basestring), None, between(0, 100))\n def do_something(name, id, age):\n pass\n\nWhat validation clauses are built in?\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n- ``typ(t)`` - value must be of exact type ``t``\n- ``inst(t)`` - value must be of exact type ``t`` or of a subclass\n- ``between(lower, upper, lower_inc=True, upper_inc=False)`` - the\n value must between ``lower`` and ``upper``. ``lower_inc`` and ``upper_inc``\n indicate range inclusivity.\n- ``len_between(...)`` - identical to ``between`` but uses\n ``len(value)``\n- ``regex(string)`` - value must match the regex string provided\n- ``list_of(v)`` - value must be a list of objects that pass the validation ``v``\n- ``dict_of(v1, v2)`` - value must be a dictionary where each key passes validation ``v1`` and each value passes validation ``v2``\n\n\nHow do I create my own validation clauses?\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe built in clauses provided by Validoot are all subclasses of the\n``validoot.clauses.Clause`` object. Check out its source code to see\nhow they work. Technically clauses can be any callable object so plain\nfunctions or lambdas also work.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/AstromechZA/validoot/tarball/1.3", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/AstromechZA/validoot", "keywords": "validate,function arguments,decorator", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "validoot", "package_url": "https://pypi.org/project/validoot/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/validoot/", "project_urls": { "Download": "https://github.com/AstromechZA/validoot/tarball/1.3", "Homepage": "http://github.com/AstromechZA/validoot" }, "release_url": "https://pypi.org/project/validoot/1.3/", "requires_dist": null, "requires_python": null, "summary": "Simple validation for function arguments using a decorator.", "version": "1.3" }, "last_serial": 1491766, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "d12c8b09e202b2f04884f5e841c476c5", "sha256": "552d578f70d6239c4698a34c0f5b049a8d771f36472191312bf70824886fc14e" }, "downloads": -1, "filename": "validoot-1.0.tar.gz", "has_sig": false, "md5_digest": "d12c8b09e202b2f04884f5e841c476c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4525, "upload_time": "2015-03-08T17:00:56", "url": "https://files.pythonhosted.org/packages/5b/b4/585fd80ebec376947c0268d84280a8ebf36c138f41bdebf7b82eac96c4cf/validoot-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "a665cd7ad9793c0664c57fe58047a4d3", "sha256": "36d4ffd92df77b81a23a6b0f3cf8de0ae98a1ae2626108f8bd10fbabada4b19a" }, "downloads": -1, "filename": "validoot-1.1.tar.gz", "has_sig": false, "md5_digest": "a665cd7ad9793c0664c57fe58047a4d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5331, "upload_time": "2015-03-27T21:18:53", "url": "https://files.pythonhosted.org/packages/a9/e4/02ed6228bb82850ace1217b7a2ff2cae3cb2ab955933d5b279c8b29a4af1/validoot-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "ceeffcc177a7984a166eb5453b5fa980", "sha256": "c89db89eceb3bb0bf7261ea582766d1d3551a4ee238335817310d4c8369332ec" }, "downloads": -1, "filename": "validoot-1.2.tar.gz", "has_sig": false, "md5_digest": "ceeffcc177a7984a166eb5453b5fa980", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5966, "upload_time": "2015-03-29T19:28:08", "url": "https://files.pythonhosted.org/packages/62/f4/3ff4853e8277814bb991d02007e91112386ea6cb3b6106d4638c4d0774a7/validoot-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "1c3df44e559621c5e88cb449d23745b7", "sha256": "4f10e501b1f4e2e964eb8c5b67c011ce6f8ff2e4b11669818c93275880e3186a" }, "downloads": -1, "filename": "validoot-1.3.tar.gz", "has_sig": false, "md5_digest": "1c3df44e559621c5e88cb449d23745b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7431, "upload_time": "2015-04-05T13:59:57", "url": "https://files.pythonhosted.org/packages/41/e1/5830049afb24169d0343fe200c904990744e1000629b5c75c5fca14667b1/validoot-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1c3df44e559621c5e88cb449d23745b7", "sha256": "4f10e501b1f4e2e964eb8c5b67c011ce6f8ff2e4b11669818c93275880e3186a" }, "downloads": -1, "filename": "validoot-1.3.tar.gz", "has_sig": false, "md5_digest": "1c3df44e559621c5e88cb449d23745b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7431, "upload_time": "2015-04-05T13:59:57", "url": "https://files.pythonhosted.org/packages/41/e1/5830049afb24169d0343fe200c904990744e1000629b5c75c5fca14667b1/validoot-1.3.tar.gz" } ] }