code: def parse_host(cls, host):
          '''Parse the host and return hostname and port.'''
          if host.endswith(']'):
              return cls.parse_hostname(host), None
          else:
              hostname, sep, port = host.rpartition(':')
  
          if sep:
              port = int(port)
              if port < 0 or port > 65535:
                  raise ValueError('Port number invalid')
          else:
              hostname = port
              port = None
  
          return cls.parse_hostname(hostname), porf parse_host(cls, host):
          '''Parse the host and return hostname and port.'''
          if host.endswith(']'):
              return cls.parse_hostname(host), None
          else:
              hostname, sep, port = host.rpartition(':')
  
          if sep:
              port = int(port)
              if port < 0 or port > 65535:
                  raise ValueError('Port number invalid')
          else:
              hostname = port
              port = None
  
          return cls.parse_hostname(hostname), port
docs: Parse the host and return hostname and port.