当前位置: 首页>>代码示例>>Python>>正文


Python web.Application类代码示例

本文整理汇总了Python中tornado.web.Application的典型用法代码示例。如果您正苦于以下问题:Python Application类的具体用法?Python Application怎么用?Python Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main(urls_map):
    settings = {"auto_reload": True, "debug": True}
    application = Application(urls_map, **settings)
    application.listen(9999)
    logging.info("API server is running on port 9999")
    ioloop_instance = tornado.ioloop.IOLoop.instance()
    ioloop_instance.start()
开发者ID:Vito2015,项目名称:rima,代码行数:7,代码来源:server.py

示例2: __init__

    def __init__(self):
        # handlers = [
        #      (r'/', IndexHandler),
        #
        #     # 所有html静态文件都默认被StaticFileHandler处理
        #      # (r'/tpl/(.*)', StaticFileHandler, {
        #      #     'path': os.path.join(os.path.dirname(__file__), 'templates')
        #      # }),
        #      # PC端网页
        #      # (r'/f/', RedirectHandler, {'url': '/f/index.html'}),
        #      # (r'/f/(.*)', StaticFileHandler, {
        #      #     'path': os.path.join(os.path.dirname(__file__), 'front')
        #      # }),
        #  ]
        handlers = []
        handlers.extend(nui.routes)
        handlers.extend(service.routes)
        handlers.extend(stock.routes)
        handlers.extend(smscenter.routes)
        handlers.extend(weui.routes)
        handlers.extend(routes)
        site_url_prefix = settings.get(constant.SITE_URL_PREFIX, "")
        if site_url_prefix:
            # 构建新的URL
            handlers = map(
                lambda x: url(site_url_prefix + x.regex.pattern, x.handler_class, x.kwargs, x.name), handlers
            )

        # handlers = get_handlers()

        # 配置默认的错误处理类
        settings.update({"default_handler_class": ErrorHandler, "default_handler_args": dict(status_code=404)})

        Application.__init__(self, handlers=handlers, **settings)
开发者ID:hulingfeng211,项目名称:mywork,代码行数:34,代码来源:manage.py

示例3: __init__

 def __init__(self):
     settings = {}
     settings["debug"] = True
     handlers = []
     handlers.extend(UploadWebService.get_handlers())
     self.redis = redis.Redis(REDIS_HOST, REDIS_PORT, db=1)
     Application.__init__(self, handlers, **settings)
开发者ID:Bossuo,项目名称:ppmessage,代码行数:7,代码来源:tornadouploadapp.py

示例4: main

def main():
    global http_server

    try:
        signal(SIGTERM, on_signal)

        parse_command_line()
        if options.config != None:
            parse_config_file(options.config)

        path = join(dirname(__file__), "templates")

        application = Application(
            [(r"/", IndexHandler), (r"/stock", StockHandler)],
            template_path=path,
            static_path=join(dirname(__file__), "static"),
        )

        application.db = motor.MotorClient(options.db_host, options.db_port).open_sync()[options.db_name]

        http_server = HTTPServer(application)
        http_server.listen(options.port, options.address)
        log().info("server listening on port %s:%d" % (options.address, options.port))
        if log().isEnabledFor(DEBUG):
            log().debug("autoreload enabled")
            tornado.autoreload.start()
        IOLoop.instance().start()

    except KeyboardInterrupt:
        log().info("exiting...")

    except BaseException as ex:
        log().error("exiting due: [%s][%s]" % (str(ex), str(format_exc().splitlines())))
        exit(1)
开发者ID:irr,项目名称:stock-labs,代码行数:34,代码来源:Server.py

示例5: main

def main():
    root_dir = os.path.abspath(os.path.split(__file__)[0])
    print(root_dir)
    app = Application([(r'/gfxtablet', GfxTabletHandler),
                       #(r'/(index.js|src/.*\.js|node_modules/.*\.js)', StaticFileHandler, {}),
                       (r'/', MainHandler)],
                      debug=config.get('DEBUG', False), static_path=root_dir, static_url_prefix='/static/')

    _logger.info("app.settings:\n%s" % '\n'.join(['%s: %s' % (k, str(v))
                                                  for k, v in sorted(app.settings.items(),
                                                                     key=itemgetter(0))]))

    port = config.get('PORT', 5000)

    app.listen(port)
    _logger.info("listening on port %d" % port)
    _logger.info("press CTRL-C to terminate the server")
    _logger.info("""
           -----------
        G f x T a b l e t
    *************************
*********************************
STARTING TORNADO APP!!!!!!!!!!!!!
*********************************
    *************************
        G f x T a b l e t
           -----------
""")
    IOLoop.instance().start()
开发者ID:jzitelli,项目名称:GfxTablet.js,代码行数:29,代码来源:tornado_server.py

示例6: run_auth_server

