<s> import re <EOL> from . utils import validator <EOL> user_regex = re . compile ( <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r'<STR_LIT>' <EOL> r"""<STR_LIT>""" , <EOL> re . IGNORECASE <EOL> ) <EOL> domain_regex = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' , <EOL> re . IGNORECASE ) <EOL> domain_whitelist = [ '<STR_LIT:localhost>' ] <EOL> @ validator <EOL> def email ( value , whitelist = None ) : <EOL> """<STR_LIT>""" <EOL> if whitelist is None : <EOL> whitelist = domain_whitelist <EOL> if not value or '<STR_LIT:@>' not in value : <EOL> return False <EOL> user_part , domain_part = value . rsplit ( '<STR_LIT:@>' , <NUM_LIT:1> ) <EOL> if not user_regex . match ( user_part ) : <EOL> return False <EOL> if domain_part not in whitelist and not domain_regex . match ( domain_part ) : <EOL> try : <EOL> domain_part = domain_part . encode ( '<STR_LIT>' ) . decode ( '<STR_LIT:ascii>' ) <EOL> return domain_regex . match ( domain_part ) <EOL> except UnicodeError : <EOL> return False <EOL> return True </s>
