<commit_before>Cerberus
========

.. image:: https://secure.travis-ci.org/nicolaiarocci/cerberus.png?branch=master 
        :target: https://secure.travis-ci.org/nicolaiarocci/cerberus

Cerberus is an ISC Licensed validation tool for Python dictionaries.

It provides type checking and basic functionality out of the box and is
designed to be easily extensible. It serves as one of the foundation blocks for
the (yet to be released) Eve RESTful Web API. Cerberus is tested for Python 2.6
and 2.7.

Features
--------
::

    >>> v = Validator({'name': {'type': 'string'}})
    >>> v.validate({'name': '<NAME>'})
    True

Unlike other validator tools, Cerberus will not raise an exception when the
first validation error is encountered. The whole document will always get
validated, and a list of issues will be provided afterwards.

::

    >>> schema = {'name': {'type': 'string'}, 'age': {'type': 'integer', 'min': 10}}
    >>> document = {'name': 1337, 'age': 5}
    >>> v.validate(document, schema)
    False

    >>> v.errors
    ["min value for field 'age' is 10", "value of field 'name' must be of string type"]

You will still get SchemaError and ValidationError exceptions on initialization
errors.

Testing
-------
::
<commit_msg>README: extending cerberus<commit_after>Cerberus
========

.. image:: https://secure.travis-ci.org/nicolaiarocci/cerberus.png?branch=master 
        :target: https://secure.travis-ci.org/nicolaiarocci/cerberus

Cerberus is an ISC Licensed validation tool for Python dictionaries.

It provides type checking and basic functionality out of the box and is
designed to be easily extensible. It serves as one of the foundation blocks for
the (yet to be released) Eve RESTful Web API. Cerberus is tested for Python 2.6
and 2.7. Support for Python 3.x is planned as well.

::

    >>> v = Validator({'name': {'type': 'string'}})
    >>> v.validate({'name': '<NAME>'})
    True

Non-blocking
------------
Unlike other validator tools, Cerberus will not raise an exception when the
first validation error is encountered. The whole document will always get
validated, and a list of issues will be provided afterwards.

::

    >>> schema = {'name': {'type': 'string'}, 'age': {'type': 'integer', 'min': 10}}
    >>> document = {'name': 1337, 'age': 5}
    >>> v.validate(document, schema)
    False

    >>> v.errors
    ["min value for field 'age' is 10", "value of field 'name' must be of string type"]

You will still get SchemaError and ValidationError exceptions on initialization
errors.

Customizing Cerberus
--------------------
Say that you need a certain value to be an odd integer. ::

    from cerberus import Validator


    class MyValidator(Validator):
        
        def _validate_isodd(self, isodd, field, value):
            if isodd and not bool(value & 1):
                self._error("Your error message")

You just subclass the Cerberus Validator and add ``_validate_RULENAME``, the
function that will validate your custom rule. Rule RULENAME is now available in
the schema definition.::

    >>> schema = {'age': {'isodd': True, 'type': 'integer'}}
    >>> v = MyValidator(schema)
    >>> v.validate({'age': 10})
    False

    >>> v.errors
    ['Your error message here']

    >>> v.validate({'age': 9})
    True

    >>> v.errors
    []

Testing
-------
::

{'fraction_non_alphanumeric': 0.13820156910078454, 'fraction_numerical': 0.009354254677127338, 'mean_word_length': 3.339005235602094, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6660626', 'n_tokens_mistral': 1006, 'n_tokens_neox': 951, 'n_words': 382}