MCPcopy
hub / github.com/tornadoweb/tornado / _format_chunk

Method _format_chunk

tornado/http1connection.py:473–487  ·  view source on GitHub ↗
(self, chunk: bytes)

Source from the content-addressed store, hash-verified

471 return future
472
473 def _format_chunk(self, chunk: bytes) -> bytes:
474 if self._expected_content_remaining is not None:
475 self._expected_content_remaining -= len(chunk)
476 if self._expected_content_remaining < 0:
477 # Close the stream now to stop further framing errors.
478 self.stream.close()
479 raise httputil.HTTPOutputError(
480 "Tried to write more data than Content-Length"
481 )
482 if self._chunking_output and chunk:
483 # Don't write out empty chunks because that means END-OF-STREAM
484 # with chunked encoding
485 return utf8("%x" % len(chunk)) + b"\r\n" + chunk + b"\r\n"
486 else:
487 return chunk
488
489 def write(self, chunk: bytes) -> "Future[None]":
490 """Implements `.HTTPConnection.write`.

Callers 2

write_headersMethod · 0.95
writeMethod · 0.95

Calls 2

utf8Function · 0.90
closeMethod · 0.45

Tested by

no test coverage detected