<commit_before>from django.core.validators import *
from django.core.exceptions import ValidationError

import magic


class MimetypeValidator(object):
    def __init__(self, mimetypes):
        self.mimetypes = mimetypes

    def __call__(self, value):
        try:
            mime = magic.from_buffer(value.read(), mime=True)
            if not mime in self.mimetypes:
                raise ValidationError('%s is not an acceptable file type' % value)
                #raise ValidationError('%s is not an acceptable file type' % mime)
                #raise ValidationError('{} {}'.format(value, mime))
        except AttributeError as e:
            raise ValidationError('This value could not be validated for file type' % value)


credit_gpa_validator = RegexValidator(
    regex='^[0-9]{1,}\.[0-9]{1,2}$',
    message='Valid inputs are: eg. 4.00 or 132.5',
    code='invalid_gpa_or_credit'
)
<commit_msg>new date validator that ensures that the input conforms to unix epoch where year must be greater than or equal to 1900<commit_after>from django.core.validators import *
from django.core.exceptions import ValidationError

import magic
import datetime


class MimetypeValidator(object):
    def __init__(self, mimetypes):
        self.mimetypes = mimetypes

    def __call__(self, value):
        try:
            mime = magic.from_buffer(value.read(), mime=True)
            if not mime in self.mimetypes:
                raise ValidationError('%s is not an acceptable file type' % value)
                #raise ValidationError('%s is not an acceptable file type' % mime)
                #raise ValidationError('{} {}'.format(value, mime))
        except AttributeError as e:
            raise ValidationError('This value could not be validated for file type' % value)



def validate_epoch(value):
    if value < datetime.date(1900, 1, 1):
        raise ValidationError(
            'Year %(value)s must be greater than 1900',
            params={'value': value.year},
        )

credit_gpa_validator = RegexValidator(
    regex='^[0-9]{1,}\.[0-9]{1,2}$',
    message='Valid inputs are: eg. 4.00 or 132.5',
    code='invalid_gpa_or_credit'
)

{'fraction_non_alphanumeric': 0.10404087320018579, 'fraction_numerical': 0.019507663725034836, 'mean_word_length': 2.8464285714285715, 'pattern_counts': {'":': 0, '<': 4, '<?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': '4123563', 'n_tokens_mistral': 667, 'n_tokens_neox': 617, 'n_words': 193}