Пример #1
0
def init(loop):
    #orm.create_pool()创建数据库连接:
    yield from orm.create_pool(loop=loop,
                               host='127.0.0.1',
                               port=3306,
                               user='******',
                               password='******',
                               db='awesome')
    #创建 middlewares 请求响应处理器(字典类型)对象,可以通过‘请求处理程序’返回对应数据:
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    #初始化jinja2模板,添加filter(过滤器):
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    #'handelers'模块自动注册,也就是取代aiohttp.web.UrlDispatcher.add_route()单个增加响应规则:
    add_routes(app, 'handlers')
    #aiohttp.web.UrlDispatcher.add_route():增加响应规则;即设置请求条件(请求方式,地址等...)和对应的处理程序:
    #app.router.add_route('GET', '/', index)
    #给文件添加静态地址:
    add_static(app)

    #loop.create_server()利用asyncio创建TCP服务:
    #make_handler()创建HTTP协议处理器来处理请求:
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    #打印日志信息:
    logging.info('server started at http://127.0.0.1:9000...')
    print('server started at http://127.0.0.1:9000...')
    return srv
Пример #2
0
def init(loop):
    app = web.Application(loop=loop,
                          middlewares=[logger_factory, response_factory])
    add_routes(app, 'www.handlers')
    srv = yield from loop.create_server(app.make_handler(), 'localhost', 8080)
    logging.info('server started at http://localhost:8080...')
    return srv
Пример #3
0
def init(loop):
    yield from www.orm.create_pool(loop=loop, host=configs['db']['host'], port=configs['db']['port'], user=configs['db']['username'], password=configs['db']['password'], db=configs['db']['database'])
    app = web.Application(loop=loop, middlewares=[logger_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000....')
    return srv
Пример #4
0
def init(loop):
    yield from www.orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, "handlers")
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), "127.0.0.1", 9000)
    logging.info("server started at http://127.0.0.1:9000...")
    return srv
Пример #5
0
async def init(loop):
    await www.orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #6
