當前位置: 首頁>>代碼示例>>Python>>正文


Python aiohttp_session.session_middleware方法代碼示例

本文整理匯總了Python中aiohttp_session.session_middleware方法的典型用法代碼示例。如果您正苦於以下問題:Python aiohttp_session.session_middleware方法的具體用法?Python aiohttp_session.session_middleware怎麽用?Python aiohttp_session.session_middleware使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aiohttp_session的用法示例。


在下文中一共展示了aiohttp_session.session_middleware方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init

# 需要導入模塊: import aiohttp_session [as 別名]
# 或者: from aiohttp_session import session_middleware [as 別名]
def init(loop):
    conf = load_config(str(PROJ_ROOT / 'config' / 'config.yml'))

    app = web.Application(loop=loop)
    cookie_storage = SimpleCookieStorage()
    app = web.Application(middlewares=[session_middleware(cookie_storage)])
    mongo = await setup_mongo(app, conf, loop)

    setup_jinja(app)

    admin = setup_admin(app, mongo)
    app.add_subapp('/admin', admin)

    app.router.add_static('/static', path=str(PROJ_ROOT / 'static'))

    # setup views and routes
    handler = SiteHandler(mongo)
    setup_routes(app, handler, PROJ_ROOT)

    host, port = conf['host'], conf['port']
    return app, host, port 
開發者ID:aio-libs,項目名稱:aiohttp_admin,代碼行數:23,代碼來源:main.py

示例2: make_app

# 需要導入模塊: import aiohttp_session [as 別名]
# 或者: from aiohttp_session import session_middleware [as 別名]
def make_app():
    #
    # WARNING!!!
    # Never use SimpleCookieStorage on production!!!
    # It’s highly insecure!!!
    #

    # make app
    middleware = session_middleware(SimpleCookieStorage())
    app = web.Application(middlewares=[middleware])

    # add the routes
    app.router.add_route('GET', '/', handler_root)
    app.router.add_route('GET', '/login', handler_login_jack)
    app.router.add_route('GET', '/logout', handler_logout)
    app.router.add_route('GET', '/listen', handler_listen)
    app.router.add_route('GET', '/speak', handler_speak)

    # set up policies
    policy = SessionIdentityPolicy()
    setup_security(app, policy, SimpleJack_AuthorizationPolicy())

    return app 
開發者ID:aio-libs,項目名稱:aiohttp-security,代碼行數:25,代碼來源:simple_example_auth.py

示例3: create_app

# 需要導入模塊: import aiohttp_session [as 別名]
# 或者: from aiohttp_session import session_middleware [as 別名]
def create_app(handler, memcached, max_age=None,
               key_factory=lambda: uuid.uuid4().hex):
    middleware = session_middleware(
        MemcachedStorage(memcached, max_age=max_age, key_factory=key_factory))
    app = web.Application(middlewares=[middleware])
    app.router.add_route('GET', '/', handler)
    return app 
開發者ID:aio-libs,項目名稱:aiohttp-session,代碼行數:9,代碼來源:test_memcached_storage.py

示例4: create_app

# 需要導入模塊: import aiohttp_session [as 別名]
# 或者: from aiohttp_session import session_middleware [as 別名]
def create_app(handler, redis, max_age=None,
               key_factory=lambda: uuid.uuid4().hex):
    middleware = session_middleware(
        RedisStorage(redis, max_age=max_age, key_factory=key_factory))
    app = web.Application(middlewares=[middleware])
    app.router.add_route('GET', '/', handler)
    return app 
開發者ID:aio-libs,項目名稱:aiohttp-session,代碼行數:9,代碼來源:test_redis_storage.py

示例5: session_middleware

# 需要導入模塊: import aiohttp_session [as 別名]
# 或者: from aiohttp_session import session_middleware [as 別名]
def session_middleware(request, handler):
    """Wrapper to Session Middleware factory.
    """
    # Do the trick, by passing app & handler back to original session
    # middleware factory. Do not forget to await on results here as original
    # session middleware factory is also awaitable.
    app = request.app
    storage = RedisStorage(app['redis'], httponly=False)
    middleware = session_middleware_(storage)
    return await middleware(request, handler) 
開發者ID:anxolerd,項目名稱:dvpwa,代碼行數:12,代碼來源:middlewares.py


注:本文中的aiohttp_session.session_middleware方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。