def run_auth_server():
    client_store = ClientStore()
    client_store.add_client(client_id="abc", client_secret="xyz",
                            redirect_uris=[],
                            authorized_grants=[oauth2.grant.ClientCredentialsGrant.grant_type])

    token_store = TokenStore()

    # Generator of tokens
    token_generator = oauth2.tokengenerator.Uuid4()
    token_generator.expires_in[oauth2.grant.ClientCredentialsGrant.grant_type] = 3600

    provider = Provider(access_token_store=token_store,
                        auth_code_store=token_store, client_store=client_store,
                        token_generator=token_generator)
    # provider.add_grant(AuthorizationCodeGrant(site_adapter=TestSiteAdapter()))
    provider.add_grant(ClientCredentialsGrant())

    try:
        app = Application([
            url(provider.authorize_path, OAuth2Handler, dict(provider=provider)),
            url(provider.token_path, OAuth2Handler, dict(provider=provider)),
        ])

        app.listen(8080)
        print("Starting OAuth2 server on http://localhost:8080/...")
        IOLoop.current().start()

    except KeyboardInterrupt:
        IOLoop.close()
开发者ID:niyoufa,项目名称:pyda,代码行数:30,代码来源:oauthlib.py

示例7: main

def main():
    application = Application([
        (r"/", MainHandler),
        (r"/login", LoginHandler),
        (r"/logout", LogoutHandler),
        (r"/events", EventHandler),
        (r"/translations/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)", TranslationHandler),
        (r"/translations/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/button", ButtonHandler),
        (r"/selections/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)", SelectionHandler),
        (r"/flags/([A-Za-z0-9_]+)", ImageHandler, {
            'location': os.path.join(os.path.dirname(__file__), 'flags', '%s'),
            'fallback': os.path.join(os.path.dirname(__file__), 'static', 'flag.png')
        }),
        ], **{
        "login_url": "/",
        "template_path": os.path.join(os.path.dirname(__file__), "templates"),
        "static_path": os.path.join(os.path.dirname(__file__), "static"),
        "cookie_secret": base64.b64encode("000000000000000000000"),
        })
    application.listen(8891)

    try:
        IOLoop.instance().start()
    except KeyboardInterrupt:
        # Exit cleanly.
        return
开发者ID:cms-dev,项目名称:tws,代码行数:26,代码来源:TranslationWebServer.py

示例8: test_proxy

    def test_proxy(self):
        config = {
            "endpoints": {"https://app.datadoghq.com": ["foo"]},
            "proxy_settings": {
                "host": "localhost",
                "port": PROXY_PORT,
                "user": None,
                "password": None
            }
        }

        app = Application()
        app.skip_ssl_validation = True
        app._agentConfig = config

        trManager = TransactionManager(MAX_WAIT_FOR_REPLAY, MAX_QUEUE_SIZE, THROTTLING_DELAY)
        trManager._flush_without_ioloop = True  # Use blocking API to emulate tornado ioloop
        CustomAgentTransaction.set_tr_manager(trManager)
        app.use_simple_http_client = False # We need proxy capabilities
        app.agent_dns_caching = False
        # _test is the instance of this class. It is needed to call the method stop() and deal with the asynchronous
        # calls as described here : http://www.tornadoweb.org/en/stable/testing.html
        CustomAgentTransaction._test = self
        CustomAgentTransaction.set_application(app)
        CustomAgentTransaction.set_endpoints(config['endpoints'])

        CustomAgentTransaction('body', {}, "") # Create and flush the transaction
        self.wait()
        del CustomAgentTransaction._test
        access_log = self.docker_client.exec_start(
            self.docker_client.exec_create(CONTAINER_NAME, 'cat /var/log/squid/access.log')['Id'])
        self.assertTrue("CONNECT" in access_log) # There should be an entry in the proxy access log
        self.assertEquals(len(trManager._endpoints_errors), 1) # There should be an error since we gave a bogus api_key
开发者ID:alq666,项目名称:dd-agent,代码行数:33,代码来源:test_proxy.py

示例9: __init__

 def __init__(self):
     settings = {
       "static_path": os.path.join(os.path.dirname(__file__), "static"),
       "cookie_secret": COOKIE_KEY,
       "login_url": "/login",
     }
     Application.__init__(self, routes, debug=DEBUG, **settings)
开发者ID:rakoo,项目名称:newebe,代码行数:7,代码来源:newebe_server.py

示例10: main

