<commit_before># -*- coding: utf-8 -*-

from datetime import datetime
import bson

from voluptuous import Required, All, Length, Schema, Invalid, Optional, Any, Extra

def date_validator(value):
    """Custom validator (only a few types are natively implemented in voluptuous)
    """
    if isinstance(value, datetime):
        return value
    else:
        raise Invalid('Input date was not of type datetime')

def typecheck(type, msg=None):
    """Coerce a value to a type.

    If the type constructor throws a ValueError, the value will be marked as
    Invalid.
    """
    def validator(value):
        if not isinstance(value,type):
            raise Invalid(msg or ('expected %s' % type.__name__))
        else:
            return value
    return validator

#Schema definition in voluptuous
revision_schema = {str: [{Required('value'): str,
                          Required('releaseDate'): date_validator}]}

codedict_schema = Schema({Extra: dict})

provider_schema = Schema({
    'name': All(str, Length(min=1)),
    'longName': All(str, Length(min=1)),
    'slug': All(str, Length(min=1)),
    'region': All(str, Length(min=1)),
    'website': All(str, Length(min=9))
    },required=True)

category_schema = Schema({
    'name': All(str, Length(min=1)),
    'provider': All(str, Length(min=1)),
    'children': Any(None,[typecheck(bson.objectid.ObjectId)]), 
    Optional('docHref'): Any(None,str),
    Optional('lastUpdate'): Any(None,typecheck(datetime)),
    'categoryCode': All(str, Length(min=1)),
    'exposed': typecheck(bool)
    }, required=True)


dataset_schema = Schema({
    'name': All(str, Length(min=1)),
    'provider': All(str, Length(min=1)),
    'datasetCode': All(str, Length(min=1)),
    'docHref': Any(None,str),<commit_msg>replaced category_schema by data_tree_schema<commit_after># -*- coding: utf-8 -*-

from datetime import datetime
import bson

from voluptuous import Required, All, Length, Schema, Invalid, Optional, Any, Extra

def date_validator(value):
    """Custom validator (only a few types are natively implemented in voluptuous)
    """
    if isinstance(value, datetime):
        return value
    else:
        raise Invalid('Input date was not of type datetime')

def typecheck(type, msg=None):
    """Coerce a value to a type.

    If the type constructor throws a ValueError, the value will be marked as
    Invalid.
    """
    def validator(value):
        if not isinstance(value,type):
            raise Invalid(msg or ('expected %s' % type.__name__))
        else:
            return value
    return validator

#Schema definition in voluptuous
revision_schema = {str: [{Required('value'): str,
                          Required('releaseDate'): date_validator}]}

codedict_schema = Schema({Extra: dict})

provider_schema = Schema({
    'name': All(str, Length(min=1)),
    'longName': All(str, Length(min=1)),
    'slug': All(str, Length(min=1)),
    'region': All(str, Length(min=1)),
    'website': All(str, Length(min=9))
    },required=True)

def _data_tree(value):
    return data_tree_schema(value)

data_tree_schema = Schema({
    'name': All(str, Length(min=1)),
    'provider': All(str, Length(min=1)),
    'children': Any(None,[_data_tree]), 
    Optional('docHref'): Any(None,str),
    Optional('lastUpdate'): Any(None,typecheck(datetime)),
    'categoryCode': All(str, Length(min=1)),
    Optional('exposed'): typecheck(bool)
    }, required=True)


dataset_schema = Schema({
    'name': All(str, Length(min=1)),
    'provider': All(str, Length(min=1)),
    'datasetCode': All(str, Length(min=1)),
    'docHref': Any(None,str),
{'fraction_non_alphanumeric': 0.14908384230982788, 'fraction_numerical': 0.006662965019433648, 'mean_word_length': 3.7221494102228045, 'pattern_counts': {'":': 0, '<': 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': '7290755', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1112, 'n_words': 306}