#NEWLINE# def clean( self , value ) : #NEWLINE# #INDENT# super ( NOSocialSecurityNumber , self ) . clean ( value ) #NEWLINE# if ( value in EMPTY_VALUES ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# if ( not re . match ( '^\\d{11}$' , value ) ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# day = int ( value [ : 2 ] ) #NEWLINE# month = int ( value [ 2 : 4 ] ) #NEWLINE# year2 = int ( value [ 4 : 6 ] ) #NEWLINE# inum = int ( value [ 6 : 9 ] ) #NEWLINE# self . birthday = None #NEWLINE# try : #NEWLINE# #INDENT# if ( 0 <= inum < 500 ) : #NEWLINE# #INDENT# self . birthday = datetime . date ( ( 1900 + year2 ) , month , day ) #NEWLINE# #UNINDENT# if ( ( 500 <= inum < 750 ) and ( year2 > 54 ) ) : #NEWLINE# #INDENT# self . birthday = datetime . date ( ( 1800 + year2 ) , month , day ) #NEWLINE# #UNINDENT# if ( ( 500 <= inum < 1000 ) and ( year2 < 40 ) ) : #NEWLINE# #INDENT# self . birthday = datetime . date ( ( 2000 + year2 ) , month , day ) #NEWLINE# #UNINDENT# if ( ( 900 <= inum < 1000 ) and ( year2 > 39 ) ) : #NEWLINE# #INDENT# self . birthday = datetime . date ( ( 1900 + year2 ) , month , day ) #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# sexnum = int ( value [ 8 ] ) #NEWLINE# if ( ( sexnum % 2 ) == 0 ) : #NEWLINE# #INDENT# self . gender = 'F' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . gender = 'M' #NEWLINE# #UNINDENT# digits = map ( int , list ( value ) ) #NEWLINE# weight_1 = [ 3 , 7 , 6 , 1 , 8 , 9 , 4 , 5 , 2 , 1 , 0 ] #NEWLINE# weight_2 = [ 5 , 4 , 3 , 2 , 7 , 6 , 5 , 4 , 3 , 2 , 1 ] #NEWLINE# def multiply_reduce( aval , bval ) : #NEWLINE# #INDENT# return sum ( [ ( a * b ) for ( a , b ) in zip ( aval , bval ) ] ) #NEWLINE# #UNINDENT# if ( ( multiply_reduce ( digits , weight_1 ) % 11 ) != 0 ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# if ( ( multiply_reduce ( digits , weight_2 ) % 11 ) != 0 ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# return value