MCPcopy Index your code
hub / github.com/python/cpython / _send_output

Method _send_output

Lib/http/client.py:1108–1160  ·  view source on GitHub ↗

Send the currently buffered request and clear the buffer. Appends an extra \\r\\n to the buffer. A message_body may be specified, to be appended to the request.

(self, message_body=None, encode_chunked=False)

Source from the content-addressed store, hash-verified

1106 yield datablock
1107
1108 def _send_output(self, message_body=None, encode_chunked=False):
1109 """Send the currently buffered request and clear the buffer.
1110
1111 Appends an extra \\r\\n to the buffer.
1112 A message_body may be specified, to be appended to the request.
1113 """
1114 self._buffer.extend((b"", b""))
1115 msg = b"\r\n".join(self._buffer)
1116 del self._buffer[:]
1117 self.send(msg)
1118
1119 if message_body is not None:
1120
1121 # create a consistent interface to message_body
1122 if hasattr(message_body, 'read'):
1123 # Let file-like take precedence over byte-like. This
1124 # is needed to allow the current position of mmap'ed
1125 # files to be taken into account.
1126 chunks = self._read_readable(message_body)
1127 else:
1128 try:
1129 # this is solely to check to see if message_body
1130 # implements the buffer API. it /would/ be easier
1131 # to capture if PyObject_CheckBuffer was exposed
1132 # to Python.
1133 memoryview(message_body)
1134 except TypeError:
1135 try:
1136 chunks = iter(message_body)
1137 except TypeError:
1138 raise TypeError("message_body should be a bytes-like "
1139 "object or an iterable, got %r"
1140 % type(message_body))
1141 else:
1142 # the object implements the buffer interface and
1143 # can be passed directly into socket methods
1144 chunks = (message_body,)
1145
1146 for chunk in chunks:
1147 if not chunk:
1148 if self.debuglevel > 0:
1149 print('Zero length chunk ignored')
1150 continue
1151
1152 if encode_chunked and self._http_vsn == 11:
1153 # chunked encoding
1154 chunk = f'{len(chunk):X}\r\n'.encode('ascii') + chunk \
1155 + b'\r\n'
1156 self.send(chunk)
1157
1158 if encode_chunked and self._http_vsn == 11:
1159 # end chunked transfer
1160 self.send(b'0\r\n\r\n')
1161
1162 def putrequest(self, method, url, skip_host=False,
1163 skip_accept_encoding=False):

Callers 1

endheadersMethod · 0.95

Calls 5

sendMethod · 0.95
_read_readableMethod · 0.95
extendMethod · 0.45
joinMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected