#NEWLINE# def clean( self , value ) : #NEWLINE# #INDENT# '\n        Value can be either a string in the format XXX.XXX.XXX-XX or an\n        11-digit number.\n        ' #NEWLINE# value = super ( BRCPFField , self ) . clean ( value ) #NEWLINE# if ( value in EMPTY_VALUES ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# orig_value = value [ : ] #NEWLINE# if ( not value . isdigit ( ) ) : #NEWLINE# #INDENT# value = re . sub ( '[-\\.]' , '' , value ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# int ( value ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'digits_only' ] ) #NEWLINE# #UNINDENT# if ( len ( value ) != 11 ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'max_digits' ] ) #NEWLINE# #UNINDENT# orig_dv = value [ ( - 2 ) : ] #NEWLINE# new_1dv = sum ( [ ( i * int ( value [ idx ] ) ) for ( idx , i ) in enumerate ( range ( 10 , 1 , ( - 1 ) ) ) ] ) #NEWLINE# new_1dv = DV_maker ( ( new_1dv % 11 ) ) #NEWLINE# value = ( ( value [ : ( - 2 ) ] + str ( new_1dv ) ) + value [ ( - 1 ) ] ) #NEWLINE# new_2dv = sum ( [ ( i * int ( value [ idx ] ) ) for ( idx , i ) in enumerate ( range ( 11 , 1 , ( - 1 ) ) ) ] ) #NEWLINE# new_2dv = DV_maker ( ( new_2dv % 11 ) ) #NEWLINE# value = ( value [ : ( - 1 ) ] + str ( new_2dv ) ) #NEWLINE# if ( value [ ( - 2 ) : ] != orig_dv ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# return orig_value