code: def create_hosts_allowlist(
      host_list: Sequence[str] | None, port: int | None
  ) -> list[str]:
      """
  
      This allowlist can be used to restrict websocket or other connections to
      only those explicitly originating from approved hosts.
  
      Args:
          host_list (seq[str]) :
              A list of string `<name>` or `<name>:<port>` values to add to the
              allowlist.
  
              If no port is specified in a host string, then ``":80"``  is
              implicitly assumed.
  
          port (int) :
              If ``host_list`` is empty or ``None``, then the allowlist will
              be the single item list `` [ 'localhost:<port>' ]``
  
              If ``host_list`` is not empty, this parameter has no effect.
  
      Returns:
          list[str]
  
      Raises:
          ValueError, if host or port values are invalid
  
      Note:
          If any host in ``host_list`` contains a wildcard ``*`` a warning will
          be logged regarding permissive websocket connections.
  
      """
      if not host_list:
          return ["localhost:" + str(port)]
  
      hosts: list[str] = []
      for host in host_list:
          if "*" in host:
              log.warning(
                  "Host wildcard %r will allow connections originating "
                  "from multiple (or possibly all) hostnames or IPs. Use non-wildcard "
                  "values to restrict access explicitly",
                  host,
              )
          if host == "*":
              # do not append the :80 port suffix in that case: any port is
              # accepted
              hosts.append(host)
              continue
          parts = host.split(":")
          if len(parts) == 1:
              if parts[0] == "":
                  raise ValueError("Empty host value")
              hosts.append(host + ":80")
          elif len(parts) == 2:
              try:
                  int(parts[1])
              except ValueError:
                  raise ValueError(
                      "Invalid port in host value: %s" % host
                  )
              if parts[0] == "":
                  raise ValueError("Empty host value")
              hosts.append(host)
          else:
              raise ValueError("Invalid host value: %s" % host)
      return hosts
  
file_path: bokeh/src/bokeh/server/util.py
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING, Sequence
  from tornado import netutil
label_desc: Use image node_id 3 for calling a global function with example usage: create_hosts_allowlist(host_list, port) and returns: hosts, list