<commit_before>import re

# Abstracted to simplify unit testing via mock
def Invalid(message):
    import ckan.plugins.toolkit as tk
    raise tk.Invalid(message)

def dedupe_unordered(items):
    return list(set(items))

def is_alphanumeric_plus(str):
    '''Check that all characters are are alphanumeric or [space,_,-,.,/,:].'''
    return re.match('^[-.:/\w ]+$', ''.join(str)) is not None

def input_value_validator(value):
    if "__Other" in value :
        Invalid("'Other, please specify' is not a valid option")
    if not is_alphanumeric_plus(value):
        Invalid('A selected field cannot include most special characters')
    # assume that duplicates are mistakes continue quietly
    if not isinstance(value, basestring):
        value = dedupe_unordered(value)
    return value

# check multiple fields at once
# http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html#custom-validators
def check_all(key, flattened_data, errors, context):
    return

def pra_control_num_validator(value):
    PRA_CONTROL_NUM_REGEX = re.compile('^\d{4}-\d{4}$')
    if value and not PRA_CONTROL_NUM_REGEX.match(value):
        Invalid("Must be in the format ####-####")
    return value

def dig_id_validator(value):
    DIG_ID_REGEX = re.compile('^DI\d{5}$')
    if value and not DIG_ID_REGEX.match(value):
        Invalid("Must be in the format DI#####")
    return value


def positive_number_validator(value):
    # feels incredibly verbose... requires code review
    if value:
        try:
            if float(value) < 0:
                Invalid("Must be a positive number")
        except ValueError:
            Invalid("Must be a positive number")
    return value



<commit_msg>broken date validator<commit_after>import re

# Abstracted to simplify unit testing via mock
def Invalid(message):
    import ckan.plugins.toolkit as tk
    raise tk.Invalid(message)

def dedupe_unordered(items):
    return list(set(items))

def is_alphanumeric_plus(str):
    '''Check that all characters are are alphanumeric or [space,_,-,.,/,:].'''
    return re.match('^[-.:/\w ]+$', ''.join(str)) is not None

def input_value_validator(value):
    if "__Other" in value :
        Invalid("'Other, please specify' is not a valid option")
    if not is_alphanumeric_plus(value):
        Invalid('A selected field cannot include most special characters')
    # assume that duplicates are mistakes continue quietly
    if not isinstance(value, basestring):
        value = dedupe_unordered(value)
    return value

# check multiple fields at once
# http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html#custom-validators
def check_all(key, flattened_data, errors, context):
    return

def pra_control_num_validator(value):
    PRA_CONTROL_NUM_REGEX = re.compile('^\d{4}-\d{4}$')
    if value and not PRA_CONTROL_NUM_REGEX.match(value):
        Invalid("Must be in the format ####-####")
    return value

def dig_id_validator(value):
    DIG_ID_REGEX = re.compile('^DI\d{5}$')
    if value and not DIG_ID_REGEX.match(value):
        Invalid("Must be in the format DI#####")
    return value


def positive_number_validator(value):
    # feels incredibly verbose... requires code review
    if value:
        try:
            if float(value) < 0:
                Invalid("Must be a positive number")
        except ValueError:
            Invalid("Must be a positive number")
    return value

def reasonable_date_validator(value):
    ''' check the year is between 1700 and 2300 '''
# TODO: this doesn't work as expected. Feels like a CKAN bug with custom resource fields.
#     if value:
#         date = int(value.replace('-',''))
#         if date < 1700*10000 or date > 2300*10000:
#             print 'this does not work!'+str(date)+value
#             Invalid("The chosen year is out of range.")
#         return value
#     else: 
#         return value
    return value


{'fraction_non_alphanumeric': 0.11364802462801436, 'fraction_numerical': 0.008722421754746024, 'mean_word_length': 3.2196969696969697, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '1673488', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1159, 'n_words': 360}