1+ import ast
12import os .path
2- from functools import partial
33from contextlib import contextmanager
4- import ast
4+ from functools import partial
55
6- import tornado
7- from tornado import template
8- from tornado .web import HTTPError , Finish
9- from tornado .web import StaticFileHandler
6+ import tornado .template
7+ import tornado .web
8+ import tornado .ioloop
109
1110from . import page
1211from .httpbased import HttpHandler
12+ from .page import make_applications
1313from .tornado import webio_handler , set_ioloop
1414from .tornado_http import TornadoHttpContext
1515from .utils import cdn_validation , print_listen_address
16- from .page import make_applications
1716from ..session import register_session_implement , CoroutineBasedSession , ThreadBasedSession , Session
1817from ..utils import get_free_port , STATIC_PATH , parse_file_size
1918
@@ -103,7 +102,7 @@ def add_to_path(p):
103102 return module
104103
105104
106- _app_list_tpl = template .Template ("""
105+ _app_list_tpl = tornado . template .Template ("""
107106<!DOCTYPE html>
108107<html lang="">
109108<head>
@@ -145,7 +144,7 @@ def default_index_page(path, base):
145144 dirs .append ([(f + '/' ), '' ])
146145
147146 items = dirs + files
148- max_name_width = max ([len (n ) for n , _ in items ]+ [0 ])
147+ max_name_width = max ([len (n ) for n , _ in items ] + [0 ])
149148 return _app_list_tpl .generate (files = items , title = title , max_name_width = max_name_width )
150149
151150
@@ -204,8 +203,8 @@ def _path_deploy(base, port=0, host='', static_dir=None, max_payload_size=2 ** 2
204203
205204 handlers = []
206205 if static_dir is not None :
207- handlers .append ((r"/static/(.*)" , StaticFileHandler , {"path" : static_dir }))
208- handlers .append ((LOCAL_STATIC_URL + r"/(.*)" , StaticFileHandler , {"path" : STATIC_PATH }))
206+ handlers .append ((r"/static/(.*)" , tornado . web . StaticFileHandler , {"path" : static_dir }))
207+ handlers .append ((LOCAL_STATIC_URL + r"/(.*)" , tornado . web . StaticFileHandler , {"path" : STATIC_PATH }))
209208 handlers .append ((r"/.*" , RequestHandler ))
210209
211210 print_listen_address (host , port )
@@ -250,7 +249,8 @@ def path_deploy(base, port=0, host='',
250249 # use `websocket_ping_interval` to keep the connection alive
251250 tornado_app_settings .setdefault ('websocket_ping_interval' , 30 )
252251 tornado_app_settings .setdefault ('websocket_max_message_size' , max_payload_size ) # Backward compatible
253- tornado_app_settings ['websocket_max_message_size' ] = parse_file_size (tornado_app_settings ['websocket_max_message_size' ])
252+ tornado_app_settings ['websocket_max_message_size' ] = parse_file_size (
253+ tornado_app_settings ['websocket_max_message_size' ])
254254 gen = _path_deploy (base , port = port , host = host ,
255255 static_dir = static_dir , debug = debug ,
256256 max_payload_size = max_payload_size ,
@@ -277,9 +277,9 @@ def get_app(self):
277277 reload = self .get_query_argument ('reload' , None ) is not None
278278 type , res = get_app_from_path (self .request .path , abs_base , index = index_func , reload = reload )
279279 if type == 'error' :
280- raise HTTPError (status_code = res )
280+ raise tornado . web . HTTPError (status_code = res )
281281 elif type == 'html' :
282- raise Finish (res )
282+ raise tornado . web . Finish (res )
283283
284284 app_name = self .get_query_argument ('app' , 'index' )
285285 app = res .get (app_name ) or res ['index' ]
@@ -326,9 +326,9 @@ def get_app(context: TornadoHttpContext):
326326
327327 type , res = get_app_from_path (context .get_path (), abs_base , index = index_func , reload = reload )
328328 if type == 'error' :
329- raise HTTPError (status_code = res )
329+ raise tornado . web . HTTPError (status_code = res )
330330 elif type == 'html' :
331- raise Finish (res )
331+ raise tornado . web . Finish (res )
332332
333333 app_name = context .request_url_parameter ('app' , 'index' )
334334 return res .get (app_name ) or res ['index' ]
0 commit comments