本文整理汇总了Python中pyramid.interfaces.IResponse类的典型用法代码示例。如果您正苦于以下问题:Python IResponse类的具体用法?Python IResponse怎么用?Python IResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IResponse类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self):
self._logger.debug('Request URL: %s.', self.request.url)
try:
if self._enable_messaging:
prep_executor = \
WarnAndResubmitExecutor(self._prepare_resource)
data = prep_executor()
do_continue = prep_executor.do_continue
else:
data = self._prepare_resource()
do_continue = not IResponse.providedBy(data) # pylint: disable=E1101
if do_continue:
# Return a response to bypass Pyramid rendering.
if self._enable_messaging:
res_executor = WarnAndResubmitExecutor(self._get_result)
result = res_executor(data)
else:
result = self._get_result(data)
else:
result = data
except HTTPError as http_exc:
result = self.request.get_response(http_exc)
except Exception as err: # catch Exception pylint: disable=W0703
result = self._handle_unknown_exception(str(err),
get_traceback())
return result
开发者ID:fogathmann,项目名称:everest-thelma,代码行数:26,代码来源:base.py
示例2: __call__
def __call__(self, content, context, request):
chain = query_layout_chain(request.root, context, request, self.layout)
if not chain:
log.warning(
"Can't find layout '%s' for context '%s'",
self.layout, context)
return content
value = request.layout_data
for layout, layoutcontext in chain:
if layout.view is not None:
vdata = layout.view(layoutcontext, request)
if IResponse.providedBy(vdata):
return vdata
if vdata is not None:
value.update(vdata)
system = {'view': getattr(request, '__view__', None),
'renderer_info': layout.renderer,
'context': layoutcontext,
'request': request,
'content': content,
'wrapped_content': content}
content = layout.renderer.render(value, system, request)
if getattr(request, '__layout_debug__', False):
content = self.layout_info(
layout, layoutcontext, request, content)
return content
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:32,代码来源:layout_impl.py
示例3: test_GET_request
def test_GET_request(self):
request = DummyRequest(
path='/proxy/bar/remote/path/@@view',
params={'foo': 'bar'},
headers={'X-BRIDGE-ORIGIN': 'foo',
'X-BRIDGE-AC': 'john.doe'})
response = Response()
response.status_code = 200
response.raw = StringIO('the response data')
response.headers['content-length'] = 17
self.expect(self.requests.request(
'get',
'http://127.0.0.1:9080/bar/remote/path/@@view',
params={'foo': 'bar'},
headers={'X-BRIDGE-ORIGIN': 'foo',
'X-BRIDGE-AC': 'john.doe'})).result(
response)
self.mocker.replay()
proxy = queryAdapter(request, IProxy)
response = proxy()
self.assertTrue(IResponse.providedBy(response))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.body, 'the response data')
开发者ID:4teamwork,项目名称:ftw.bridge.proxy,代码行数:27,代码来源:test_proxy.py
示例4: test_proxy_replaces_portal_url_in_data
def test_proxy_replaces_portal_url_in_data(self):
request = DummyRequest(
path='/proxy/bar/remote/path/@@view',
params={'foo': 'bar %s baz' % PORTAL_URL_PLACEHOLDER},
headers={'X-BRIDGE-ORIGIN': 'foo',
'X-BRIDGE-AC': 'john.doe'})
response = Response()
response.status_code = 200
response.raw = StringIO('response')
self.expect(self.requests.request(
'get',
'http://127.0.0.1:9080/bar/remote/path/@@view',
params={'foo': 'bar http://localhost:8080/foo/ baz'},
headers={'X-BRIDGE-ORIGIN': 'foo',
'X-BRIDGE-AC': 'john.doe'})).result(
response)
self.mocker.replay()
proxy = queryAdapter(request, IProxy)
response = proxy()
self.assertTrue(IResponse.providedBy(response))
self.assertEqual(response.status, '200 OK')
开发者ID:4teamwork,项目名称:ftw.bridge.proxy,代码行数:25,代码来源:test_proxy.py
示例5: my_form_view
def my_form_view(request):
# form
form = pform.Form(
None,
request,
fields=pform.Fieldset(
pform.TextField("name", title=u"Name"), # field title
pform.TextField(
"email",
title=u"E-Mail",
description=u"Please provide email address.",
validator=pform.Email(), # email validator
),
pform.CompositeField(
"address",
title="Address",
fields=(
pform.TextField("street", title="Street", missing=""),
pform.TextField("street1", title="", required=False),
pform.ChoiceField("country", default="US", title="Country", vocabulary=countries),
pform.TextField("city", title="City"),
pform.TextField("state", title="State", required=True),
pform.TextField("zip", title="Zip", required=True),
),
),
),
)
# form actions
def update_handler(form, data):
pprint(data)
form.request.add_message("Content has been updated.")
return HTTPFound(location="/")
def cancel_handler(form):
form.request.add_message("Cancel button")
raise HTTPFound(location="/")
form.buttons.add_action("Update", action=update_handler, actype=pform.AC_PRIMARY, extract=True)
form.buttons.add_action("Cancel", action=cancel_handler)
# form default data
form.content = {
"title": "Test title",
"address": {"city": "Houston", "country": "KZ"},
"description": "Context description",
}
res = form.update_form()
if IResponse.providedBy(res):
return res
return {"view": form}
开发者ID:fafhrd91,项目名称:pform,代码行数:53,代码来源:composite-imperative.py
示例6: update_form
def update_form(self, data=None):
""" update form """
if not self.content and data:
self.content = data
self.update_widgets()
self.update_actions()
ac_result = self.actions.execute()
if IResponse.providedBy(ac_result):
raise HTTPResponseIsReady(ac_result)
result = self.update()
if IResponse.providedBy(result):
raise HTTPResponseIsReady(result)
if result is None:
result = {}
if ac_result is not None:
result.update(ac_result)
return result
开发者ID:fafhrd91,项目名称:pform,代码行数:23,代码来源:form.py
示例7: test_proxy_view
def test_proxy_view(self):
request = DummyRequest(
path='/proxy/foo/remote/path/@@view',
params={'foo': 'bar'},
headers={'X-BRIDGE-ORIGIN': 'bar',
'X-BRIDGE-AC': 'john.doe'},
environ={'REMOTE_ADDR': '127.0.0.1'})
self.expect(self.proxy()).result(Response('proxied response'))
self.mocker.replay()
view = ProxyView(request)
response = view.__call__()
self.assertTrue(IResponse.providedBy(response))
self.assertEqual(response.body, 'proxied response')
开发者ID:4teamwork,项目名称:ftw.bridge.proxy,代码行数:15,代码来源:test_proxy_view.py
示例8: __call_view
def __call_view(self):
if self._enable_messaging:
prep_executor = \
WarnAndResubmitExecutor(self._prepare_resource)
data = prep_executor()
do_continue = prep_executor.do_continue
else:
data = self._prepare_resource()
do_continue = not IResponse.providedBy(data) # pylint: disable=E1101
if do_continue:
# Return a response to bypass Pyramid rendering.
if self._enable_messaging:
res_executor = \
WarnAndResubmitExecutor(self._get_result)
result = res_executor(data)
else:
result = self._get_result(data)
else:
result = data
return result
开发者ID:helixyte,项目名称:everest,代码行数:20,代码来源:base.py
示例9: test_implements_IResponse
def test_implements_IResponse(self):
from pyramid.interfaces import IResponse
cls = self._getTargetClass()
self.assertTrue(IResponse.implementedBy(cls))
开发者ID:HorizonXP,项目名称:pyramid,代码行数:4,代码来源:test_response.py
示例10: test_provides_IResponse
def test_provides_IResponse(self):
from pyramid.interfaces import IResponse
inst = self._getTargetClass()()
self.assertTrue(IResponse.providedBy(inst))
开发者ID:HorizonXP,项目名称:pyramid,代码行数:4,代码来源:test_response.py
示例11: render_to_response
def render_to_response(self, value, system_values, request=None):
result = self.render(value, system_values, request=request)
if IResponse.providedBy(result):
return result
return self._make_response(result, request)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:5,代码来源:layout_impl.py
注:本文中的pyramid.interfaces.IResponse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论