def canonicalize_address(addr):
 parsed_address = address.parse(addr, addr_spec_only=True)
 if (not isinstance(parsed_address, address.EmailAddress)):
  return addr
 local_part = parsed_address.mailbox.lower()
 hostname = parsed_address.hostname.lower()
 if (hostname in ('gmail.com', 'googlemail.com')):
  local_part = local_part.replace('.', '')
 return '@'.join((local_part, hostname))

def canonicalize_address ( addr ) : parsed_address = address . parse ( addr , addr_spec_only = True ) if ( not isinstance ( parsed_address , address . EmailAddress ) ) : return addr local_part = parsed_address . mailbox . lower ( ) hostname = parsed_address . hostname . lower ( ) if ( hostname in ( 'gmail.com' , 'googlemail.com' ) ) : local_part = local_part . replace ( '.' , '' ) return '@' . join ( ( local_part , hostname ) )
gmail addresses with and without periods are the same .