Skip to content

Commit 5b80869

Browse files
committed
maint: update doc
1 parent 5e882ec commit 5b80869

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

pywebio/platform/django.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def webio_view(target,
6565
session_expire_seconds=None,
6666
session_cleanup_interval=None,
6767
allowed_origins=None, check_origin=None):
68-
"""获取用于与后端实现进行整合的view函数,基于http请求与前端进行通讯
68+
"""获取在django中运行PyWebIO任务的视图函数。
69+
基于http请求与前端进行通讯
6970
7071
:param target: 任务函数。任务函数为协程函数时,使用 :ref:`基于协程的会话实现 <coroutine_based_session>` ;任务函数为普通函数时,使用基于线程的会话实现。
7172
:param int session_expire_seconds: 会话不活跃过期时间。
@@ -108,12 +109,11 @@ def start_server(target, port=8080, host='localhost',
108109
session_cleanup_interval=None,
109110
session_expire_seconds=None,
110111
debug=False, **django_options):
111-
"""启动一个 Django server 来运行PyWebIO的 ``target`` 服务
112+
"""启动一个 Django server ``target`` 任务函数作为Web服务提供。
112113
113-
:param target: task function. It's a coroutine function is use CoroutineBasedSession or
114-
a simple function is use ThreadBasedSession.
115-
:param port: server bind port. set ``0`` to find a free port number to use
116-
:param host: server bind host. ``host`` may be either an IP address or hostname. If it's a hostname,
114+
:param target: 任务函数。任务函数为协程函数时,使用 :ref:`基于协程的会话实现 <coroutine_based_session>` ;任务函数为普通函数时,使用基于线程的会话实现。
115+
:param int port: server bind port. set ``0`` to find a free port number to use
116+
:param str host: server bind host. ``host`` may be either an IP address or hostname. If it's a hostname,
117117
:param list allowed_origins: 除当前域名外,服务器还允许的请求的来源列表。
118118
来源包含协议和域名和端口部分,允许使用 Unix shell 风格的匹配模式:
119119

pywebio/platform/flask.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def webio_view(target,
7070
session_expire_seconds=None,
7171
session_cleanup_interval=None,
7272
allowed_origins=None, check_origin=None):
73-
"""获取用于与后端实现进行整合的view函数,基于http请求与前端进行通讯
73+
"""获取在Flask中运行PyWebIO任务的视图函数。基于http请求与前端进行通讯
7474
7575
:param target: 任务函数。任务函数为协程函数时,使用 :ref:`基于协程的会话实现 <coroutine_based_session>` ;任务函数为普通函数时,使用基于线程的会话实现。
7676
:param int session_expire_seconds: 会话不活跃过期时间。
@@ -108,12 +108,11 @@ def start_server(target, port=8080, host='localhost',
108108
session_cleanup_interval=None,
109109
session_expire_seconds=None,
110110
debug=False, **flask_options):
111-
"""启动一个 Flask server 来运行PyWebIO的 ``target`` 服务
111+
"""启动一个 Flask server ``target`` 任务函数作为Web服务提供。
112112
113-
:param target: task function. It's a coroutine function is use CoroutineBasedSession or
114-
a simple function is use ThreadBasedSession.
115-
:param port: server bind port. set ``0`` to find a free port number to use
116-
:param host: server bind host. ``host`` may be either an IP address or hostname. If it's a hostname,
113+
:param target: 任务函数。任务函数为协程函数时,使用 :ref:`基于协程的会话实现 <coroutine_based_session>` ;任务函数为普通函数时,使用基于线程的会话实现。
114+
:param int port: server bind port. set ``0`` to find a free port number to use
115+
:param str host: server bind host. ``host`` may be either an IP address or hostname. If it's a hostname,
117116
:param list allowed_origins: 除当前域名外,服务器还允许的请求的来源列表。
118117
来源包含协议和域名和端口部分,允许使用 Unix shell 风格的匹配模式:
119118
@@ -128,7 +127,7 @@ def start_server(target, port=8080, host='localhost',
128127
:param bool disable_asyncio: 禁用 asyncio 函数。仅在 ``target`` 为协程函数时有效。
129128
130129
.. note:: 实现说明:
131-
当使用Flask backend时,若要在PyWebIO的会话中使用 ``asyncio`` 标准库里的协程函数,则需要在单独开启一个线程来运行 ``asyncio`` 事件循环,
130+
当使用Flask backend时,若要在PyWebIO的会话中使用 ``asyncio`` 标准库里的协程函数,PyWebIO需要单独开启一个线程来运行 ``asyncio`` 事件循环,
132131
若程序中没有使用到 ``asyncio`` 中的异步函数,可以开启此选项来避免不必要的资源浪费
133132
134133
:param int session_expire_seconds: 会话过期时间。若 session_expire_seconds 秒内没有收到客户端的请求,则认为会话过期。

pywebio/platform/tornado.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def on_close(self):
9999

100100

101101
def webio_handler(target, allowed_origins=None, check_origin=None):
102-
"""获取用于Tornado进行整合的RequestHandle类
102+
"""获取在Tornado中运行PyWebIO任务的RequestHandle类。RequestHandle类基于WebSocket协议与浏览器进行通讯。
103103
104104
:param target: 任务函数。任务函数为协程函数时,使用 :ref:`基于协程的会话实现 <coroutine_based_session>` ;任务函数为普通函数时,使用基于线程的会话实现。
105105
:param list allowed_origins: 除当前域名外,服务器还允许的请求的来源列表。
@@ -118,9 +118,7 @@ def webio_handler(target, allowed_origins=None, check_origin=None):
118118
session_cls = register_session_implement_for_target(target)
119119

120120
if check_origin is None:
121-
check_origin_func = _is_same_site
122-
if allowed_origins:
123-
check_origin_func = partial(_check_origin, allowed_origins=allowed_origins)
121+
check_origin_func = partial(_check_origin, allowed_origins=allowed_origins or [])
124122
else:
125123
check_origin_func = lambda origin, handler: _is_same_site(origin, handler) or check_origin(origin)
126124

@@ -158,12 +156,12 @@ def start_server(target, port=0, host='', debug=False,
158156
websocket_ping_interval=None,
159157
websocket_ping_timeout=None,
160158
**tornado_app_settings):
161-
"""Start a Tornado server to serve `target` function
159+
"""启动一个 Tornado server 将 ``target`` 任务函数作为Web服务提供。
162160
163161
:param target: 任务函数。任务函数为协程函数时,使用 :ref:`基于协程的会话实现 <coroutine_based_session>` ;任务函数为普通函数时,使用基于线程的会话实现。
164162
:param list allowed_origins: 除当前域名外,服务器还允许的请求的来源列表。
165-
:param port: server bind port. set ``0`` to find a free port number to use
166-
:param host: server bind host. ``host`` may be either an IP address or hostname. If it's a hostname,
163+
:param int port: server bind port. set ``0`` to find a free port number to use
164+
:param str host: server bind host. ``host`` may be either an IP address or hostname. If it's a hostname,
167165
the server will listen on all IP addresses associated with the name.
168166
set empty string or to listen on all available interfaces.
169167
:param bool debug: Tornado debug mode

0 commit comments

Comments
 (0)