本文整理汇总了Python中werkzeug.Response.from_app方法的典型用法代码示例。如果您正苦于以下问题:Python Response.from_app方法的具体用法?Python Response.from_app怎么用?Python Response.from_app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Response
的用法示例。
在下文中一共展示了Response.from_app方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_path_info_from_request_uri_fix
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def test_path_info_from_request_uri_fix():
"""Test the PathInfoFromRequestUriFix fixer"""
app = fixers.PathInfoFromRequestUriFix(path_check_app)
for key in 'REQUEST_URI', 'REQUEST_URL', 'UNENCODED_URL':
env = dict(create_environ(), SCRIPT_NAME='/test', PATH_INFO='/?????')
env[key] = '/test/foo%25bar?drop=this'
response = Response.from_app(app, env)
assert response.data == 'PATH_INFO: /foo%bar\nSCRIPT_NAME: /test'
示例2: test_lighttpd_cgi_root_fix
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def test_lighttpd_cgi_root_fix():
"""Test the LighttpdCGIRootFix fixer"""
app = fixers.LighttpdCGIRootFix(path_check_app)
response = Response.from_app(app, dict(create_environ(),
SCRIPT_NAME='/foo',
PATH_INFO='/bar'
))
assert response.data == 'PATH_INFO: /foo/bar\nSCRIPT_NAME: '
示例3: test_fix_headers_in_response
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def test_fix_headers_in_response():
"""Make sure fix_headers still works for backwards compatibility"""
from werkzeug import Response
class MyResponse(Response):
def fix_headers(self, environ):
Response.fix_headers(self, environ)
self.headers['x-foo'] = "meh"
myresp = MyResponse('Foo')
resp = Response.from_app(myresp, create_environ(method='GET'))
assert resp.headers['x-foo'] == 'meh'
assert resp.data == 'Foo'
示例4: test_header_rewriter_fix
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def test_header_rewriter_fix():
"""Test the HeaderRewriterFix fixer"""
@Request.application
def application(request):
return Response("", headers=[
('X-Foo', 'bar')
])
application = fixers.HeaderRewriterFix(application, ('X-Foo',), (('X-Bar', '42'),))
response = Response.from_app(application, create_environ())
assert response.headers['Content-Type'] == 'text/plain; charset=utf-8'
assert 'X-Foo' not in response.headers
assert response.headers['X-Bar'] == '42'
示例5: test_proxy_fix
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def test_proxy_fix():
"""Test the ProxyFix fixer"""
@fixers.ProxyFix
@Request.application
def app(request):
return Response('%s|%s' % (
request.remote_addr,
# do not use request.host as this fixes too :)
request.environ['HTTP_HOST']
))
response = Response.from_app(app, dict(create_environ(),
HTTP_X_FORWARDED_HOST='example.com',
HTTP_X_FORWARDED_FOR='1.2.3.4, 5.6.7.8',
REMOTE_ADDR='127.0.0.1',
HTTP_HOST='fake'
))
assert response.data == '1.2.3.4|example.com'
示例6: test_fix_headers_in_response
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def test_fix_headers_in_response():
"""Make sure fix_headers still works for backwards compatibility"""
# ignore some warnings werkzeug emits for backwards compat
for msg in ['called into deprecated fix_headers',
'fix_headers changed behavior']:
warnings.filterwarnings('ignore', message=msg,
category=DeprecationWarning)
from werkzeug import Response
class MyResponse(Response):
def fix_headers(self, environ):
Response.fix_headers(self, environ)
self.headers['x-foo'] = "meh"
myresp = MyResponse('Foo')
resp = Response.from_app(myresp, create_environ(method='GET'))
assert resp.headers['x-foo'] == 'meh'
assert resp.data == 'Foo'
warnings.resetwarnings()
示例7: __call__
# 需要导入模块: from werkzeug import Response [as 别名]
# 或者: from werkzeug.Response import from_app [as 别名]
def __call__(self, request, **kwargs):
self.request = request
response = Response.from_app(self.app, self.request.environ)
return response