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


Python RequestHandler.write_error方法代碼示例

本文整理匯總了Python中cyclone.web.RequestHandler.write_error方法的典型用法代碼示例。如果您正苦於以下問題:Python RequestHandler.write_error方法的具體用法?Python RequestHandler.write_error怎麽用?Python RequestHandler.write_error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cyclone.web.RequestHandler的用法示例。


在下文中一共展示了RequestHandler.write_error方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: write_error

# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import write_error [as 別名]
 def write_error(self, error, **kw):
     if hasattr(error, 'http_status'):
         self.set_status(error.http_status)
         self.write({'error_message': error.error_message,
             'error_code' : error.error_code})
     else:
         RequestHandler.write_error(self, error, **kw)
開發者ID:vecna,項目名稱:GLBackend,代碼行數:9,代碼來源:base.py

示例2: write_error

# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import write_error [as 別名]
    def write_error(self, status_code, **kw):
        exception = kw.get("exception")
        if exception and hasattr(exception, "error_code"):
            error_dict = {"error_message": exception.reason, "error_code": exception.error_code}

            if hasattr(exception, "arguments"):
                error_dict.update({"arguments": exception.arguments})
            else:
                error_dict.update({"arguments": []})

            self.set_status(status_code)
            self.finish(error_dict)
        else:
            RequestHandler.write_error(self, status_code, **kw)
開發者ID:corvolino,項目名稱:GlobaLeaks,代碼行數:16,代碼來源:base.py

示例3: write_error

# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import write_error [as 別名]
    def write_error(self, status_code, **kw):
        exception = kw.get('exception')
        if exception and hasattr(exception, 'error_code'):

            error_dict = {}
            error_dict.update({'error_message': exception.reason, 'error_code': exception.error_code})
            if hasattr(exception, 'arguments'):
                error_dict.update({'arguments': exception.arguments})
            else:
                error_dict.update({'arguments': []})

            self.set_status(status_code)
            self.finish(error_dict)
        else:
            RequestHandler.write_error(self, status_code, **kw)
開發者ID:tonegas,項目名稱:GlobaLeaks,代碼行數:17,代碼來源:base.py

示例4: RequestHandlerTest

# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import write_error [as 別名]

#.........這裏部分代碼省略.........
        self.rh._headers_written = True
        self.assertRaises(Exception, self.rh.redirect, "/")

    def test_redirect_with_perm(self):
        self.rh.flush = Mock()
        self.rh._log = Mock()
        self.rh.redirect("/", permanent=True)

    def test_redirect_with_slashes(self):
        self.rh.flush = Mock()
        self.rh._log = Mock()
        self.assertRaises(
            AssertionError,
            self.rh.redirect,
            "//example.com",
            status=400)

    def test_redirect_bad_url(self):
        self.rh.flush = Mock()
        self.rh._log = Mock()
        self.rh.request.uri = "foo"
        self.rh.redirect("http://foo.com", permanent=True)

    def test_write_when_finished(self):
        self.rh._finished = True
        self.assertRaises(RuntimeError, self.rh.write, "foo")

    def test_write_dict(self):
        self.rh.write({"foo": "bar"})
        self.assertEqual(
            self.rh._write_buffer,
            ['{"foo": "bar"}']
        )

    def test_create_template_loader(self):
        self.rh.application.settings = {"autoescape": True}
        res = self.rh.create_template_loader("/foo")
        self.assertTrue(res)

    def test_finish_already_finished(self):
        self.rh._finished = True
        self.assertRaises(RuntimeError, self.rh.finish)

    def test_finish_304_with_body(self):
        self.rh._status_code = 304
        self.rh._write_buffer = ""
        self.rh.flush = Mock()
        self.rh._log = Mock()
        self.rh.finish()

    def test_send_error(self):
        self.rh.flush = Mock()
        self.rh._log = Mock()
        self.rh.write_error = Mock()
        self.rh.send_error()
        self.rh.write_error.assert_called_with(500)

    def test_write_error(self):
        self.rh.flush = Mock()
        self.rh._log = Mock()
        self.rh.get_error_html = Mock()
        exc = [Mock(), Mock()]
        self.rh.finish = Mock()
        self.rh.write_error(500, exc_info=exc)

    def test_locale(self):
        self.request.headers = {
            "Accept-Language": "en"
        }
        self.rh.locale

    def test_get_user_locale(self):
        self.rh.get_user_locale()

    def test_get_browser_locale(self):
        self.request.headers = {
            "Accept-Language": "en"
        }
        self.rh.get_browser_locale()

    def test_current_user(self):
        self.rh.current_user

    def test_xsrf_token(self):
        self.request.cookies = {}
        self.rh.xsrf_token

    def test_check_xsrf_cookie(self):
        self.request.arguments = {self.rh.xsrf_cookie_name: "foo"}
        self.request.cookies = {}
        self.assertRaises(HTTPError, self.rh.check_xsrf_cookie)

    def test_xsrf_form_html(self):
        self.request.arguments = {self.rh.xsrf_cookie_name: "foo"}
        self.request.cookies = {}
        self.rh.xsrf_form_html()

    def test_static_url(self):
        self.rh.application.settings = {"static_path": "."}
        self.rh.static_url("/")
開發者ID:fiorix,項目名稱:cyclone,代碼行數:104,代碼來源:test_web.py


注:本文中的cyclone.web.RequestHandler.write_error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。