本文整理匯總了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