code: def parse_hostname(cls, hostname):
          '''Parse the hostname and normalize.'''
          if hostname.startswith('['):
              return cls.parse_ipv6_hostname(hostname)
          else:
              try:
                  new_hostname = normalize_ipv4_address(hostname)
              except ValueError:
                  # _logger.debug('', exc_info=True)
                  new_hostname = hostname
  
              new_hostname = normalize_hostname(new_hostname)
  
              if any(char in new_hostname for char in FORBIDDEN_HOSTNAME_CHARS):
                  raise ValueError('Invalid hostname: {}'
                                   .format(ascii(hostname)))
  
              return new_hostnamf parse_hostname(cls, hostname):
          '''Parse the hostname and normalize.'''
          if hostname.startswith('['):
              return cls.parse_ipv6_hostname(hostname)
          else:
              try:
                  new_hostname = normalize_ipv4_address(hostname)
              except ValueError:
                  # _logger.debug('', exc_info=True)
                  new_hostname = hostname
  
              new_hostname = normalize_hostname(new_hostname)
  
              if any(char in new_hostname for char in FORBIDDEN_HOSTNAME_CHARS):
                  raise ValueError('Invalid hostname: {}'
                                   .format(ascii(hostname)))
  
              return new_hostname
docs: Parse the hostname and normalize.