Send 'data' to the server. ``data`` can be a string object, a bytes object, an array object, a file-like object that supports a .read() method, or an iterable object.
(self, data)
| 1047 | response.close() |
| 1048 | |
| 1049 | def send(self, data): |
| 1050 | """Send 'data' to the server. |
| 1051 | ``data`` can be a string object, a bytes object, an array object, a |
| 1052 | file-like object that supports a .read() method, or an iterable object. |
| 1053 | """ |
| 1054 | |
| 1055 | if self.sock is None: |
| 1056 | if self.auto_open: |
| 1057 | self.connect() |
| 1058 | else: |
| 1059 | raise NotConnected() |
| 1060 | |
| 1061 | if self.debuglevel > 0: |
| 1062 | print("send:", repr(data)) |
| 1063 | if hasattr(data, "read") : |
| 1064 | if self.debuglevel > 0: |
| 1065 | print("sending a readable") |
| 1066 | encode = self._is_textIO(data) |
| 1067 | if encode and self.debuglevel > 0: |
| 1068 | print("encoding file using iso-8859-1") |
| 1069 | while datablock := data.read(self.blocksize): |
| 1070 | if encode: |
| 1071 | datablock = datablock.encode("iso-8859-1") |
| 1072 | sys.audit("http.client.send", self, datablock) |
| 1073 | self.sock.sendall(datablock) |
| 1074 | return |
| 1075 | sys.audit("http.client.send", self, data) |
| 1076 | try: |
| 1077 | self.sock.sendall(data) |
| 1078 | except TypeError: |
| 1079 | if isinstance(data, collections.abc.Iterable): |
| 1080 | for d in data: |
| 1081 | self.sock.sendall(d) |
| 1082 | else: |
| 1083 | raise TypeError("data should be a bytes-like object " |
| 1084 | "or an iterable, got %r" % type(data)) |
| 1085 | |
| 1086 | def _output(self, s): |
| 1087 | """Add a line of output to the current request buffer. |