<commit_before>from django import forms
from django.core.exceptions import ValidationError
from django.utils import six
from django.utils.encoding import force_text
from django.utils.translation import string_concat

from .widgets import DateRangeWidget


class DateRangeField(forms.Field):
    widget = DateRangeWidget

    def __init__(self, base=forms.DateField(), **kwargs):
        super(DateRangeField, self).__init__(**kwargs)
        self.base = base

    def to_python(self, value):
        # Try to coerce the value to unicode.
        unicode_value = force_text(value, strings_only=True)
        if isinstance(unicode_value, six.text_type):
            value = unicode_value.strip()

        if self.widget.separator in value:
            parts = value.split(self.widget.separator, 2)

            try:
                part1 = self.base.to_python(parts[0])
            except ValidationError as e:
                raise ValidationError(string_concat('Error in period beginning: ', e.message), e.code)

            try:
                part2 = self.base.to_python(parts[1])
            except ValidationError as e:
                raise ValidationError(string_concat('Error in period end: ', e.message), e.code)

            return part1, part2
        else:
            return ()
<commit_msg>Changed superclass to DateField and removed 'base' argument so that alternative input_forms can be passed and validated.<commit_after>from django import forms
from django.core.exceptions import ValidationError
from django.utils import six
from django.utils.encoding import force_text
from django.utils.translation import string_concat

from .widgets import DateRangeWidget


class DateRangeField(forms.DateField):
    widget = DateRangeWidget

    def to_python(self, value):
        # Try to coerce the value to unicode.
        unicode_value = force_text(value, strings_only=True)
        if isinstance(unicode_value, six.text_type):
            value = unicode_value.strip()

        if self.widget.separator in value:
            parts = value.split(self.widget.separator, 2)

            try:
                part1 = super().to_python(parts[0])
            except ValidationError as e:
                raise ValidationError(string_concat('Error in period beginning: ', e.message), e.code)

            try:
                part2 = super().to_python(parts[1])
            except ValidationError as e:
                raise ValidationError(string_concat('Error in period end: ', e.message), e.code)

            return part1, part2
        else:
            return ()

{'fraction_non_alphanumeric': 0.08003108003108003, 'fraction_numerical': 0.005439005439005439, 'mean_word_length': 2.561549100968188, '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': '4928622', 'n_tokens_mistral': 701, 'n_tokens_neox': 650, 'n_words': 196}