<commit_before>import re
from IPy import IP

from django import forms
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe

class NetInput(forms.Widget):
    input_type = 'text'

    def render(self, name, value, attrs=None):
        # Default forms.Widget compares value != '' which breaks IP...
        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value:
            final_attrs['value'] = force_unicode(value)
        return mark_safe(u'<input%s />' % forms.util.flatatt(final_attrs))


class NetAddressFormField(forms.Field):
    widget = NetInput
    default_error_messages = {
        'invalid': u'Enter a valid IP Address.',
    }

    def __init__(self, *args, **kwargs):
        super(NetAddressFormField, self).__init__(*args, **kwargs)

    def clean(self, value):
        super(NetAddressFormField, self).clean(value)

        if value in (None, ''):
            return None
        if isinstance(value, IP):
            return value
        try:
            return IP(value)
        except ValueError, e:
            raise forms.ValidationError(e)

<commit_msg>Override to_python instead of clean<commit_after>import re
from IPy import IP

from django import forms
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe

class NetInput(forms.Widget):
    input_type = 'text'

    def render(self, name, value, attrs=None):
        # Default forms.Widget compares value != '' which breaks IP...
        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value:
            final_attrs['value'] = force_unicode(value)
        return mark_safe(u'<input%s />' % forms.util.flatatt(final_attrs))


class NetAddressFormField(forms.Field):
    widget = NetInput
    default_error_messages = {
        'invalid': u'Enter a valid IP Address.',
    }

    def __init__(self, *args, **kwargs):
        super(NetAddressFormField, self).__init__(*args, **kwargs)

    def to_python(self, value):
        if not value:
            return None

        if isinstance(value, IP):
            return value

        return self.python_type(value)


{'fraction_non_alphanumeric': 0.10331125827814569, 'fraction_numerical': 0.0, 'mean_word_length': 2.821247892074199, 'pattern_counts': {'":': 0, '<': 5, '<?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': '763450', 'n_tokens_mistral': 664, 'n_tokens_neox': 648, 'n_words': 179}