<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , unicode_literals <EOL> import re <EOL> from django . contrib . localflavor . fi . fi_municipalities import MUNICIPALITY_CHOICES <EOL> from django . core . validators import EMPTY_VALUES <EOL> from django . forms import ValidationError <EOL> from django . forms . fields import Field , RegexField , Select <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> class FIZipCodeField ( RegexField ) : <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , max_length = None , min_length = None , * args , ** kwargs ) : <EOL> super ( FIZipCodeField , self ) . __init__ ( r'<STR_LIT>' , <EOL> max_length , min_length , * args , ** kwargs ) <EOL> class FIMunicipalitySelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( FIMunicipalitySelect , self ) . __init__ ( attrs , choices = MUNICIPALITY_CHOICES ) <EOL> class FISocialSecurityNumber ( Field ) : <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> super ( FISocialSecurityNumber , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> checkmarks = "<STR_LIT>" <EOL> result = re . match ( r"""<STR_LIT>""" % checkmarks , value , re . VERBOSE | re . IGNORECASE ) <EOL> if not result : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> gd = result . groupdict ( ) <EOL> checksum = int ( gd [ '<STR_LIT:date>' ] + gd [ '<STR_LIT>' ] ) <EOL> if checkmarks [ checksum % len ( checkmarks ) ] == gd [ '<STR_LIT>' ] . upper ( ) : <EOL> return '<STR_LIT:%s>' % value . upper ( ) <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) </s>
