code: def normalize_hostname(hostname):
      '''Normalizes a hostname so that it is ASCII and valid domain name.'''
      try:
          new_hostname = hostname.encode('idna').decode('ascii').lower()
      except UnicodeError as error:
          raise UnicodeError('Hostname {} rejected: {}'.format(hostname, error)) from error
  
      if hostname != new_hostname:
          # Check for round-trip. May raise UnicodeError
          new_hostname.encode('idna')
  
      return new_hostnamf normalize_hostname(hostname):
      '''Normalizes a hostname so that it is ASCII and valid domain name.'''
      try:
          new_hostname = hostname.encode('idna').decode('ascii').lower()
      except UnicodeError as error:
          raise UnicodeError('Hostname {} rejected: {}'.format(hostname, error)) from error
  
      if hostname != new_hostname:
          # Check for round-trip. May raise UnicodeError
          new_hostname.encode('idna')
  
      return new_hostname
docs: Normalizes a hostname so that it is ASCII and valid domain name.