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


Python Application.db方法代码示例

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


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

示例1: main

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
def main():

    from tank_maven.utils import setup_db

    app_settings = {
        'cookie_secret': settings.SECRET_KEY,
        'login_url': '/login/',
        'logout_url': '/logout/',
        'debug': settings.DEBUG,
        'template_path': settings.TEMPLATES_PATH,
        'static_path': settings.STATIC_PATH,
        'ui_modules': uimodules,
    }

    application = Application([
        url(r'/', handlers.HomeHandler, name='home'),
        url(r'^/login/$', handlers.LoginHandler, name='login'),
        url(r'^/logout/$', handlers.LogoutHandler, name='logout'),
        url(r'^/sign-up/$', handlers.SignupHandler, name='sign-up'),
        url(r'^/profile/edit/$', handlers.ProfileEditHandler, name='profile-edit'),
        url(r'^/settings/(.*)/$', handlers.SettingHandler,
            name='setting'),
        url(r'^/settings/$', handlers.SettingsHandler, name='settings-index'),
    ], **app_settings)
    application.db = setup_db()
    return application
开发者ID:gaker,项目名称:tank-maven,代码行数:28,代码来源:app.py

示例2: main

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
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,代码行数:36,代码来源:Server.py

示例3: parse_command_line

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
if __name__ == "__main__":
    parse_command_line()
    ioloop = IOLoop.instance()
    application = Application([
        (r"/", QuestionnaireListHandler),
        (r"/cat/(\d+)", QuestionHandler),
        (r"/result/(\d+)", ResultHandler)
    ],
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
        cookie_secret=COOKIE_SECRET,
        debug=True,
        xsrf_cookies=True,
    )
    application.db = momoko.Pool(
        dsn=DSN,
        size=1,
        ioloop=ioloop,
        cursor_factory=NamedTupleCursor,
    )

    future = application.db.connect()
    ioloop.add_future(future, lambda f: ioloop.stop())
    ioloop.start()
    future.result()

    http_server = HTTPServer(application)
    http_server.listen(8000, 'localhost')
    ioloop.start()
开发者ID:LiaoPan,项目名称:tornado-cat-example,代码行数:31,代码来源:main.py

示例4: get_normalized_settings

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
from tornado.web import Application
from tornado.log import enable_pretty_logging
from tornado.ioloop import IOLoop

from api.utils.db import get_db_session
from api.utils.settings import get_normalized_settings
from api.v1_0.handlers.urls import APIUrls


if __name__ == "__main__":

    settings = get_normalized_settings()
    # APIUrls is in v1_0/handlers/urls.py -- path table
    application = Application(handlers=APIUrls, **settings)
    # attaching database here -- used to initialize request handlers
    # see base.py db property
    application.db = get_db_session(settings)

    if settings['debug']:
        enable_pretty_logging()
        # simple single process pattern
        application.listen(settings['bind_port'], settings['bind_addr'], )
    else:
        server = HTTPServer(application)
        # simple multi-process pattern
        server.bind(settings['bind_port'], settings['bind_addr'] )
        server.start(settings['tornado_start'])

    print 'starting server...'
    IOLoop.instance().start()
开发者ID:Begun-A,项目名称:Kv-008,代码行数:32,代码来源:app.py

示例5: main

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
def main():
    application = Application(urls, **settings)
    application.db = Pool.instance(settings["dsn"])
    http_server = HTTPServer(application)
    http_server.listen(settings["port"], settings["host"])
    IOLoop.instance().start()
开发者ID:Sicun,项目名称:sicun.org,代码行数:8,代码来源:main.py

示例6: define

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
import routes
from common import settings 
from tornado.web import Application
from tornado.gen import IOLoop
from tornado.log import gen_log
from tornado.options import define,options ,parse_command_line

from motor.motor_tornado import MotorClient

define('port',default=11108,type=int,help='listen port')
define('debug',default=True,type=bool,help='running at debug mode?')

import logging
logging.basicConfig(level=logging.DEBUG)


