MCPcopy Index your code
hub / github.com/RustPython/RustPython / _send_output

Method _send_output

Lib/http/client.py:1104–1156  ·  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

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

Callers 1

endheadersMethod · 0.95

Calls 9

sendMethod · 0.95
_read_readableMethod · 0.95
hasattrFunction · 0.85
iterFunction · 0.85
lenFunction · 0.85
printFunction · 0.50
extendMethod · 0.45
joinMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected