本文整理汇总了Python中tornadio2.TornadioRouter.apply_routes方法的典型用法代码示例。如果您正苦于以下问题:Python TornadioRouter.apply_routes方法的具体用法?Python TornadioRouter.apply_routes怎么用?Python TornadioRouter.apply_routes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornadio2.TornadioRouter
的用法示例。
在下文中一共展示了TornadioRouter.apply_routes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_warrior_server
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def start_warrior_server(warrior, port_number=8001):
SeesawConnection.warrior = warrior
warrior.on_projects_loaded += SeesawConnection.handle_projects_loaded
warrior.on_project_refresh += SeesawConnection.handle_project_refresh
warrior.on_project_installing += SeesawConnection.handle_project_installing
warrior.on_project_installed += SeesawConnection.handle_project_installed
warrior.on_project_installation_failed += SeesawConnection.handle_project_installation_failed
warrior.on_project_selected += SeesawConnection.handle_project_selected
warrior.on_status += SeesawConnection.handle_warrior_status
warrior.runner.on_pipeline_start_item += SeesawConnection.handle_start_item
warrior.runner.on_pipeline_finish_item += SeesawConnection.handle_finish_item
warrior.runner.on_status += SeesawConnection.handle_runner_status
ioloop.PeriodicCallback(SeesawConnection.broadcast_bandwidth, 1000).start()
router = TornadioRouter(SeesawConnection)
application = web.Application(
router.apply_routes([(r"/(.*\.(html|css|js|swf|png))$",
web.StaticFileHandler, {"path": PUBLIC_PATH}),
("/", IndexHandler),
("/api/(.+)$", ApiHandler, {"warrior": warrior})]),
# flash_policy_port = 843,
# flash_policy_file = os.path.join(PUBLIC_PATH, "flashpolicy.xml"),
socket_io_port = port_number,
debug = True
)
SocketServer(application, auto_start=False)
示例2: __init__
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def __init__(self):
handlers = [
(r"/", MainHandler),
(r"/auth/login", WeiboAuthHandler),
(r"/auth/logout", LogoutHandler),
(r"/vote", VoteHandler),
]
settings = dict(
static_path=os.path.join(os.path.dirname(__file__), "public"),
cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
login_url="/auth/login",
debug=True,
xsrf_cookies=True,
weibo_consumer_key='100689067',
weibo_consumer_secret='1f54eff4858b924d090833d537335bd8',
flash_policy_port = 843,
flash_policy_file = op.join(ROOT, 'flashpolicy.xml'),
socket_io_port = 8000,
)
VoteRouter = TornadioRouter(VoteConnection,
dict(enabled_protocols=['websocket', 'xhr-polling',
'jsonp-polling', 'htmlfile']))
tornado.web.Application.__init__(self, VoteRouter.apply_routes(handlers), **settings)
#self.redis = redis.StrictRedis()
self.adb = opermongo.asyncdb(database='test')
self.db = opermongo.db(database='test')
示例3: InitServer
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def InitServer():
if settings.LOGGING:
logging.getLogger().setLevel(logging.DEBUG)
generate_settings()
SAHRouter = TornadioRouter(RouterConnection)
SAHApplication = web.Application(
SAHRouter.apply_routes(
[
(r"/", IndexHandler),
(r"/test/", TestHandler),
(
r"/static/(.*)",
web.StaticFileHandler,
{"path": os.path.abspath(os.path.join(os.getcwd(), "web", "static"))},
),
]
),
socket_io_port=settings.WS_PORT,
debug=settings.DEBUG,
)
SAHSocketServer = SocketServer(SAHApplication, auto_start=False)
# Add periodic callback (aka faux-thread) into the ioloop before starting
# Tornado doesn't respond well to running a thread while the IO loop is going.
cb = ioloop.PeriodicCallback(GamePulse, 1000, SAHSocketServer.io_loop)
cb.start()
SAHSocketServer.io_loop.start()
示例4: start_runner_server
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def start_runner_server(project, runner, bind_address="", port_number=8001, http_username=None, http_password=None):
if bind_address=="0.0.0.0":
bind_address = ""
SeesawConnection.project = project
SeesawConnection.runner = runner
runner.on_pipeline_start_item += SeesawConnection.handle_start_item
runner.on_pipeline_finish_item += SeesawConnection.handle_finish_item
runner.on_status += SeesawConnection.handle_runner_status
router = TornadioRouter(SeesawConnection)
application = AuthenticatedApplication(
router.apply_routes([(r"/(.*\.(html|css|js|swf|png|ico))$",
web.StaticFileHandler, {"path": PUBLIC_PATH}),
("/", IndexHandler),
("/api/(.+)$", ApiHandler, {"runner": runner})]),
# flash_policy_port = 843,
# flash_policy_file = os.path.join(PUBLIC_PATH, "flashpolicy.xml"),
socket_io_address = bind_address,
socket_io_port = port_number,
# settings for AuthenticatedApplication
auth_enabled = (http_password or "").strip() != "",
check_auth = lambda r, username, password: \
(
password==http_password and \
(http_username or "").strip() in ["", username]
),
auth_realm = "ArchiveTeam Warrior",
skip_auth = [ r"^/socket\.io/1/websocket/[a-z0-9]+$" ]
)
SocketServer(application, auto_start=False)
示例5: __init__
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def __init__(self, cacher):
router = TornadioRouter(Client)
self.server = None
self.cacher = cacher
self.reportUUID = uuid.uuid4().hex
self.app = tornado.web.Application(
router.apply_routes([
(r"/", MainHandler, dict(
template='index.jade',
reportUUID=self.reportUUID,
cacher=cacher)),
(r"/offline\.html", MainHandler, dict(
template='offline.jade',
reportUUID=self.reportUUID,
cacher=cacher)),
(r"/brief\.html$", MainHandler, dict(
template='brief.jade',
reportUUID=self.reportUUID,
cacher=cacher)),
(r"/monitoring\.html$", MainHandler, dict(
template='monitoring.jade',
reportUUID=self.reportUUID,
cacher=cacher)),
(r"/data\.json$", JsonHandler,
dict(reportUUID=self.reportUUID, cacher=cacher)),
]),
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True,
)
示例6: main
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def main(args=None):
if args is None:
args = sys.argv
setup_logger()
router = TornadioRouter(RouterConnection)
bg_loop = IOLoop()
bg_thread = Thread(target=lambda: bg_loop.start())
bg_task = task.Task(bg_loop)
application = Application(
router.apply_routes([
(r"/", IndexHandler),
(r"/start", StartHandler),
(r"/start_mission", StartMissionHandler),
]),
debug=True,
)
application.listen(8000)
StartHandler.triggered.connect(bg_task.setup_api)
StartMissionHandler.triggered.connect(bg_task.start_mission)
event.api_started.connect(RouterConnection.on_api_started)
event.mission_started.connect(RouterConnection.on_mission_started)
event.mission_result.connect(RouterConnection.on_mission_result)
try:
bg_thread.start()
IOLoop.instance().start()
except KeyboardInterrupt:
bg_loop.stop()
IOLoop.instance().stop()
# api_token = args[1]
# client_ = client.Client(api_token)
# event_loop = tornado.ioloop.IOLoop()
# event_loop = task.EventLoop()
# mission = client.Mission(client=client_, event_loop=event_loop)
# mission.start(api_deck_id=2, api_mission_id=5)
# mission.start(api_deck_id=3, api_mission_id=21)
# mission.start(api_deck_id=4, api_mission_id=38)
# nyukyo = client.Nyukyo(client=client_, event_loop=event_loop)
# nyukyo.start()
# event_loop.start()
return 0
示例7: __init__
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def __init__(self, state):
router = TornadioRouter(Client)
self.reportUUID = uuid.uuid4().hex
self.app = tornado.web.Application(
router.apply_routes([
(r"/", MainHandler, dict(template='index.jade', reportUUID=self.reportUUID, state=state)),
(r"/data\.json$", DataHandler, dict(reportUUID=self.reportUUID, state=state)),
(r"/toplist\.json$", ResultsHandler, dict(reportUUID=self.reportUUID, state=state)),
]),
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True,
)
示例8: load_app
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def load_app(port, root):
settings = {
"static_path": path.join(root, "static"),
"template_path": path.join(root, "template"),
"globals": {
"project_name": "BAT -- Bootstrap, AngularJS, Tornado"
},
"flash_policy_port": 843,
"flash_policy_file": path.join(root, 'flashpolicy.xml'),
"socket_io_port": port,
}
routers = [
(r"/", MainHandler),
(r"/ajax", AjaxHandler),
(r"/signin", SigninHandler),
(r"/fluid", FluidHandler),
(r"/hero", HeroHandler),
(r"/sfn", SFNHandler),
(r"/sticky-footer", StickyFooterHandler),
(r"/justified-nav", JustifiedNavHandler),
(r"/carousel", CarouselHandler),
(r"/market-narrow", MarketNarrowHandler),
(r"/static-grid", StaticGridHandler),
(r"/ajax-grid", AjaxGridHandler),
(r"/angular-ui", AngularUIHandler),
(r"/", SocketIOGenHandler)
]
try:
from tornadio2 import TornadioRouter, SocketServer
from connections import QueryConnection
# Create tornadio router
QueryRouter = TornadioRouter(QueryConnection)
# Create socket application
application = web.Application(
QueryRouter.apply_routes(routers),
**settings
)
#application.listen(8888)
SocketServer(application)
except ImportError:
print "Failed to load module tornadio2"
application = web.Application(
routers,
**settings
)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
示例9: run
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def run(port, address, debug):
global ss
logging.getLogger().setLevel(logging.DEBUG)
router = TornadioRouter(ExecuteConnection)
ss = SocketServer(web.Application(
router.apply_routes([(r"/", IndexHandler),
(r"/static/(.*)", web.StaticFileHandler,
{'path':'../static'}),
]),
socket_io_port = port,
socket_io_address = address,
debug=debug),
auto_start = False)
ss.io_loop.add_handler(executor._fifo, handle_output, ss.io_loop.WRITE)
ss.io_loop.start()
示例10: __init__
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def __init__(self, **settings):
params = dict(enabled_protocols=["websocket", "xhr-polling", "jsonp-polling", "htmlfile"])
router = TornadioRouter(handler.SocketIOHandler, params)
handlers = router.apply_routes(
[
(r"/api/service", handler.ServiceHandler),
(r"/api/store", handler.StoreHandler),
(r"/options", handler.OptionsHandler),
(r"/", handler.MainHandler),
]
)
tornado.web.Application.__init__(self, handlers, **settings)
self.jinja = Environment(loader=FileSystemLoader(settings["template_path"]))
tornado.locale.set_default_locale("en_US")
self.locale = tornado.locale.get(locale.getdefaultlocale()[0])
self.store = Store()
示例11: start_warrior_server
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def start_warrior_server(warrior, bind_address="", port_number=8001, http_username=None, http_password=None):
SeesawConnection.warrior = warrior
warrior.on_projects_loaded += SeesawConnection.handle_projects_loaded
warrior.on_project_refresh += SeesawConnection.handle_project_refresh
warrior.on_project_installing += SeesawConnection.handle_project_installing
warrior.on_project_installed += SeesawConnection.handle_project_installed
warrior.on_project_installation_failed += SeesawConnection.handle_project_installation_failed
warrior.on_project_selected += SeesawConnection.handle_project_selected
warrior.on_status += SeesawConnection.handle_warrior_status
warrior.runner.on_pipeline_start_item += SeesawConnection.handle_start_item
warrior.runner.on_pipeline_finish_item += SeesawConnection.handle_finish_item
warrior.runner.on_status += SeesawConnection.handle_runner_status
if not http_username:
http_username = warrior.http_username
if not http_password:
http_password = warrior.http_password
ioloop.PeriodicCallback(SeesawConnection.broadcast_bandwidth, 1000).start()
router = TornadioRouter(SeesawConnection)
application = AuthenticatedApplication(
router.apply_routes([(r"/(.*\.(html|css|js|swf|png|ico))$",
web.StaticFileHandler, {"path": PUBLIC_PATH}),
("/", IndexHandler),
("/api/(.+)$", ApiHandler, {"warrior": warrior})]),
# flash_policy_port = 843,
# flash_policy_file = os.path.join(PUBLIC_PATH, "flashpolicy.xml"),
socket_io_address = bind_address,
socket_io_port = port_number,
# settings for AuthenticatedApplication
auth_enabled = lambda: (realize(http_password) or "").strip() != "",
check_auth = lambda r, username, password: \
(
password==realize(http_password) and \
(realize(http_username) or "").strip() in ["", username]
),
auth_realm = "ArchiveTeam Warrior",
skip_auth = [ r"^/socket\.io/1/websocket/[a-z0-9]+$" ]
)
SocketServer(application, auto_start=False)
示例12: start_runner_server
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def start_runner_server(project, runner, bind_address="", port_number=8001):
if bind_address=="0.0.0.0":
bind_address = ""
SeesawConnection.project = project
SeesawConnection.runner = runner
runner.on_pipeline_start_item += SeesawConnection.handle_start_item
runner.on_pipeline_finish_item += SeesawConnection.handle_finish_item
runner.on_status += SeesawConnection.handle_runner_status
router = TornadioRouter(SeesawConnection)
application = web.Application(
router.apply_routes([(r"/(.*\.(html|css|js|swf|png))$",
web.StaticFileHandler, {"path": PUBLIC_PATH}),
("/", IndexHandler),
("/api/(.+)$", ApiHandler, {"runner": runner})]),
# flash_policy_port = 843,
# flash_policy_file = os.path.join(PUBLIC_PATH, "flashpolicy.xml"),
socket_io_address = bind_address,
socket_io_port = port_number
)
SocketServer(application, auto_start=False)
示例13: run
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
def run(port, address, debug):
if debug:
logging.getLogger().setLevel(logging.DEBUG)
router = TornadioRouter(ExecuteConnection)
ss = SocketServer(web.Application(
router.apply_routes([(r"/", IndexHandler),
(r"/static/(.*)", web.StaticFileHandler,
{'path':os.path.join(ROOT ,'static')}),
]),
flash_policy_port = 843,
flash_policy_file = os.path.join(ROOT, 'flashpolicy.xml'),
socket_io_port = port,
socket_io_address = address,
debug=debug),
auto_start = False)
# We do auto_start=False above and the following loop, so that SIGINT interrupts from
# the user doesn't kill the process.
while True:
try:
ss.io_loop.start()
except:
pass
示例14: TornadioRouter
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
import os
import logging
from tornadio2 import TornadioRouter, SocketServer
from tornado import web
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
from django_socketio_chat.tornadio_app import chat
from django.conf import settings
logging.getLogger().setLevel(logging.INFO)
# Create chat router
ChatRouter = TornadioRouter(chat.ChatConnection,
user_settings={'websocket_check': True},
namespace='chat/socket.io')
# Create application
application = web.Application(
ChatRouter.apply_routes([]),
socket_io_port=8001,
debug=settings.DEBUG
)
SocketServer(application)
示例15: TornadioRouter
# 需要导入模块: from tornadio2 import TornadioRouter [as 别名]
# 或者: from tornadio2.TornadioRouter import apply_routes [as 别名]
fh.close()
im = Image.open("static/pic/" + fname)
im.save('static/pic/' + fname)
response['status'] = True
response['path'] = "pic/" + fname
self.finish(
json.dumps(response))
EventRouter = TornadioRouter(
EventConnection)
application = tornado.web.Application(
EventRouter.apply_routes([
(r"/", NotVJSHandler.Index),
(r"/pic/(.*)", tornado.web.StaticFileHandler, {
'path': path.join(static_path, "pic")}),
(r"/temp/(.*)", tornado.web.StaticFileHandler, {
'path': path.join(static_path, "temp")}),
(r"/js/(.*)", tornado.web.StaticFileHandler, {
'path': path.join(static_path, "js")}),
(r"/css/(.*)", tornado.web.StaticFileHandler, {
'path': path.join(static_path, "css")}),
(r"/upload$", NotVJSHandler.Upload)]),
flash_policy_port=843,
flash_policy_file=path.join(ROOT, 'flashpolicy.xml'),
socket_io_port=8888)