MCPcopy Create free account
hub / github.com/EasyIME/PIME / write

Method write

python/python3/tornado/web.py:818–848  ·  view source on GitHub ↗

Writes the given chunk to the output buffer. To write the output to the network, use the `flush()` method below. If the given chunk is a dictionary, we write it as JSON and set the Content-Type of the response to be ``application/json``. (if you want to send JSON as

(self, chunk: Union[str, bytes, dict])

Source from the content-addressed store, hash-verified

816 self.finish()
817
818 def write(self, chunk: Union[str, bytes, dict]) -> None:
819 """Writes the given chunk to the output buffer.
820
821 To write the output to the network, use the `flush()` method below.
822
823 If the given chunk is a dictionary, we write it as JSON and set
824 the Content-Type of the response to be ``application/json``.
825 (if you want to send JSON as a different ``Content-Type``, call
826 ``set_header`` *after* calling ``write()``).
827
828 Note that lists are not converted to JSON because of a potential
829 cross-site security vulnerability. All JSON output should be
830 wrapped in a dictionary. More details at
831 http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and
832 https://github.com/facebook/tornado/issues/1009
833 """
834 if self._finished:
835 raise RuntimeError("Cannot write() after finish()")
836 if not isinstance(chunk, (bytes, unicode_type, dict)):
837 message = "write() only accepts bytes, unicode, and dict objects"
838 if isinstance(chunk, list):
839 message += (
840 ". Lists not accepted for security reasons; see "
841 + "http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write" # noqa: E501
842 )
843 raise TypeError(message)
844 if isinstance(chunk, dict):
845 chunk = escape.json_encode(chunk)
846 self.set_header("Content-Type", "application/json; charset=UTF-8")
847 chunk = utf8(chunk)
848 self._write_buffer.append(chunk)
849
850 def render(self, template_name: str, **kwargs: Any) -> "Future[None]":
851 """Renders the template with the given arguments as the response.

Callers 15

finishMethod · 0.95
write_errorMethod · 0.95
getMethod · 0.45
getMethod · 0.45
postMethod · 0.45
save_fileMethod · 0.45
launch_browserMethod · 0.45
mainFunction · 0.45
convert_liu_unitabFunction · 0.45
MaFunction · 0.45
flushMethod · 0.45
getMethod · 0.45

Calls 3

set_headerMethod · 0.95
utf8Function · 0.90
appendMethod · 0.45

Tested by

no test coverage detected