def __init__(self, handlers, blueprints=[]): """ 初始化应用 :param blueprints: 蓝图列表 :return: """ # 已注册的蓝图标签 self.bp_labels = [] self.logger = logging.getLogger('conch') if MODE_DEBUG: self.logger.setLevel(logging.DEBUG) self.logger.addHandler(fileTimeHandler) # 活跃请求列表 # CustomRequestsLiveList self.live_request_list = CustomRequestsLiveList() self.mysqldb = scoped_session(sessionmaker(bind=mysql_master_engine)) settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), cookie_secret='`\xbb\x1f\x99\x8fH~F\xbe\xb1\x12\x94)\xe2\xb3}\xb6~\x1c\xf4\x87\xeeeP', xsrf_cookies=False, login_url='/mgr/login', debug=MODE_DEBUG ) # 设置路由 self.handlers = handlers for _bp in blueprints: self.registerBlueprint(_bp) self.handlers.append((r".*", HornerBaseHandler)) tornado.web.Application.__init__(self, self.handlers, **settings) self.setEnvironment() self.kefu_list = [] # for test self.test_rtc_list = {}
class ConchApplication(tornado.web.Application): def __init__(self, handlers, blueprints=[]): """ 初始化应用 :param blueprints: 蓝图列表 :return: """ # 已注册的蓝图标签 self.bp_labels = [] self.logger = logging.getLogger('conch') if MODE_DEBUG: self.logger.setLevel(logging.DEBUG) self.logger.addHandler(fileTimeHandler) # 活跃请求列表 # CustomRequestsLiveList self.live_request_list = CustomRequestsLiveList() self.mysqldb = scoped_session(sessionmaker(bind=mysql_master_engine)) settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), cookie_secret='`\xbb\x1f\x99\x8fH~F\xbe\xb1\x12\x94)\xe2\xb3}\xb6~\x1c\xf4\x87\xeeeP', xsrf_cookies=False, login_url='/mgr/login', debug=MODE_DEBUG ) # 设置路由 self.handlers = handlers for _bp in blueprints: self.registerBlueprint(_bp) self.handlers.append((r".*", HornerBaseHandler)) tornado.web.Application.__init__(self, self.handlers, **settings) self.setEnvironment() self.kefu_list = [] # for test self.test_rtc_list = {} def getDbSession(self): ''' :return Session: ''' return self.mysqldb def registerHandlers(self, handlers): self.handlers = handlers def checkBlueprintConfliction(self, cur_blueprint): """ 检查蓝图是否冲突 :param cur_blueprint: :return: raise Exception """ for _bp in self.bp_labels: if _bp == cur_blueprint: raise Exception("Blueprint %s Confliction!" % cur_blueprint) def registerBlueprint(self, blueprint_app): """ 注册蓝图子应用 :param blueprint_app: :return: """ self.checkBlueprintConfliction(blueprint_app.getBlueprintName()) self.bp_labels.append(blueprint_app.getBlueprintName()) _blueprint_url_routes = blueprint_app.getRouteRules() for _bp_url in _blueprint_url_routes: if _bp_url[2] is not None: self.handlers.append(tornado.web.url(_bp_url[0], _bp_url[1], name=_bp_url[2])) else: self.handlers.append(_bp_url) def setEnvironment(self): pass def getLiveRequestHandlerList(self): ''' 获取活跃请求记录列表 :return: ''' return self.live_request_list def addToLivelist(self, request): self.live_request_list.addLiveRequestHandler(request) self.logger.debug("当前对话列表长度: %d" % self.live_request_list.getLiveRequestLength()) def printLength(self): self.logger.debug("当前对话列表长度: %d" % self.live_request_list.getLiveRequestLength())