<s> """<STR_LIT>""" <EOL> import re , datetime <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 NOZipCodeField ( RegexField ) : <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( NOZipCodeField , self ) . __init__ ( r'<STR_LIT>' , <EOL> max_length = None , min_length = None , * args , ** kwargs ) <EOL> class NOMunicipalitySelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> from no_municipalities import MUNICIPALITY_CHOICES <EOL> super ( NOMunicipalitySelect , self ) . __init__ ( attrs , choices = MUNICIPALITY_CHOICES ) <EOL> class NOSocialSecurityNumber ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> super ( NOSocialSecurityNumber , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return u'<STR_LIT>' <EOL> if not re . match ( r'<STR_LIT>' , value ) : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> day = int ( value [ : <NUM_LIT:2> ] ) <EOL> month = int ( value [ <NUM_LIT:2> : <NUM_LIT:4> ] ) <EOL> year2 = int ( value [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> inum = int ( value [ <NUM_LIT:6> : <NUM_LIT:9> ] ) <EOL> self . birthday = None <EOL> try : <EOL> if <NUM_LIT> <= inum < <NUM_LIT> : <EOL> self . birthday = datetime . date ( <NUM_LIT> + year2 , month , day ) <EOL> if <NUM_LIT> <= inum < <NUM_LIT> and year2 > <NUM_LIT> : <EOL> self . birthday = datetime . date ( <NUM_LIT> + year2 , month , day ) <EOL> if <NUM_LIT> <= inum < <NUM_LIT:1000> and year2 < <NUM_LIT> : <EOL> self . birthday = datetime . date ( <NUM_LIT> + year2 , month , day ) <EOL> if <NUM_LIT> <= inum < <NUM_LIT:1000> and year2 > <NUM_LIT> : <EOL> self . birthday = datetime . date ( <NUM_LIT> + year2 , month , day ) <EOL> except ValueError : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> sexnum = int ( value [ <NUM_LIT:8> ] ) <EOL> if sexnum % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> self . gender = '<STR_LIT:F>' <EOL> else : <EOL> self . gender = '<STR_LIT:M>' <EOL> digits = map ( int , list ( value ) ) <EOL> weight_1 = [ <NUM_LIT:3> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> weight_2 = [ <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> def multiply_reduce ( aval , bval ) : <EOL> return sum ( [ ( a * b ) for ( a , b ) in zip ( aval , bval ) ] ) <EOL> if multiply_reduce ( digits , weight_1 ) % <NUM_LIT:11> != <NUM_LIT:0> : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> if multiply_reduce ( digits , weight_2 ) % <NUM_LIT:11> != <NUM_LIT:0> : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> return value </s>
