Anonymous datatype validation
Project description
datatype - Anonymous datatype validation
========================================
Example:
--------
>>> from datatype.validation import failures
>>> datatype = {'foo': [{'bar': 'int'}]}
>>> bad_value = {'foo': [{'bar': 'baz'}], 'bif': 'pow!'}
>>> failures(datatype, bad_value)
['foo[0].bar: expected int, got str', 'unexpected property "bif"']
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
PRIMITIVE = ["nullable "] + ("int" | "str" | "float" | "bool")
DICTIONARY = {DICTIONARY-KEY: DEFINITION}
DICTIONARY-KEY = ["optional "] + DICTIONARY-KEY-NAME
DICTIONARY-KEY-NAME = [A-Za-z0-9_]+
LIST = [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]}]
Copyright and License
---------------------
Copyright 2011 LearningStation, Inc.
Licensed under the BSD-3 License. You may obtain a copy of the License in the
LICENSE file.
========================================
Example:
--------
>>> from datatype.validation import failures
>>> datatype = {'foo': [{'bar': 'int'}]}
>>> bad_value = {'foo': [{'bar': 'baz'}], 'bif': 'pow!'}
>>> failures(datatype, bad_value)
['foo[0].bar: expected int, got str', 'unexpected property "bif"']
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
PRIMITIVE = ["nullable "] + ("int" | "str" | "float" | "bool")
DICTIONARY = {DICTIONARY-KEY: DEFINITION}
DICTIONARY-KEY = ["optional "] + DICTIONARY-KEY-NAME
DICTIONARY-KEY-NAME = [A-Za-z0-9_]+
LIST = [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]}]
Copyright and License
---------------------
Copyright 2011 LearningStation, Inc.
Licensed under the BSD-3 License. You may obtain a copy of the License in the
LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
datatype-0.2.tar.gz
(2.5 kB
view details)
File details
Details for the file datatype-0.2.tar.gz.
File metadata
- Download URL: datatype-0.2.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f62051a51231cedd4da7375bde9f4eefb415d787971481ba779052d5774c616b
|
|
| MD5 |
6a7095413469e64869058b710d9f2f17
|
|
| BLAKE2b-256 |
4a3b0ae3180470370a8cecde102a1e940339ead41d01ed65cf064e7e572cb970
|