if __name__ == '__main__':
	parse_command_line()

	client = MotorClient(host='192.168.2.14',port=27017)
	db=client['smscenter']

	handlers=[]
	handlers.extend(routes.routes)
	app = Application(handlers=handlers,**settings)
	app.db=db
	
	gen_log.info('server listening at '+str(options.port))
	app.listen(options.port)
	IOLoop.current().start()
开发者ID:hulingfeng211,项目名称:tornado-amazeui,代码行数:32,代码来源:manager.py

示例7: silence_gap

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
        start, end = silence_gap(now)
        if start <= now <= end:
            return

    for stamp in stamps:
        if stamp.key in cfg.events:
            error, _ = thresholds(stamp, now, start, end)
            elapsed = now - stamp.timestamp
            if elapsed >= timedelta(seconds=error) and elapsed <= alert_duration:
                alert(stamp, **cfg.alert_options)


if os.path.exists(CONFIG):
    parse_config_file(CONFIG)
parse_command_line()

format = load_backend(cfg.format)
alert = load_backend(cfg.alert)
alert_duration = timedelta(seconds=cfg.alert_duration) if cfg.alert_duration else timedelta.max

app = Application([
    (r"/", MainHandler),
    (r"/([\w-]+)/?", EventHandler),
], debug=cfg.debug)

app.db = AsyncClient(cfg.database)

app.listen(cfg.port)
PeriodicCallback(monitor, cfg.monitor).start()
IOLoop.instance().start()
开发者ID:APSL,项目名称:lifeordeath,代码行数:32,代码来源:app.py

示例8: signal_term_handler

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]

def signal_term_handler(sig, _):
    logging.error("Got %s. Quit.", sig)
    exit(0)


if __name__ == '__main__':
    signal(SIGTERM, signal_term_handler)
    app = Application([
        (r"/websocket", Handler),
        (r"/()", StaticFileHandler, {'path': 'static/index.html'}),
        (r"/userpics/(.+)", StaticFileHandler, {'path': 'userpics/'}),
        (r"/static/(.+)", StaticFileHandler, {'path': 'static/'}),
    ])
    try:
        ioloop = IOLoop.instance()
        app.db = Pool(dsn="dbname=mol user=mol password=molpassword "
                          "host=localhost port=5432",
                      size=5, max_size=100, auto_shrink=True,
                      ioloop=ioloop)
        future = app.db.connect()
        ioloop.add_future(future, lambda _: ioloop.stop())
        app.wsPool = {}
        ioloop.start()
        future.result()
        app.listen(1984, address="127.0.0.1")
        ioloop.start()
    except KeyboardInterrupt:
        signal_term_handler(SIGTERM, None)
开发者ID:JJjie,项目名称:RuCTF-2015,代码行数:31,代码来源:main.py

示例9: get_app

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
 def get_app(self):
         app = Application(urls.handlers, **config.settings)
         app.db = tornado.database.Connection(
             host=options.mysql_host, database=options.mysql_database,
             user=options.mysql_user, password=options.mysql_password)
         return app
开发者ID:CarlosGabaldon,项目名称:lean_mail,代码行数:8,代码来源:handlers_test.py

示例10: len

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import db [as 别名]
                    result = len(user_1_ips & user_2_ips) > 0

        self.write(str(result or False))
        self.finish()


if __name__ == '__main__':
    application = Application([
        (r'/', MainHandler),
    ])
    conn_params = {
        'db_name': 'tornado',
        'username': 'tornado',
        'password': 'tornado',
        'host': 'localhost',
        'port': 5432,
    }
    ioloop = IOLoop.instance()
    application.db = Pool(dsn="dbname={db_name} "
                              "user={username} "
                              "password={password} "
                              "host={host} "
                              "port={port}".format(**conn_params),
                          size=1, ioloop=ioloop)
    future = application.db.connect()
    ioloop.add_future(future, lambda f: ioloop.stop())
    ioloop.start()

    application.listen(8888)
    ioloop.start()
开发者ID:AndrewLvov,项目名称:ipaddr,代码行数:32,代码来源:main.py


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