bokeh.server.util#
提供一些实用函数,用于实现bokeh.server中的不同组件。
- bind_sockets(address: str | None, port: int) tuple[list[socket], int][source]#
将套接字绑定到地址上的端口。
此函数返回一个包含新套接字作为第一个元素的2元组, 以及绑定端口作为第二个元素。(当传递0作为端口号以绑定任何空闲端口时非常有用。)
- Returns:
(socket, port)
- create_hosts_allowlist(host_list: Sequence[str] | None, port: int | None) list[str][源代码]#
此白名单可用于限制WebSocket或其他连接,仅允许明确来自已批准主机的连接。
- Parameters:
- Returns:
列表[字符串]
- Raises:
ValueError, 如果主机或端口值无效 –
注意
如果
host_list中的任何主机包含通配符*,将会记录一个关于宽松的websocket连接的警告。
- match_host(host: str, pattern: str) bool[source]#
将主机字符串与模式进行匹配
如果主机名与模式匹配,包括任何通配符,此函数将返回
True。如果模式包含端口,主机字符串也必须包含匹配的端口。- Returns:
布尔
示例
>>> match_host('192.168.0.1:80', '192.168.0.1:80') True >>> match_host('192.168.0.1:80', '192.168.0.1') True >>> match_host('192.168.0.1:80', '192.168.0.1:8080') False >>> match_host('192.168.0.1', '192.168.0.2') False >>> match_host('192.168.0.1', '192.168.*.*') True >>> match_host('alice', 'alice') True >>> match_host('alice:80', 'alice') True >>> match_host('alice', 'bob') False >>> match_host('foo.example.com', 'foo.example.com.net') False >>> match_host('alice', '*') True >>> match_host('alice', '*:*') True >>> match_host('alice:80', '*') True >>> match_host('alice:80', '*:80') True >>> match_host('alice:8080', '*:80') False