<commit_before>from warnings import warn
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from vies import VATIN, VIES_COUNTRY_CHOICES
from vies.widgets import VATINWidget, VATINHiddenWidget


class VATINField(forms.MultiValueField):
    """VIES VAT field. That verifies on the fly."""
    hidden_widget = VATINHiddenWidget

    def __init__(self, choices=VIES_COUNTRY_CHOICES, *args, **kwargs):
        max_length = kwargs.pop('max_length', 14)
        fields = (
            forms.ChoiceField(required=False, choices=choices),
            forms.CharField(required=False, max_length=max_length)
        )
        widget = VATINWidget(choices=choices)
        super(VATINField, self).__init__(widget=widget, fields=fields, *args, **kwargs)

    def compress(self, data_list):
        if data_list:
            return "".join(data_list)
        return None

    def clean(self, value):
        if not value or not isinstance(value, (list, tuple)):
            if not value or not [v for v in value if v not in self.empty_values]:
                if self.required:
                    raise ValidationError(self.error_messages['required'], code='required')
                else:
                    return self.compress([])
        else:
            try:
                vatin = VATIN(*value)
                if vatin.is_valid():
                    return super(VATINField, self).clean(value)
                else:
                    raise ValidationError(_('%(value)s is not a valid European VAT.'), code='invalid',
                                          params={'value': self.compress(value)})
            except ValueError:
                raise ValidationError(_('%(value)s is not a valid European VAT.'), code='invalid',
                                      params={'value': self.compress(value)})


class VIESField(VATINField):
    """Deprecated in favor of VATINField"""
    def __init__(self, *args, **kwargs):
        warn(DeprecationWarning, '%(class)s has been deprecated in favor of VATINField')
        super(VIESField, self).__init__(*args, **kwargs)<commit_msg>changes empty from none to empty string.<commit_after>from warnings import warn
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from vies import VATIN, VIES_COUNTRY_CHOICES
from vies.widgets import VATINWidget, VATINHiddenWidget


class VATINField(forms.MultiValueField):
    """VIES VAT field. That verifies on the fly."""
    hidden_widget = VATINHiddenWidget

    def __init__(self, choices=VIES_COUNTRY_CHOICES, *args, **kwargs):
        max_length = kwargs.pop('max_length', 14)
        fields = (
            forms.ChoiceField(required=False, choices=choices),
            forms.CharField(required=False, max_length=max_length)
        )
        widget = VATINWidget(choices=choices)
        super(VATINField, self).__init__(widget=widget, fields=fields, *args, **kwargs)

    def compress(self, data_list):
        if data_list:
            return "".join(data_list)
        return ''

    def clean(self, value):
        if not value or not isinstance(value, (list, tuple)):
            if not value or not [v for v in value if v not in self.empty_values]:
                if self.required:
                    raise ValidationError(self.error_messages['required'], code='required')
                else:
                    return self.compress([])
        else:
            try:
                vatin = VATIN(*value)
                if vatin.is_valid():
                    return super(VATINField, self).clean(value)
                else:
                    raise ValidationError(_('%(value)s is not a valid European VAT.'), code='invalid',
                                          params={'value': self.compress(value)})
            except ValueError:
                raise ValidationError(_('%(value)s is not a valid European VAT.'), code='invalid',
                                      params={'value': self.compress(value)})


class VIESField(VATINField):
    """Deprecated in favor of VATINField"""
    def __init__(self, *args, **kwargs):
        warn(DeprecationWarning, '%(class)s has been deprecated in favor of VATINField')
        super(VIESField, self).__init__(*args, **kwargs)
{'fraction_non_alphanumeric': 0.10135601011261779, 'fraction_numerical': 0.0009193288899103654, 'mean_word_length': 2.373643410852713, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1302132', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1137, 'n_words': 322}