• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python webob.exc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __call__

 def __call__(self, environ, start_response):
     try:
         request = self.get_request(environ)
         path, realpath, statinfo = self.check_path(request.path)
         app = self.serve_file(path, realpath, statinfo, request)
         if app:
             return app(environ, start_response)
         exc = get_http_exception(httplib.NOT_FOUND)
         return exc(environ, start_response)
     except webob.exc.HTTPException, exc:
         return exc(environ, start_response)
开发者ID:smulloni,项目名称:satimol,代码行数:11,代码来源:fileserver.py


示例2: test_413_fault_json

    def test_413_fault_json(self):
        # Test fault serialized to JSON via file-extension and/or header.
        requests = [
            webob.Request.blank('/.json'),
            webob.Request.blank('/', headers={"Accept": "application/json"}),
        ]

        for request in requests:
            exc = webob.exc.HTTPRequestEntityTooLarge
            # NOTE(aloga): we intentionally pass an integer for the
            # 'Retry-After' header. It should be then converted to a str
            fault = wsgi.Fault(exc(explanation='sorry',
                        headers={'Retry-After': 4}))
            response = request.get_response(fault)

            expected = {
                "overLimit": {
                    "message": "sorry",
                    "code": 413,
                    "retryAfter": "4",
                },
            }
            actual = jsonutils.loads(response.body)

            self.assertEqual(response.content_type, "application/json")
            self.assertEqual(expected, actual)
开发者ID:B-Rich,项目名称:nova-1,代码行数:26,代码来源:test_faults.py


示例3: __call__

    def __call__(self, environ, start_response):
        """
        Call the application and catch exceptions.
        """
        app_iter = None

        # Just call the application and send the output back
        #   unchanged and catch relevant HTTP exceptions
        try:
            app_iter = self.app(environ, start_response)
        except (HTTPClientError, HTTPRedirection), exc:        
            app_iter = exc(environ, start_response)            
开发者ID:djdarkbeat,项目名称:coldsweat,代码行数:12,代码来源:app.py


示例4: test_HTTPException

def test_HTTPException():
    import warnings
    _called = []
    _result = object()
    def _response(environ, start_response):
        _called.append((environ, start_response))
        return _result
    environ = {}
    start_response = object()
    exc = HTTPException('testing', _response)
    ok_(exc.wsgi_response is _response)
    result = exc(environ, start_response)
    ok_(result is result)
    assert_equal(_called, [(environ, start_response)])
开发者ID:dairiki,项目名称:webob,代码行数:14,代码来源:test_exc.py


示例5: test_413_fault_json

    def test_413_fault_json(self):
        """Test fault serialized to JSON via file-extension and/or header."""
        requests = [webob.Request.blank("/.json"), webob.Request.blank("/", headers={"Accept": "application/json"})]

        for request in requests:
            exc = webob.exc.HTTPRequestEntityTooLarge
            fault = wsgi.Fault(exc(explanation="sorry", headers={"Retry-After": 4}))
            response = request.get_response(fault)

            expected = {"overLimit": {"message": "sorry", "code": 413, "retryAfter": 4}}
            actual = jsonutils.loads(response.body)

            self.assertEqual(response.content_type, "application/json")
            self.assertEqual(expected, actual)
开发者ID:kleopatra999,项目名称:manila,代码行数:14,代码来源:test_faults.py


示例6: exception_from_response

