本文整理汇总了Python中aspen.testing.client.Client.build_wsgi_environ方法的典型用法代码示例。如果您正苦于以下问题:Python Client.build_wsgi_environ方法的具体用法?Python Client.build_wsgi_environ怎么用?Python Client.build_wsgi_environ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aspen.testing.client.Client
的用法示例。
在下文中一共展示了Client.build_wsgi_environ方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_wsgi_environ
# 需要导入模块: from aspen.testing.client import Client [as 别名]
# 或者: from aspen.testing.client.Client import build_wsgi_environ [as 别名]
def build_wsgi_environ(self, *a, **kw):
"""Extend base class to support authenticating as a certain user.
"""
# csrf - for both anon and authenticated
self.cookie[b'csrf_token'] = b'sotokeny'
kw[b'HTTP_X-CSRF-TOKEN'] = b'sotokeny'
# user authentication
auth_as = kw.pop('auth_as', None)
if auth_as is None:
if SESSION in self.cookie:
del self.cookie[SESSION]
else:
user = User.from_username(auth_as)
user.sign_in(self.cookie)
return Client.build_wsgi_environ(self, *a, **kw)
示例2: build_wsgi_environ
# 需要导入模块: from aspen.testing.client import Client [as 别名]
# 或者: from aspen.testing.client.Client import build_wsgi_environ [as 别名]
def build_wsgi_environ(self, *a, **kw):
"""Extend base class to support authenticating as a certain user.
"""
self.cookie.clear()
# csrf - for both anon and authenticated
csrf_token = kw.get('csrf_token', b'ThisIsATokenThatIsThirtyTwoBytes')
if csrf_token:
self.cookie[b'csrf_token'] = csrf_token
kw[b'HTTP_X-CSRF-TOKEN'] = csrf_token
# user authentication
auth_as = kw.pop('auth_as', None)
if auth_as:
user.User.from_username(auth_as).sign_in(self.cookie)
for k, v in kw.pop('cookies', {}).items():
self.cookie[k] = v
return Client.build_wsgi_environ(self, *a, **kw)
示例3: build_wsgi_environ
# 需要导入模块: from aspen.testing.client import Client [as 别名]
# 或者: from aspen.testing.client.Client import build_wsgi_environ [as 别名]
def build_wsgi_environ(self, *a, **kw):
"""Extend base class to support authenticating as a certain user.
"""
self.cookie.clear()
# csrf - for both anon and authenticated
csrf_token = kw.get('csrf_token', b'ThisIsATokenThatIsThirtyTwoBytes')
if csrf_token:
self.cookie[b'csrf_token'] = csrf_token
kw[b'HTTP_X-CSRF-TOKEN'] = csrf_token
# user authentication
auth_as = kw.pop('auth_as', None)
if auth_as:
assert auth_as.session_token
self.cookie[SESSION] = '%s:%s' % (auth_as.id, auth_as.session_token)
# cookies
for k, v in kw.pop('cookies', {}).items():
self.cookie[k] = v
return Client.build_wsgi_environ(self, *a, **kw)