Переглянути джерело

adjust tornado backend code

wangweimin 5 роки тому
батько
коміт
d6fe7bb687
4 змінених файлів з 16 додано та 9 видалено
  1. 0 2
      pywebio/__init__.py
  2. 10 3
      pywebio/ioloop.py
  3. 5 0
      pywebio/platform/__init__.py
  4. 1 4
      pywebio/platform/tornado.py

+ 0 - 2
pywebio/__init__.py

@@ -8,9 +8,7 @@
 version = "0.1.0"
 version_info = (0, 1, 0, 0)
 
-from os.path import abspath, dirname
 
-project_dir = dirname(abspath(__file__))
 
 # Set default logging handler to avoid "No handler found" warnings.
 import logging

+ 10 - 3
pywebio/ioloop.py

@@ -1,7 +1,8 @@
 import tornado.websocket
 from tornado.web import StaticFileHandler
 from .framework import Global
-from .platform.tornado import ws_handler, STATIC_PATH
+from .platform import STATIC_PATH
+from .platform.tornado import webio_handler
 
 
 def run_async(coro_obj):
@@ -9,11 +10,17 @@ def run_async(coro_obj):
 
 
 def start_ioloop(coro_func, port=8080, debug=True, tornado_app_args=None):
-    handlers = [(r"/ws", ws_handler(coro_func)),
+    """
+    tornado app arg
+        websocket_max_message_size
+        ``websocket_ping_interval``, ``websocket_ping_timeout``, and
+       ``websocket_max_message_size``.
+
+    """
+    handlers = [(r"/ws", webio_handler(coro_func)),
                 (r"/(.*)", StaticFileHandler, {"path": STATIC_PATH,
                                                'default_filename': 'index.html'})]
 
-    gen_log.setLevel(logging.DEBUG)
     tornado_app_args = tornado_app_args or {}
     app = tornado.web.Application(handlers=handlers, debug=debug, **tornado_app_args)
     http_server = tornado.httpserver.HTTPServer(app)

+ 5 - 0
pywebio/platform/__init__.py

@@ -0,0 +1,5 @@
+from os.path import abspath, dirname
+
+project_dir = dirname(dirname(abspath(__file__)))
+
+STATIC_PATH = '%s/html' % project_dir

+ 1 - 4
pywebio/platform/tornado.py

@@ -2,13 +2,10 @@ import json
 
 import tornado
 import tornado.websocket
-from .. import project_dir
 from ..framework import WebIOSession
 
-STATIC_PATH = '%s/html' % project_dir
 
-
-def ws_handler(coro_func, debug=True):
+def webio_handler(coro_func, debug=True):
     class WSHandler(tornado.websocket.WebSocketHandler):
 
         def check_origin(self, origin):