#NEWLINE# def validate_email( email ) : #NEWLINE# #INDENT# if ( len ( email ) > 254 ) : #NEWLINE# #INDENT# raise ValidationError ( 'Invalid Email' ) #NEWLINE# #UNINDENT# if ( ( not domain_part ) or ( '@' not in email ) ) : #NEWLINE# #INDENT# raise ValidationError ( 'Invalid Email' ) #NEWLINE# #UNINDENT# ( user_part , domain_part ) = email . rsplit ( '@' , 1 ) #NEWLINE# if ( not USER_REGEX . match ( user_part ) ) : #NEWLINE# #INDENT# raise ValidationError ( 'Invalid Email' ) #NEWLINE# #UNINDENT# if ( not DOMAIN_REGEX . match ( domain_part ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# domain_part = domain_part . encode ( 'idna' ) . decode ( 'ascii' ) #NEWLINE# #UNINDENT# except UnicodeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if DOMAIN_REGEX . match ( domain_part ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# #UNINDENT# raise ValidationError ( 'Invalid Email' ) #NEWLINE# #UNINDENT# return True