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

Method flush

python/python3/tornado/web.py:1060–1108  ·  view source on GitHub ↗

Flushes the current output buffer to the network. .. versionchanged:: 4.0 Now returns a `.Future` if no callback is given. .. versionchanged:: 6.0 The ``callback`` argument was removed.

(self, include_footers: bool = False)

Source from the content-addressed store, hash-verified

1058 return template.Loader(template_path, **kwargs)
1059
1060 def flush(self, include_footers: bool = False) -> "Future[None]":
1061 """Flushes the current output buffer to the network.
1062
1063 .. versionchanged:: 4.0
1064 Now returns a `.Future` if no callback is given.
1065
1066 .. versionchanged:: 6.0
1067
1068 The ``callback`` argument was removed.
1069 """
1070 assert self.request.connection is not None
1071 chunk = b"".join(self._write_buffer)
1072 self._write_buffer = []
1073 if not self._headers_written:
1074 self._headers_written = True
1075 for transform in self._transforms:
1076 assert chunk is not None
1077 (
1078 self._status_code,
1079 self._headers,
1080 chunk,
1081 ) = transform.transform_first_chunk(
1082 self._status_code, self._headers, chunk, include_footers
1083 )
1084 # Ignore the chunk and only write the headers for HEAD requests
1085 if self.request.method == "HEAD":
1086 chunk = b""
1087
1088 # Finalize the cookie headers (which have been stored in a side
1089 # object so an outgoing cookie could be overwritten before it
1090 # is sent).
1091 if hasattr(self, "_new_cookie"):
1092 for cookie in self._new_cookie.values():
1093 self.add_header("Set-Cookie", cookie.OutputString(None))
1094
1095 start_line = httputil.ResponseStartLine("", self._status_code, self._reason)
1096 return self.request.connection.write_headers(
1097 start_line, self._headers, chunk
1098 )
1099 else:
1100 for transform in self._transforms:
1101 chunk = transform.transform_chunk(chunk, include_footers)
1102 # Ignore the chunk and only write the headers for HEAD requests
1103 if self.request.method != "HEAD":
1104 return self.request.connection.write(chunk)
1105 else:
1106 future = Future() # type: Future[None]
1107 future.set_result(None)
1108 return future
1109
1110 def finish(self, chunk: Optional[Union[str, bytes, dict]] = None) -> "Future[None]":
1111 """Finishes this response, ending the HTTP request.

Callers 4

finishMethod · 0.95
getMethod · 0.45
transform_chunkMethod · 0.45
finishMethod · 0.45

Calls 6

add_headerMethod · 0.95
joinMethod · 0.80
transform_first_chunkMethod · 0.45
write_headersMethod · 0.45
transform_chunkMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected