<commit_before>from django import forms
from django.conf import settings
from django.core.validators import RegexValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _


class SHA256ChecksumField(models.CharField):
    default_validators = [
        RegexValidator(
            regex=r'^[A-Fa-f0-9]{64}$',
            message=_('Invalid SHA256 checksum format'),
            code='invalid_sha256sum',
        ),
    ]
    description = _("SHA256 checksum")

    def __init__(self, blank=False):
        # SHA-256 checksum in hexadecimal representation takes up 64 chars,
        # e.g. 4bit * 64 = 256bit
        super().__init__(blank=blank, max_length=64)

    def deconstruct(self):
        name, path, args, kwargs = super().deconstruct()
        del kwargs['max_length']
        return name, path, args, kwargs

    def formfield(self, **kwargs):<commit_msg>Separate exact length and hexadecimal check<commit_after>from django import forms
from django.conf import settings
from django.core.validators import (
    RegexValidator, MinLengthValidator, MaxLengthValidator
)
from django.db import models
from django.utils.translation import ugettext_lazy as _


class SHA256ChecksumField(models.CharField):
    default_validators = [
        MinLengthValidator(64),
        MaxLengthValidator(64),
        RegexValidator(
            regex=r'^[A-Fa-f0-9]+$',
            message=_(
                'Invalid SHA256 checksum format, expected only '
                'hexadecimal digits'
            ),
            code='sha256sum_non_hexadecimal',
        ),
    ]
    description = _("SHA256 checksum")

    def __init__(self, blank=False):
        # SHA-256 checksum in hexadecimal representation takes up 64 chars,
        # e.g. 4bit * 64 = 256bit
        super().__init__(blank=blank, max_length=64)

    def deconstruct(self):
        name, path, args, kwargs = super().deconstruct()
        del kwargs['max_length']
        return name, path, args, kwargs

    def formfield(self, **kwargs):
{'fraction_non_alphanumeric': 0.09724950884086445, 'fraction_numerical': 0.029469548133595286, 'mean_word_length': 2.850661625708885, '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': '2614490', 'n_tokens_mistral': 630, 'n_tokens_neox': 576, 'n_words': 151}