提供一些有用的实用程序函数,以便在中实现不同的组件 bokeh.server .
bokeh.server
bind_sockets
将套接字绑定到地址上的端口。
address (str) -- 绑定端口的地址,例如。 "localhost"
"localhost"
port (int) -- 要绑定的端口号。传递0,使操作系统自动选择可用端口。
此函数返回一个2元组,新的套接字作为第一个元素,绑定的端口作为第二个元素。(将0作为端口号传递以绑定任何空闲端口时非常有用。)
(插座、端口)
check_allowlist
对照allowlist检查给定的请求主机。
host (str) -- 要与allowlist进行比较的主机字符串。如果主机未指定端口,则 ":80" 隐式假设。
":80"
allowlist (seq[str]) -- 要匹配的主机模式的列表
True, if host matches any pattern in allowlist, otherwise False
True
host
allowlist
False
create_hosts_allowlist
此allowlist可用于将websocket或其他连接限制为仅显式源于已批准主机的连接。
host_list (seq[str]) -- 字符串列表 <name> 或 <name>:<port> 要添加到allowlist的值。如果主机字符串中没有指定端口,则 ":80" 隐式假设。
port (int) -- 如果 host_list 是空的还是 None ,则allowlist将是单个项列表 `` [ 'localhost:<port>' ]`` 如果 host_list 不为空,此参数无效。
host_list
None
列表 [str]
ValueError, if host or port values are invalid --
注解
如果有主机 host_list 包含通配符 * 将记录有关允许的websocket连接的警告。
*
match_host
与一个字符串匹配
host (str) -- 要与给定模式进行比较的主机名
pattern (str) -- 表示主机名模式的字符串,可能包括ip地址八位字节或端口的通配符。
此函数将返回 True 如果主机名与模式匹配,包括任何通配符。如果模式包含端口,则主机字符串也必须包含匹配的端口。
布尔
实际案例
>>> 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