本文整理匯總了Python中cyclone.web.RequestHandler.write方法的典型用法代碼示例。如果您正苦於以下問題:Python RequestHandler.write方法的具體用法?Python RequestHandler.write怎麽用?Python RequestHandler.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cyclone.web.RequestHandler
的用法示例。
在下文中一共展示了RequestHandler.write方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write
# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import write [as 別名]
def write(self, chunk):
"""
This is a monkey patch to RequestHandler to allow us to serialize also
json list objects.
"""
if isinstance(chunk, types.ListType):
self.set_header("Content-Type", "application/json")
chunk = escape.json_encode(chunk)
RequestHandler.write(self, chunk)
示例2: RequestHandlerTest
# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import write [as 別名]
#.........這裏部分代碼省略.........
self.rh.clear_cookie("name")
self.assertEqual(None, self.rh.get_cookie("name"))
def test_clear_all_cookies(self):
self.rh.clear_cookie = Mock()
self.rh.request.cookies = {"foo": None}
self.rh.clear_all_cookies()
self.rh.clear_cookie.assert_called_with("foo")
def test_redirect_too_late(self):
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)