code: def _spec_to_matches(server_list, server_spec, mode):
      
      assert mode in ("uri", "hostname", "hostname_port")
  
      def match(server_doc):
          if mode == "hostname":
              return server_spec == server_doc["hostname"]
          elif mode == "hostname_port":
              return server_spec == "{}:{}".format(
                  server_doc["hostname"], server_doc["port"]
              )
          elif mode == "uri":
              return server_spec == "{}://{}:{}".format(
                  server_doc["scheme"], server_doc["hostname"], server_doc["port"]
              )
          else:
              raise NotImplementedError("Unreachable error! Something is very wrong.")
  
      return [server_doc for server_doc in server_list if match(server_doc)]
docs: mode is in {uri, hostname, hostname_port}
  
      A list of matching server docs.
      Should usually be 0 or 1 matches. Multiple matches are possible though.