本文整理汇总了Python中handlers.COOKIE_NAME属性的典型用法代码示例。如果您正苦于以下问题:Python handlers.COOKIE_NAME属性的具体用法?Python handlers.COOKIE_NAME怎么用?Python handlers.COOKIE_NAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类handlers
的用法示例。
在下文中一共展示了handlers.COOKIE_NAME属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auth_factory
# 需要导入模块: import handlers [as 别名]
# 或者: from handlers import COOKIE_NAME [as 别名]
def auth_factory(app, handler):
@asyncio.coroutine
def auth(request):
logging.info('check user: %s %s' % (request.method, request.path))
request.__user__ = None # ?????__user__????None
cookie_str = request.cookies.get(COOKIE_NAME) # ??cookie?????cookie????COOKIE_NAME??headlers??????
if cookie_str:
user = yield from cookie2user(cookie_str) # ??cookie????????
if user:
logging.info('set current user: %s' % user.email)
request.__user__ = user # ???????????
# ???????????????????????????????
if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
return web.HTTPFound('/signin')
return (yield from handler(request))
return auth
# ????????POST?????????
示例2: auth_factory
# 需要导入模块: import handlers [as 别名]
# 或者: from handlers import COOKIE_NAME [as 别名]
def auth_factory(app, handler):
'''
middleware(???)???cookie?????????
'''
async def auth(request):
logging.info('check user: %s %s' % (request.method, request.path))
request.__user__ = None
cookie_str = request.cookies.get(COOKIE_NAME)
if cookie_str:
# ??cookie???????????
user = await cookie2user(cookie_str)
if user:
logging.info('set current user:%s' % user.email)
request.__user__ = user
if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
# HTTPFound: Exception->HTTPRedirection->302
return web.HTTPFound('/signin')
return (await handler(request))
return auth
示例3: auth_factory
# 需要导入模块: import handlers [as 别名]
# 或者: from handlers import COOKIE_NAME [as 别名]
def auth_factory(app,handler):
async def auth(request):
request.__user__ = None
cookie_str = request.cookies.get(COOKIE_NAME)
if cookie_str:
user = await cookie2user(cookie_str)
if user:
logging.info('set current user :%s' % user.email)
request.__user__ = user
if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
return web.HTTPFound('/signin')
return await handler(request)
return auth
# ??????
示例4: auth_factory
# 需要导入模块: import handlers [as 别名]
# 或者: from handlers import COOKIE_NAME [as 别名]
def auth_factory(app, handler):
@asyncio.coroutine
def auth(request):
logging.info('check user: {} {}'.format(request.method, request.path))
request.__user__ = None
cookie_str = request.cookies.get(COOKIE_NAME)
if cookie_str:
user = yield from cookie2user(cookie_str)
if user:
logging.info('set current user: {}'.format(user.email))
request.__user__ = user
if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
return web.HTTPFound('/signin')
return (yield from handler(request))
return auth
示例5: auth_factory
# 需要导入模块: import handlers [as 别名]
# 或者: from handlers import COOKIE_NAME [as 别名]
def auth_factory(app, handler):
async def auth(request):
logging.info('check user: %s %s' % (request.method, request.path))
request.__user__ = None
cookie_str = request.cookies.get(COOKIE_NAME)
if cookie_str:
user = await cookie2user(cookie_str)
if user:
logging.info('set current user: %s' % user.email)
request.__user__ = user
if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
return web.HTTPFound('/signin')
return (await handler(request))
return auth