MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / path_deploy

Function path_deploy

pywebio/platform/path_deploy.py:218–290  ·  view source on GitHub ↗

Deploy the PyWebIO applications from a directory. The server communicates with the browser using WebSocket protocol. :param str base: Base directory to load PyWebIO application. :param int port: The port the server listens on. :param str host: The host the server listens on. :p

(base, port=0, host='',
                index=True, static_dir=None,
                reconnect_timeout=0,
                cdn=True, debug=False,
                allowed_origins=None, check_origin=None,
                max_payload_size='200M',
                **tornado_app_settings)

Source from the content-addressed store, hash-verified

216
217
218def path_deploy(base, port=0, host='',
219 index=True, static_dir=None,
220 reconnect_timeout=0,
221 cdn=True, debug=False,
222 allowed_origins=None, check_origin=None,
223 max_payload_size='200M',
224 **tornado_app_settings):
225 """Deploy the PyWebIO applications from a directory.
226
227 The server communicates with the browser using WebSocket protocol.
228
229 :param str base: Base directory to load PyWebIO application.
230 :param int port: The port the server listens on.
231 :param str host: The host the server listens on.
232 :param bool/callable index: Whether to provide a default index page when request a directory, default is ``True``.
233 ``index`` also accepts a function to custom index page, which receives the requested directory path as parameter
234 and return HTML content in string.
235
236 You can override the index page by add a `index.py` PyWebIO app file to the directory.
237 :param str static_dir: Directory to store the application static files.
238 The files in this directory can be accessed via ``http://<host>:<port>/static/files``.
239 For example, if there is a ``A/B.jpg`` file in ``static_dir`` path,
240 it can be accessed via ``http://<host>:<port>/static/A/B.jpg``.
241 :param int reconnect_timeout: The client can reconnect to server within ``reconnect_timeout`` seconds after an unexpected disconnection.
242 If set to 0 (default), once the client disconnects, the server session will be closed.
243
244 The rest arguments of ``path_deploy()`` have the same meaning as for :func:`pywebio.platform.tornado.start_server`
245 """
246 debug = Session.debug = os.environ.get('PYWEBIO_DEBUG', debug)
247 page.MAX_PAYLOAD_SIZE = max_payload_size = parse_file_size(max_payload_size)
248 # Since some cloud server may close idle connections (such as heroku),
249 # use `websocket_ping_interval` to keep the connection alive
250 tornado_app_settings.setdefault('websocket_ping_interval', 30)
251 tornado_app_settings.setdefault('websocket_max_message_size', max_payload_size) # Backward compatible
252 tornado_app_settings['websocket_max_message_size'] = parse_file_size(
253 tornado_app_settings['websocket_max_message_size'])
254 gen = _path_deploy(base, port=port, host=host,
255 static_dir=static_dir, debug=debug,
256 max_payload_size=max_payload_size,
257 **tornado_app_settings)
258
259 cdn = cdn_validation(cdn, 'warn', stacklevel=3) # if CDN is not available, warn user and disable CDN
260
261 abs_base = next(gen)
262
263 index_func = {True: partial(default_index_page, base=abs_base), False: lambda p: '403 Forbidden'}.get(index, index)
264
265 Handler = webio_handler(lambda: None, cdn=cdn, allowed_origins=allowed_origins,
266 check_origin=check_origin, reconnect_timeout=reconnect_timeout)
267
268 class WSHandler(Handler):
269
270 def get_cdn(self):
271 _cdn = super().get_cdn()
272 if not _cdn:
273 return LOCAL_STATIC_URL
274 return _cdn
275

Callers 2

start_test_serverFunction · 0.90
__main__.pyFile · 0.90

Calls 7

parse_file_sizeFunction · 0.85
_path_deployFunction · 0.85
cdn_validationFunction · 0.85
sendMethod · 0.80
webio_handlerFunction · 0.70
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…