0
async def init(loop):
    await orm.create_pool(loop, host='127.0.0.1', port=3306, user='******', password='******', db='blog')
    app = web.Application(loop=loop, middlewares=[factories.logger_factory, factories.auth_factory, factories.response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #7
0
async def init(loop):
    await orm.create_pool(loop=loop, host='172.21.13.65', port=3306, user='******', password='******', db='awesome')
    app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info("server started at http://127.0.0.1:9000")
    return srv
Пример #8
0
def init(loop):
    yield from orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[response_factory])
    # app.router.add_route()
    add_routes(app, 'handlers')

    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #9
0
async def init(loop):
    await orm.create_pool(loop=loop, **db_conf)
    app = web.Application(loop=loop,
                          middlewares=[looger_factory, response_factory])
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #10
0
async def init(loop):
    await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome')
    app = web.Application(loop=loop, middlewares=[
        logger_factory, response_factory
    ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #11
0
def init(loop):
    logging.info("start server")
    yield from www.orm.createPool(loop=loop)
    app = web.Application(
        loop=loop, middlewares=[loggerFactory, authFactory, responseFactory])
    init_jinja2(app, filter=dict(datetime=datetimeFilter))
    add_routes(app, 'handles')
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8888)
    logging.info('server started at http://127.0.0.1:8888...')
    return srv
Пример #12
0
def init(loop):
    yield from www.orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='weibo')
    app = web.Application(loop=loop, middlewares=[logger_factory, data_factory, auth_factory, response_factory])

    init_jinja2(app, filters=dict(datetime=datetime_filter))

    add_routes(app, 'www.handlers')
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000')
    return srv
Пример #13
0
def init(loop):
    yield from orm.create_pool(loop=loop, **configs.db)
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    port = 9001
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', port)
    logging.info('server started at http://127.0.0.1:%s...' % port)
    return srv
Пример #14
0
async def init(loop):
    await www.orm.create_pool(loop=loop, **www.config.configs.db)
    # await www.orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='python_blog')
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #15
0
async def init(loop):
    await orm.create_pool(loop=loop, **configs.db)
    app = web.Application(
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    runner = web.AppRunner(app)
    await runner.setup()
    srv = web.TCPSite(runner, 'localhost', 9000)
    logging.info('server started at http://localhost:9000...')
    await srv.start()
Пример #16
0
async def init(loop):
    await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='leilei')
    """middlewares是一种拦截器,一个URL在被某个函数处理前,可以经过一系列的middleware的处理。"""
    #创建app 并且添加拦截器::对其进行预处理 log 和response的一些处理
    app = web.Application(loop=loop, middlewares=[
        logger_factory, response_factory,auth_factory
    ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9001)
    logging.info('server started at http://127.0.0.1:9001...')
    return srv
Пример #17
0
async def init(loop):
    await create_pool(loop,
                      host='localhost',
                      user='******',
                      password='******',
                      db='poetry')
    app = web.Application(loop=loop,
                          middlewares=[auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    manage_static(app)
    srv = await loop.create_server(app.make_handler(), 'localhost', 8888)
    logging.info('server started at http://127.0.0.1:8888...')
    return srv
Пример #18
0
async def init(loop):
    await orm.create_pool(loop=loop,
                          host='123.206.178.243',
                          port=3306,
                          user='******',
                          password='******',
                          db='awesome')
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, response_factory, auth_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'www.handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000')
    return srv
Пример #19
0
def init(loop):
    yield from www.orm.create_pool(loop=loop,
                               host = '127.0.0.1',
                              port = 3306,
                              user = '******',
                              password = '******',
                              db = 'awesome')
    app = web.Application(loop=loop, middlewares=[
        logger_factory, auth_factory, response_factory
    ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #20
0
async def init(loop):
    await www.orm.create_pool(loop=loop,
                              host="127.0.0.1",
                              port=3306,
                              user="******",
                              password="******",
                              db="awesome")
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, "handlers")
    add_static(app)
    srv = await loop.create_server(app.make_handler(), "127.0.0.1", 9000)
    logging.info("server started at http://127.0.0.1:9000...")
    return srv
Пример #21
0
def init(loop):
    # 创建数据库连接池,db参数传配置文件里边的db
    yield from orm.create_pool(loop=loop, **configs.db)
    # middlewares 设置两个中间处理函数
    # middlewares 中的每个factory接收两个参数,app和handler,即middlewares中下一个handler
    # middlewares 的最后一个元素的 handler会通过routes查找到相应的 routes注册的handler
    app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory])
    # 初始化 jinja2模板
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    # 添加请求的 handlers,即各个请求相对应的处理函数
    add_routes(app, 'handlers')
    # 添加静态文件所在地址
    add_static(app)
    # 启动服务器
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #22
0
async def init(loop):
    await orm.create_pool(loop=loop,
                          host='127.0.0.1',
                          port=3306,
                          user='******',
                          password='******',
                          db='awesome')
    app = web.Application(loop=loop,
                          middlewares=[logger_factory, response_factory])
    init_jinja2(app, filters=dict(
        datetime=datetime_filter))  #初始化Jinja2,这里值得注意是设置文件路径的path参数
    #同级目录不需要添加相应的模块信息
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('Server started at http://127.0.0.1:9000...')
    return srv
Пример #23
0
async def init(loop):
    await orm.create_pool(loop=loop,
                          host='localhost',
                          port=3306,
                          user='******',
                          password='******',
                          db='python')
    app = web.Application(loop=loop,
                          middlewares=[logger_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')  #注册函数处理器
    add_static(app)
    srv = await loop.create_server(app.make_handler(), 'localhost', 9000)
    # srv = await loop.create_server(app.make_handler(), '192.168.0.108', 9000)
    logging.info('server started at http://192.168.1.192:9000...')
    # print('server started at http://192.168.0.103:9000...')
    return srv
Пример #24
0
async def init(loop):
    # await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome')
    await orm.create_pool(loop=loop, **configs.db)

    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, response_factory, auth_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    # app.router.add_route('GET', '/', index)

    host = configs.session.host
    port = configs.session.port
    srv = await loop.create_server(app.make_handler(), host, port)
    logging.info('server started at "http://%s:%d"...' % (host, port))
    return srv
Пример #25
0
async def init(loop):
    loop.set_debug(True)
    logging.getLogger("asyncio").setLevel(logging.WARNING)
    await orm.create_pool(loop=loop,
                          host='127.0.0.1',
                          port=3306,
                          user='******',
                          password='******',
                          db='awesome')
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #26
0
async def init(loop):
    await orm.create_pool(loop=loop,
                          host='120.79.177.232',
                          port=33066,
                          user='******',
                          password='******',
                          database='iwblog')
    app = web.Application(loop=loop,
                          middlewares=[
                              logger_factory, data_factory, response_factory,
                              auth_factory
                          ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app._make_handler(), '127.0.0.1', 9001)
    logging.info('server started at http://127.0.0.1:9001...')
    return srv
Пример #27
0
async def init(loop):
    logging.info('init...')
    from www.config import configs
    await orm.create_pool(loop=loop,
                          host=configs.db.host,
                          port=configs.db.port,
                          user=configs.db.user,
                          password=configs.db.password,
                          db=configs.db.db_name)
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #28
0
async def init(loop):
    '''
    调用asyncio实现异步IO
    :param loop:
    :return:
    '''

    await orm.create_pool(loop=loop, **configs.db)  # 创建数据库连接池
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory,
                     response_factory])  #创建app对象,同时传入上文定义的拦截器middlewares
    init_jinja2(app,
                filters=dict(datetime=datetime_filter))  #初始化jinja2模板,并传入时间过滤器
    add_routes(app, 'handlers')  #handlers指的是handlers模块也就是handlers.py
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #29
0
async def init(loop):
    await www.orm.create_pool(loop=loop,
                              host='127.0.0.1',
                              port=3306,
                              user='******',
                              password='******',
                              db='awesome')
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, response_factory, auth_factory])
    init_jinjia2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    runner = web.AppRunner(app)
    # 耗时的异步操作需要等待
    await runner.setup()
    site = web.TCPSite(runner, '127.0.0.1', 9000)
    # 同是耗时任务,需要等待
    await site.start()
Пример #30
0
async def init(loop):
    await orm.create_pool(loop=loop,
                          host='127.0.0.1',
                          port=3306,
                          user='******',
                          password='******',
                          db='awesome')
    app = web.Application(loop=loop,
                          middlewares=[logger_factory, response_factory])
    # app.router.add_route('GET', '/', index)
    runner = web.AppRunner(app)
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    await runner.setup()

    srv = web.TCPSite(runner, '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000 ...')
    await srv.start()
Пример #31
0
async def init(loop):
    await create_pool(loop=loop,
                      host='127.0.0.1',
                      port=3306,
                      user='******',
                      password='******',
                      db='users')
    app = web.Application(
        loop=loop,
        middlewares=[
            logger_factory,
            auth_factory,
            response_factory  #response_factory指定返回类型
        ])
    # app.router.add_route('GET', '/', index) #这个会返回一个文件,所以一打开就会下载,而不是显示网页
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Пример #32
0
def init(loop):
    #orm.create_pool()创建数据库连接:
    yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome')
    #创建 middlewares 请求响应处理器(字典类型)对象,可以通过‘请求处理程序’返回对应数据:
    app = web.Application(loop=loop, middlewares=[
        logger_factory, auth_factory, response_factory
    ])
    #初始化jinja2模板,添加filter(过滤器):
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    #'handelers'模块自动注册,也就是取代aiohttp.web.UrlDispatcher.add_route()单个增加响应规则:
    add_routes(app, 'handlers')
    #aiohttp.web.UrlDispatcher.add_route():增加响应规则;即设置请求条件(请求方式,地址等...)和对应的处理程序:
    #app.router.add_route('GET', '/', index)
    #给文件添加静态地址:
    add_static(app)

    #loop.create_server()利用asyncio创建TCP服务:
    #make_handler()创建HTTP协议处理器来处理请求:
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    #打印日志信息:
    logging.info('server started at http://127.0.0.1:9000...')
    print('server started at http://127.0.0.1:9000...')
    return srv
Пример #33
0
def init(loop):
    # yield from www.orm.create_pool(loop=loop,host='127.0.0.1',port =3306,user='******',password='******',db='awesome')
    yield from orm.create_pool(loop=loop, **configs.db)

    #  handlers: url对应的内容 middlewares:根据内容的类型决定具体返回的形式
    app = web.Application(
        loop=loop,
        middlewares=[
            # logger_factory, response_factory
            logger_factory,
            auth_factory,
            response_factory
        ])

    # jinja2的filter(过滤器)
    init_jinja2(app, filters=dict(datetime=datetime_filter))

    add_routes(app, 'handlers')  # 与handlers.py 文件名一致
    add_static(app)

    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9090)

    logging.info('server started at http://127.0.0.1:9090...')
    return srv