<commit_before>from datetime import datetime
import re

import six

from ipuz.exceptions import IPUZException


def validate_bool(field_name, field_data):
    if type(field_data) is not bool:
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_int(field_name, field_data):
    # type instead of isinstance as bool inherits from int
    if type(field_data) is not int:
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_non_negative_int(field_name, field_data):
    if type(field_data) is not int or field_data < 0:
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_string(field_name, field_data):
    if not isinstance(field_data, six.string_types):
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_dict_of_strings(field_name, field_data):
    if type(field_data) is not dict:
        raise IPUZException("Invalid {} value found".format(field_name))
    for key, value in field_data.items():
        validate_string(field_name, key)
        validate_string(field_name, value)


def validate_list_of_strings(field_name, field_data):
    if type(field_data) is not list:
        raise IPUZException("Invalid {} value found".format(field_name))
    for element in field_data:
        validate_string(field_name, field_data)
<commit_msg>Refactor to reuse validation logic for integer<commit_after>from datetime import datetime
import re

import six

from ipuz.exceptions import IPUZException


def validate_bool(field_name, field_data):
    if type(field_data) is not bool:
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_int(field_name, field_data):
    # type instead of isinstance as bool inherits from int
    if type(field_data) is not int:
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_non_negative_int(field_name, field_data):
    validate_int(field_name, field_data)
    if field_data < 0:
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_string(field_name, field_data):
    if not isinstance(field_data, six.string_types):
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_dict_of_strings(field_name, field_data):
    if type(field_data) is not dict:
        raise IPUZException("Invalid {} value found".format(field_name))
    for key, value in field_data.items():
        validate_string(field_name, key)
        validate_string(field_name, value)


def validate_list_of_strings(field_name, field_data):
    if type(field_data) is not list:
        raise IPUZException("Invalid {} value found".format(field_name))
    for element in field_data:
        validate_string(field_name, field_data)

{'fraction_non_alphanumeric': 0.08508365966536134, 'fraction_numerical': 0.000711997152011392, 'mean_word_length': 4.553359683794467, 'pattern_counts': {'":': 0, '<': 5, '<?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': '464685', 'n_tokens_mistral': 845, 'n_tokens_neox': 829, 'n_words': 223}