當前位置: 首頁>>代碼示例>>Python>>正文


Python interfaces.IResponse類代碼示例

本文整理匯總了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;未經允許,請勿轉載。