def clean(self, value):
        super(SIEMSOField, self).clean(value)
        if value in EMPTY_VALUES:
            return u''

        value = value.strip()

        m = self.emso_regex.match(value)
        if m is None:
            raise ValidationError(self.default_error_messages['invalid'])

        # Validate EMSO
        s = 0
        int_values = [int(i) for i in value]
        for a, b in zip(int_values, range(7, 1, -1) * 2):
            s += a * b
        chk = s % 11
        if chk == 0:
            K = 0
        else:
            K = 11 - chk

        if K == 10 or int_values[-1] != K:
            raise ValidationError(self.default_error_messages['checksum'])

        # Extract extra info in the identification number
        day, month, year, nationality, gender, chksum = [int(i) for i in m.groups()]

        if year < 890:
            year += 2000
        else:
            year += 1000

        # validate birthday
        try:
            birthday = datetime.date(year, month, day)
        except __HOLE__:
            raise ValidationError(self.error_messages['date'])
        if datetime.date.today() < birthday:
            raise ValidationError(self.error_messages['date'])

        self.info = {
            'gender': gender < 500 and 'male' or 'female',
            'birthdate': birthday,
            'nationality': nationality,
        }
        return value
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.4/django/contrib/localflavor/si/forms.py/SIEMSOField.clean