<commit_before>#!/usr/bin/env python

from validictory.validator import SchemaValidator, ValidationError

__all__ = [ 'validate', 'SchemaValidator', 'ValidationError' ]
__version__ = '0.6.1'

def validate(data, schema, validator_cls=SchemaValidator,
             format_validators=None, required_by_default=True):
    '''
    Validates a parsed json document against the provided schema. If an
    error is found a ValueError is raised.

    ``data`` is a python dictionary object of parsed json data.

    ``schema`` is a python dictionary object representing the schema.

    If ``validator_cls`` is provided that class will be used to validate
    the given ``schema`` against the given ``data``. The given class should
    be a subclass of the SchemaValidator class.

    If ``format_validators`` is provided, the validator_cls will be
    instanciated with these default format validators.

    ``required_by_default`` specifies if ``required`` should default to True
    or False (default: True)
    '''
    v = validator_cls(format_validators, required_by_default)
    return v.validate(data,schema)

if __name__ == '__main__':
    import sys
    import json
    if len(sys.argv) == 2:
        if sys.argv[1] == "--help":
            raise SystemExit("%s SCHEMAFILE [INFILE]" % (sys.argv[0],))
        schemafile = open(sys.argv[1], 'rb')
        infile = sys.stdin
    elif len(sys.argv) == 3:
        schemafile = open(sys.argv[1], 'rb')
        infile = open(sys.argv[2], 'rb')
    else:
        raise SystemExit("%s SCHEMAFILE [INFILE]" % (sys.argv[0],))
    try:
        obj = json.load(infile)
        schema = json.load(schemafile)
        validate(obj, schema)
    except ValueError, e:
        raise SystemExit(e)
<commit_msg>bump version<commit_after>#!/usr/bin/env python

from validictory.validator import SchemaValidator, ValidationError

__all__ = [ 'validate', 'SchemaValidator', 'ValidationError' ]
__version__ = '0.6.2-dev'

def validate(data, schema, validator_cls=SchemaValidator,
             format_validators=None, required_by_default=True):
    '''
    Validates a parsed json document against the provided schema. If an
    error is found a ValueError is raised.

    ``data`` is a python dictionary object of parsed json data.

    ``schema`` is a python dictionary object representing the schema.

    If ``validator_cls`` is provided that class will be used to validate
    the given ``schema`` against the given ``data``. The given class should
    be a subclass of the SchemaValidator class.

    If ``format_validators`` is provided, the validator_cls will be
    instanciated with these default format validators.

    ``required_by_default`` specifies if ``required`` should default to True
    or False (default: True)
    '''
    v = validator_cls(format_validators, required_by_default)
    return v.validate(data,schema)

if __name__ == '__main__':
    import sys
    import json
    if len(sys.argv) == 2:
        if sys.argv[1] == "--help":
            raise SystemExit("%s SCHEMAFILE [INFILE]" % (sys.argv[0],))
        schemafile = open(sys.argv[1], 'rb')
        infile = sys.stdin
    elif len(sys.argv) == 3:
        schemafile = open(sys.argv[1], 'rb')
        infile = open(sys.argv[2], 'rb')
    else:
        raise SystemExit("%s SCHEMAFILE [INFILE]" % (sys.argv[0],))
    try:
        obj = json.load(infile)
        schema = json.load(schemafile)
        validate(obj, schema)
    except ValueError, e:
        raise SystemExit(e)

{'fraction_non_alphanumeric': 0.11155721250358475, 'fraction_numerical': 0.006309148264984227, 'mean_word_length': 3.197352587244284, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4003646', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1024, 'n_words': 333}