当前位置: 首页>>代码示例>>Python>>正文


Python webob.dec方法代码示例

本文整理汇总了Python中webob.dec方法的典型用法代码示例。如果您正苦于以下问题:Python webob.dec方法的具体用法?Python webob.dec怎么用?Python webob.dec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob的用法示例。


在下文中一共展示了webob.dec方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _do_test_exception_safety_reflected_in_faults

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def _do_test_exception_safety_reflected_in_faults(self, expose):
        class ExceptionWithSafety(exception.ManilaException):
            safe = expose

        @webob.dec.wsgify
        def fail(req):
            raise ExceptionWithSafety('some explanation')

        api = self._wsgi_app(fail)
        resp = webob.Request.blank('/').get_response(api)
        self.assertIn('{"computeFault', six.text_type(resp.body), resp.body)
        expected = ('ExceptionWithSafety: some explanation' if expose else
                    'The server has either erred or is incapable '
                    'of performing the requested operation.')
        self.assertIn(expected, six.text_type(resp.body), resp.body)
        self.assertEqual(500, resp.status_int, resp.body) 
开发者ID:openstack,项目名称:manila,代码行数:18,代码来源:test_faults.py

示例2: test_compat_headers

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_compat_headers(self):
        """Test that compat headers are set

        Compat headers might exist on a super class to support
        previous API contracts. This ensures that you can set that to
        a list of headers and those values are the same as the
        request_id.

        """
        @webob.dec.wsgify
        def application(req):
            return req.environ[request_id.ENV_REQUEST_ID]

        app = AltHeader(application)
        req = webob.Request.blank('/test')
        res = req.get_response(app)

        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)

        self.assertEqual(res.headers.get("x-compute-req-id"), res_req_id)
        self.assertEqual(res.headers.get("x-silly-id"), res_req_id) 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:23,代码来源:test_request_id.py

示例3: test_global_request_id_set

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_global_request_id_set(self):
        """Test that global request_id is set."""
        @webob.dec.wsgify
        def application(req):
            return req.environ[request_id.GLOBAL_REQ_ID]

        global_req = "req-%s" % uuid.uuid4()
        app = request_id.RequestId(application)
        req = webob.Request.blank(
            '/test',
            headers={"X-OpenStack-Request-ID": global_req})
        res = req.get_response(app)
        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
        if isinstance(res_req_id, bytes):
            res_req_id = res_req_id.decode('utf-8')
        # global-request-id in request environ is returned as response body
        self.assertEqual(res.body.decode('utf-8'), global_req)
        self.assertNotEqual(res.body.decode('utf-8'), res_req_id) 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:20,代码来源:test_request_id.py

示例4: test_global_request_id_drop

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_global_request_id_drop(self):
        """Test that bad format ids are dropped.

        This ensures that badly formatted ids are dropped entirely.
        """
        @webob.dec.wsgify
        def application(req):
            return req.environ.get(request_id.GLOBAL_REQ_ID)

        global_req = "req-%s-bad" % uuid.uuid4()
        app = request_id.RequestId(application)
        req = webob.Request.blank(
            '/test',
            headers={"X-OpenStack-Request-ID": global_req})
        res = req.get_response(app)
        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
        if isinstance(res_req_id, bytes):
            res_req_id = res_req_id.decode('utf-8')
        # global-request-id in request environ is returned as response body
        self.assertEqual(res.body.decode('utf-8'), '') 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:22,代码来源:test_request_id.py

示例5: __call__

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def __call__(self, request):
        """WSGI method that controls (de)serialization and method dispatch."""

        LOG.info(_LI("%(method)s %(url)s"),
                 {"method": request.method,
                  "url": request.url})

        # Identify the action, its arguments, and the requested
        # content type
        action_args = self.get_action_args(request.environ)
        action = action_args.pop('action', None)
        content_type, body = self.get_body(request)
        accept = request.best_match_content_type()

        # NOTE(Vek): Splitting the function up this way allows for
        #            auditing by external tools that wrap the existing
        #            function.  If we try to audit __call__(), we can
        #            run into troubles due to the @webob.dec.wsgify()
        #            decorator.
        return self._process_stack(request, action, action_args,
                                   content_type, body, accept) 
开发者ID:cloudbase,项目名称:coriolis,代码行数:23,代码来源:wsgi.py

示例6: test_raise

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_raise(self):
        """Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
        @webob.dec.wsgify
        def raiser(req):
            raise wsgi.Fault(webob.exc.HTTPNotFound(explanation='whut?'))

        req = webob.Request.blank('/.json')
        resp = req.get_response(raiser)
        self.assertEqual("application/json", resp.content_type)
        self.assertEqual(404, resp.status_int)
        self.assertIn(six.b('whut?'), resp.body) 
开发者ID:openstack,项目名称:manila,代码行数:13,代码来源:test_faults.py

示例7: test_raise_403

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_raise_403(self):
        """Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
        @webob.dec.wsgify
        def raiser(req):
            raise wsgi.Fault(webob.exc.HTTPForbidden(explanation='whut?'))

        req = webob.Request.blank('/.json')
        resp = req.get_response(raiser)
        self.assertEqual("application/json", resp.content_type)
        self.assertEqual(403, resp.status_int)
        self.assertNotIn(six.b('resizeNotAllowed'), resp.body)
        self.assertIn(six.b('forbidden'), resp.body) 
开发者ID:openstack,项目名称:manila,代码行数:14,代码来源:test_faults.py

示例8: _do_test_exception_mapping

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def _do_test_exception_mapping(self, exception_type, msg):
        @webob.dec.wsgify
        def fail(req):
            raise exception_type(msg)

        api = self._wsgi_app(fail)
        resp = webob.Request.blank('/').get_response(api)
        self.assertIn(msg, six.text_type(resp.body), resp.body)
        self.assertEqual(exception_type.code, resp.status_int, resp.body)

        if hasattr(exception_type, 'headers'):
            for (key, value) in exception_type.headers.items():
                self.assertIn(key, resp.headers)
                self.assertEqual(value, resp.headers[key]) 
开发者ID:openstack,项目名称:manila,代码行数:16,代码来源:test_faults.py

示例9: test_exception_with_none_code_throws_500

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_exception_with_none_code_throws_500(self):
        class ExceptionWithNoneCode(Exception):
            code = None

        @webob.dec.wsgify
        def fail(req):
            raise ExceptionWithNoneCode()

        api = self._wsgi_app(fail)
        resp = webob.Request.blank('/').get_response(api)
        self.assertEqual(500, resp.status_int) 
开发者ID:openstack,项目名称:manila,代码行数:13,代码来源:test_faults.py

示例10: test_generate_request_id

# 需要导入模块: import webob [as 别名]
# 或者: from webob import dec [as 别名]
def test_generate_request_id(self):
        @webob.dec.wsgify
        def application(req):
            return req.environ[request_id.ENV_REQUEST_ID]

        app = request_id.RequestId(application)
        req = webob.Request.blank('/test')
        res = req.get_response(app)
        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
        if isinstance(res_req_id, bytes):
            res_req_id = res_req_id.decode('utf-8')
        self.assertThat(res_req_id, matchers.StartsWith('req-'))
        # request-id in request environ is returned as response body
        self.assertEqual(res.body.decode('utf-8'), res_req_id) 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:16,代码来源:test_request_id.py


注:本文中的webob.dec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。