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)
| 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): |
no test coverage detected