def exception_from_response(response):
    """Convert an OpenStack V2 Fault into a webob exception.

    Since we are calling the OpenStack API we should process the Faults
    produced by them. Extract the Fault information according to [1] and
    convert it back to a webob exception.

    [1] http://docs.openstack.org/developer/nova/v2/faults.html

    :param response: a webob.Response containing an exception
    :returns: a webob.exc.exception object
    """
    exceptions = {
        400: webob.exc.HTTPBadRequest,
        401: webob.exc.HTTPUnauthorized,
        403: webob.exc.HTTPForbidden,
        404: webob.exc.HTTPNotFound,
        405: webob.exc.HTTPMethodNotAllowed,
        406: webob.exc.HTTPNotAcceptable,
        409: webob.exc.HTTPConflict,
        413: webob.exc.HTTPRequestEntityTooLarge,
        415: webob.exc.HTTPUnsupportedMediaType,
        429: webob.exc.HTTPTooManyRequests,
        501: webob.exc.HTTPNotImplemented,
        503: webob.exc.HTTPServiceUnavailable,
    }

    message = ('Unexpected API Error. Please report this at '
               'http://bugs.launchpad.net/ooi/ and attach the ooi '
               'API log if possible.')

    code = response.status_int
    exc = exceptions.get(code, webob.exc.HTTPInternalServerError)

    if code in exceptions:
        try:
            message = response.json_body.popitem()[1].get("message")
        except Exception:
            LOG.exception("Unknown error happenened processing response %s"
                          % response)
            exc = webob.exc.HTTPInternalServerError
    else:
        LOG.error("Nova returned an internal server error %s"
                  % response)

    return exc(explanation=message)
开发者ID:openstack,项目名称:ooi,代码行数:46,代码来源:helpers.py


示例7: __call__

 def __call__(self, environ, start_response):
                 
     # Note that catching the webob exception is for Python 2.4 support.
     # In the brave new world of new-style exceptions (derived from object)
     # multiple inheritance works like you'd expect: the NotAuthenticatedError 
     # is caught because it descends from the past and webob exceptions.
     # In the old world (2.4-), the webob exception needs to be in the catch list
         
     environ['paste.httpexceptions'] = self
     environ.setdefault('paste.expected_exceptions',
                        []).extend([paste.httpexceptions.HTTPException,
                                    webob.exc.HTTPException])
     try:
         return self.application(environ, start_response)        
     except (paste.httpexceptions.HTTPException, 
             webob.exc.HTTPException), exc:        
         return exc(environ, start_response)
开发者ID:nakato,项目名称:AuthKit,代码行数:17,代码来源:__init__.py


示例8: test_HTTPException

def test_HTTPException():
    import warnings
    _called = []
    _result = object()
    def _response(environ, start_response):
        _called.append((environ, start_response))
        return _result
    environ = {}
    start_response = object()
    exc = HTTPException('testing', _response)
    ok_(exc.wsgi_response is _response)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        assert(exc.exception is exc)
        assert(len(w) == 1)
    result = exc(environ, start_response)
    ok_(result is result)
    assert_equal(_called, [(environ, start_response)])
开发者ID:alertedsnake,项目名称:webob,代码行数:18,代码来源:test_exc.py


示例9: test_413_fault_xml

    def test_413_fault_xml(self):
        requests = [
            webob.Request.blank('/.xml'),
            webob.Request.blank('/', headers={"Accept": "application/xml"}),
        ]

        for request in requests:
            exc = webob.exc.HTTPRequestEntityTooLarge
            fault = faults.Fault(exc(explanation='sorry',
                        headers={'Retry-After': 4}))
            response = request.get_response(fault)

            expected = self._prepare_xml("""
                <overLimit code="413" xmlns="%s">
                    <message>sorry</message>
                    <retryAfter>4</retryAfter>
                </overLimit>
            """ % common.XML_NS_V10)
            actual = self._prepare_xml(response.body)

            self.assertEqual(expected, actual)
            self.assertEqual(response.content_type, "application/xml")
            self.assertEqual(response.headers['Retry-After'], 4)
开发者ID:kavanista,项目名称:nova,代码行数:23,代码来源:test_faults.py


示例10: manage_http_exception

def manage_http_exception(code, message):
    exc = default_exceptions.get(code, webob.exc.HTTPInternalServerError)
    return exc("%s" % message)
开发者ID:indigo-dc,项目名称:bdocker,代码行数:3,代码来源:exceptions.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python webob.Request类代码示例发布时间:2022-05-26
下一篇:
Python reportview.get_match_cond函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap