test_urllib2.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:mechanize 作者: python-mechanize 项目源码 文件源码
def test_raise_http_errors(self):
        # HTTPDefaultErrorHandler should raise HTTPError if no error handler
        # handled the error response
        from mechanize import _response
        h = mechanize.HTTPDefaultErrorHandler()

        url = "http://example.com"
        code = 500
        msg = "Error"
        request = mechanize.Request(url)
        response = _response.test_response(url=url, code=code, msg=msg)

        # case 1. it's not an HTTPError
        try:
            h.http_error_default(request, response, code, msg, response.info())
        except mechanize.HTTPError as exc:
            self.assert_(exc is not response)
            self.assert_(exc.fp is response)
        else:
            self.assert_(False)

        # case 2. response object is already an HTTPError, so just re-raise it
        error = mechanize.HTTPError(url, code, msg, "fake headers", response)
        try:
            h.http_error_default(request, error, code, msg, error.info())
        except mechanize.HTTPError as exc:
            self.assert_(exc is error)
        else:
            self.assert_(False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号