本文整理汇总了Python中pyramid.interfaces.IResponse.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IResponse.providedBy方法的具体用法?Python IResponse.providedBy怎么用?Python IResponse.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.interfaces.IResponse
的用法示例。
在下文中一共展示了IResponse.providedBy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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
示例2: __call__
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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
示例3: test_GET_request
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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')
示例4: test_proxy_replaces_portal_url_in_data
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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')
示例5: my_form_view
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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}
示例6: update_form
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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
示例7: test_proxy_view
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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')
示例8: __call_view
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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
示例9: test_provides_IResponse
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
def test_provides_IResponse(self):
from pyramid.interfaces import IResponse
inst = self._getTargetClass()()
self.assertTrue(IResponse.providedBy(inst))
示例10: render_to_response
# 需要导入模块: from pyramid.interfaces import IResponse [as 别名]
# 或者: from pyramid.interfaces.IResponse import providedBy [as 别名]
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)