本文整理汇总了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)