def main():
    parse_command_line()
    flagfile = os.path.join(os.path.dirname(__file__), options.flagfile)
    parse_config_file(flagfile)

    settings = dict(
        login_url='/todo/login',
        debug=True,
        template_path=os.path.join(os.path.dirname(__file__), 'templates'),
        static_path=os.path.join(os.path.dirname(__file__), 'static'),

        cookie_secret=options.cookie_secret,
        dropbox_consumer_key=options.dropbox_consumer_key,
        dropbox_consumer_secret=options.dropbox_consumer_secret,
        )
    #print options.dropbox_consumer_key
    #print options.dropbox_consumer_secret
    app = Application([
            ('/', RootHandler),
            ('/todo/?', TodoHandler),
            ('/todo/add', AddHandler),
            ('/delete', DeleteHandler),
            ('/create', CreateHandler),
            ('/todo/login', DropboxLoginHandler),
            ('/todo/logout', LogoutHandler),
            ], **settings)
    app.listen(options.port,address='127.0.0.1',xheaders=True)
    IOLoop.instance().start()
开发者ID:wynemo,项目名称:simpletodo,代码行数:28,代码来源:main.py

示例11: __init__

    def __init__(self):
        handlers = [
            (r"/", IndexHandler),
            (r"/schedule", ScheduleHandler),
            (r"/recently", RecentlyViewHandler),
            (r"/overview", OverViewHandler),
            (r"/domains", DomainsViewHandler),
            (r"/details", DomainDetailHandler),
        ]
        config = dict(
            template_path=os.path.join(os.path.dirname(__file__), settings.TEMPLATE_ROOT),
            static_path=os.path.join(os.path.dirname(__file__), settings.STATIC_ROOT),
            #xsrf_cookies=True,
            cookie_secret="__TODO:_E720135A1F2957AFD8EC0E7B51275EA7__",
            autoescape=None,
            debug=settings.DEBUG
        )
        Application.__init__(self, handlers, **config)

        self.rd_main = redis.Redis(settings.REDIS_HOST,
                                   settings.REDIS_PORT,
                                   db=settings.REDIS_DB)
        self.db = Connection(
            host=settings.MYSQL_HOST, database=settings.MYSQL_DB,
            user=settings.MYSQL_USER, password=settings.MYSQL_PASS)
开发者ID:yidun55,项目名称:crawler,代码行数:25,代码来源:app.py

示例12: __init__

    def __init__(self):
        settings = load_settings(config)
        handlers = [
            (r'/$', StaticHandler, dict(
                template_name='index.html',
                title=settings['site_title']
            )),
            (r'/drag', StaticHandler, dict(
                template_name='draggable.html',
                title=settings['site_title']
            )),
            (r'/http', StaticHandler, dict(
                template_name='httpdemo.html',
                title=settings['site_title']
            )),
            (r'/demo', HTTPDemoHandler),
            (r'/demo/quickstart',StaticHandler,dict(
                template_name='App/demo/quickstart.html'
            )),
            (r'/user/list', UserHandler),
            (r'/user', UserHandler),#post
            (r'/user/(\w+)', UserHandler),#delete
        ]

        self.db = settings['db']
        self.dbsync = settings['dbsync']

        Application.__init__(self, handlers, **settings)
开发者ID:hulingfeng211,项目名称:angularjs,代码行数:28,代码来源:manage.py

示例13: run

 def run(self):
     loop = IOLoop()
     app = Application([
         (r'/', WsSocketHandler)
     ])
     app.listen(self.port)
     loop.start()
开发者ID:poppy-project,项目名称:pypot,代码行数:7,代码来源:ws.py

示例14: main

def main():
	app = Application([
		(r'/', MainHandler),
		(r'/res', ResourceHandler)
	], debug=True, gzip=True, cookie_secret='nice to meet you', template_path='templates', static_path='public', static_url_prefix="/public/");
	app.listen(8000)
	IOLoop.instance().start()
开发者ID:aaronzhang1990,项目名称:workshare,代码行数:7,代码来源:app.py

示例15: make_server

def make_server(config_path):
    root = path.dirname(__file__)
    static_path = path.join(root, 'static')
    template_path = path.join(root, 'template')

    define('port', default=7777, type=int)
    define('production', default=False, type=bool)
    define('mongo_db_name', default='open_wireless_map', type=str)
    define('mongo_host', default='localhost', type=str)
    define('mongo_port', default=27017, type=int)
    define('mongo_user', default=None, type=str)
    define('mongo_password', default=None, type=str)
    define('api_password_hash', default=None, type=str)

    parse_config_file(config_path)

    app_config = dict(static_path=static_path,
                      template_path=template_path)
    if not options.production:
        app_config.update(debug=True)

    server = Application(url_map, **app_config)
    server.settings['api_password_hash'] = options.api_password_hash
    server.settings['mongo'] = get_mongo(db_name=options.mongo_db_name,
                                         host=options.mongo_host,
                                         port=options.mongo_port,
                                         user=options.mongo_user,
                                         password=options.mongo_password)
    return server
开发者ID:charlesthomas,项目名称:open_wireless_map,代码行数:29,代码来源:server.py


注:本文中的tornado.web.Application类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。