<commit_before>import json

import django
from django import forms
from django.core.exceptions import ValidationError
from django.urls import reverse
from django.template import loader
from django.utils.encoding import force_text

from select2rocks.settings import SELECT2_OPTIONS, SELECT2_ATTRS


class Select2TextInput(forms.TextInput):
    is_required = False

    def get_context(self, name, value, attrs=None):
        context = {
            'type': self.input_type,
            'name': name,
            'hidden': self.is_hidden,
            'required': self.is_required,
        }

        if value is not None:
            # Only add the value if it is non-empty
            context['value'] = self._format_value(value)

        if django.VERSION >= (1, 11):
            context['attrs'] = self.build_attrs(self.attrs, attrs)
        else:
            context['attrs'] = self.build_attrs(attrs)

        for key, attr in context['attrs'].items():
            if attr == 1:
                # 1 == True so 'key="1"' will show up only as 'key'
                if not isinstance(attr, bool):<commit_msg>widgets: use format_value instead of _format_value<commit_after>import json

import django
from django import forms
from django.core.exceptions import ValidationError
from django.urls import reverse
from django.template import loader
from django.utils.encoding import force_text

from select2rocks.settings import SELECT2_OPTIONS, SELECT2_ATTRS


class Select2TextInput(forms.TextInput):
    is_required = False

    def get_context(self, name, value, attrs=None):
        context = {
            'type': self.input_type,
            'name': name,
            'hidden': self.is_hidden,
            'required': self.is_required,
        }

        if value is not None:
            # Only add the value if it is non-empty
            context['value'] = self.format_value(value)

        if django.VERSION >= (1, 11):
            context['attrs'] = self.build_attrs(self.attrs, attrs)
        else:
            context['attrs'] = self.build_attrs(attrs)

        for key, attr in context['attrs'].items():
            if attr == 1:
                # 1 == True so 'key="1"' will show up only as 'key'
                if not isinstance(attr, bool):
{'fraction_non_alphanumeric': 0.09635879218472469, 'fraction_numerical': 0.008880994671403197, 'mean_word_length': 2.4136363636363636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '736319', 'n_tokens_mistral': 637, 'n_tokens_neox': 611, 'n_words': 192}