MCPcopy
hub / github.com/opendevops-cn/opendevops / write

Method write

scripts/tornado_source_code/tornado/web.py:809–839  ·  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

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

Callers 7

finishMethod · 0.95
write_errorMethod · 0.95
flushMethod · 0.45
getMethod · 0.45
transform_chunkMethod · 0.45
_write_bodyMethod · 0.45
_write_frameMethod · 0.45

Calls 3

set_headerMethod · 0.95
utf8Function · 0.90
appendMethod · 0.80

Tested by

no test coverage detected