class_docstr: Implements the HTTP/1.x protocol.
  
  This class can be on its own for clients, or via `HTTP1ServerConnection`
  for servers.
class_docstr_tok: ["Implements","the","HTTP\/1.x","protocol",".","This","class","can","be","on","its","own","for","clients",",","or","via","`","HTTP1ServerConnection","`","for","servers","."]
code: def _format_chunk(self, chunk: bytes) -> bytes:
      if self._expected_content_remaining is not None:
          self._expected_content_remaining -= len(chunk)
          if self._expected_content_remaining < 0:
              # Close the stream now to stop further framing errors.
              self.stream.close()
              raise httputil.HTTPOutputError(
                  "Tried to write more data than Content-Length"
              )
      if self._chunking_output and chunk:
          # Don't write out empty chunks because that means END-OF-STREAM
          # with chunked encoding
          return utf8("%x" % len(chunk)) + b"\r\n" + chunk + b"\r\n"
      else:
          return chunk
  
imports: import asyncio
  import logging
  import re
  import types
  from tornado.concurrent import Future, future_add_done_callback, future_set_result_unless_cancelled
  from tornado.escape import native_str, utf8
  from tornado import gen
  from tornado import httputil
  from tornado import iostream
  from tornado.log import gen_log, app_log
  from tornado.util import GzipDecompressor
  from typing import cast, Optional, Type, Awaitable, Callable, Union, Tuple
label_desc: Use image node_id 11 for calling the HTTP1Connection obj's underlying member method code with example usage: obj._format_chunk(chunk) and returns: unknown, chunk