def sanitize_address(addr, encoding):
 if (not isinstance(addr, tuple)):
  addr = parseaddr(force_text(addr))
 (nm, addr) = addr
 (localpart, domain) = (None, None)
 nm = Header(nm, encoding).encode()
 try:
  addr.encode('ascii')
 except UnicodeEncodeError:
  (localpart, domain) = split_addr(addr, encoding)
 if (localpart and domain):
  address = Address(nm, username=localpart, domain=domain)
  return str(address)
 try:
  address = Address(nm, addr_spec=addr)
 except (InvalidHeaderDefect, NonASCIILocalPartDefect):
  (localpart, domain) = split_addr(addr, encoding)
  address = Address(nm, username=localpart, domain=domain)
 return str(address)

def sanitize_address ( addr , encoding ) : if ( not isinstance ( addr , tuple ) ) : addr = parseaddr ( force_text ( addr ) ) ( nm , addr ) = addr ( localpart , domain ) = ( None , None ) nm = Header ( nm , encoding ) . encode ( ) try : addr . encode ( 'ascii' ) except UnicodeEncodeError : ( localpart , domain ) = split_addr ( addr , encoding ) if ( localpart and domain ) : address = Address ( nm , username = localpart , domain = domain ) return str ( address ) try : address = Address ( nm , addr_spec = addr ) except ( InvalidHeaderDefect , NonASCIILocalPartDefect ) : ( localpart , domain ) = split_addr ( addr , encoding ) address = Address ( nm , username = localpart , domain = domain ) return str ( address )
format a pair of or an email address string .