Metadata-Version: 1.0
Name: datatype
Version: 0.8.1
Summary: Anonymous datatype validation
Home-page: https://github.com/LearningStation/datatype
Author: Adam Wagner
Author-email: awagner83@gmail.com
License: BSD3
Description: datatype - Anonymous datatype validation and coercion
        =====================================================
        
        Examples
        --------
        ::
        
            >>> from datatype.validation import failures
        
            >>> datatype = {'foo': [{'bar': 'int'}]}
            >>> bad_value = {'foo': [{'bar': 'baz'}], 'bif': 'pow!'}
        
            >>> failures(datatype, bad_value)
            ['unexpected property "bif"', 'foo[0].bar: expected int, got str']
        
        
        Wildcard dictionary keys::
        
            >>> datatype = {'_any_': ['int']}
            >>> good_value = {'foo': [1, 2, 3], 'bar': [3, 4, 5]}
        
            >>> failures(datatype, good_value)
            []
        
        
        Coercion::
        
            >>> from datatype.coercion import coerce_value
        
            >>> coerce_value(['str'], [1, 2, 3])
            ['1', '2', '3']
        
        
        Datatype Definitions
        --------------------
        
        Datatype definitions are represented with a small set of types that should be
        built-in for *most* languages.
        
        Required types for proper validation:
        
        * int
        * float
        * string
        * boolean
        * dictionary (or anonymous object)
        * list (or array)
        
        
        Specification
        -------------
        ::
        
            DEFINITION = PRIMITIVE | LIST | DICTIONARY | TUPLE
            PRIMITIVE = ["nullable "] + ("int" | "str" | "float" | "bool")
            DICTIONARY = (dictionary of) key: DICTIONARY-KEY, value: DEFINITION
            DICTIONARY-KEY = (["optional "] + DICTIONARY-KEY-NAME) | "_any_"
            DICTIONARY-KEY-NAME = [A-Za-z0-9_]+
            LIST = (list of one) DEFINITION
            TUPLE = (list of more than one) DEFINITION
        
        
        Definition Examples (in python)
        -------------------------------
        ::
        
            definition: "int"
            example value: 5
        
            definition: {"foo": "int"}
            example value: {"foo": 5}
        
            definition: [{"foo": ["bool"]}]
            example value: [{"foo": [True, False]}, {"foo": [False, False]}]
        
            definition: {"_any_": "int"}
            example value: {"foo": 5, "bar": 7}
        
            definition: ["int", "str"]
            example value: [5, "foo"]
        
        
        Copyright and License
        ---------------------
        
        Copyright 2011-2012 LearningStation, Inc. and Adam Wagner
        
        Licensed under the BSD-3 License.  You may obtain a copy of the License in the
        LICENSE file.
        
        
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Software Development
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Libraries
