<commit_before>import re

from django import forms
from widgets import ParsleyChoiceFieldRendererMixin

FIELD_TYPES = [
    (forms.URLField, "url"),
    (forms.EmailField, "email"),
    (forms.IntegerField, "digits"),
    (forms.DecimalField, "number"),
    (forms.FloatField, "number"),
]


FIELD_ATTRS = [
    ("min_length", "minlength"),
    ("max_length", "maxlength"),
    ("min_value", "min"),
    ("max_value", "max"),
]


def update_widget_attrs(field, prefix='data'):
    attrs = field.widget.attrs
    if field.required:
        if isinstance(field, forms.ChoiceField):
            class ParsleyChoiceFieldRenderer(ParsleyChoiceFieldRendererMixin, field.widget.renderer):
                parsley_namespace = prefix
            field.widget.renderer = ParsleyChoiceFieldRenderer
        else:
            attrs["{prefix}-required".format(prefix=prefix)] = "true"
            error_message = field.error_messages.get('required', None)
            if error_message:
                attrs["{prefix}-required-message".format(prefix=prefix)] = error_message

    if isinstance(field, forms.RegexField):
        attrs.update({"{prefix}-regexp".format(prefix=prefix): field.regex.pattern})
<commit_msg>Added comment<commit_after>import re

from django import forms
from widgets import ParsleyChoiceFieldRendererMixin

FIELD_TYPES = [
    (forms.URLField, "url"),
    (forms.EmailField, "email"),
    (forms.IntegerField, "digits"),
    (forms.DecimalField, "number"),
    (forms.FloatField, "number"),
]


FIELD_ATTRS = [
    ("min_length", "minlength"),
    ("max_length", "maxlength"),
    ("min_value", "min"),
    ("max_value", "max"),
]


def update_widget_attrs(field, prefix='data'):
    attrs = field.widget.attrs
    if field.required:
        if isinstance(field, forms.ChoiceField):
            # Use a mixin, to try and support non-standard renderers if possible
            class ParsleyChoiceFieldRenderer(ParsleyChoiceFieldRendererMixin, field.widget.renderer):
                parsley_namespace = prefix
            field.widget.renderer = ParsleyChoiceFieldRenderer
        else:
            attrs["{prefix}-required".format(prefix=prefix)] = "true"
            error_message = field.error_messages.get('required', None)
            if error_message:
                attrs["{prefix}-required-message".format(prefix=prefix)] = error_message

    if isinstance(field, forms.RegexField):
        attrs.update({"{prefix}-regexp".format(prefix=prefix): field.regex.pattern})

{'fraction_non_alphanumeric': 0.13137806347930897, 'fraction_numerical': 0.0, 'mean_word_length': 3.3760984182776803, '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': '3586199', 'n_tokens_mistral': 713, 'n_tokens_neox': 707, 'n_words': 136}