MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / send

Method send

tools/python-3.11.9-amd64/Lib/http/client.py:988–1026  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

986 response.close()
987
988 def send(self, data):
989 """Send `data' to the server.
990 ``data`` can be a string object, a bytes object, an array object, a
991 file-like object that supports a .read() method, or an iterable object.
992 """
993
994 if self.sock is None:
995 if self.auto_open:
996 self.connect()
997 else:
998 raise NotConnected()
999
1000 if self.debuglevel > 0:
1001 print("send:", repr(data))
1002 if hasattr(data, "read") :
1003 if self.debuglevel > 0:
1004 print("sending a readable")
1005 encode = self._is_textIO(data)
1006 if encode and self.debuglevel > 0:
1007 print("encoding file using iso-8859-1")
1008 while 1:
1009 datablock = data.read(self.blocksize)
1010 if not datablock:
1011 break
1012 if encode:
1013 datablock = datablock.encode("iso-8859-1")
1014 sys.audit("http.client.send", self, datablock)
1015 self.sock.sendall(datablock)
1016 return
1017 sys.audit("http.client.send", self, data)
1018 try:
1019 self.sock.sendall(data)
1020 except TypeError:
1021 if isinstance(data, collections.abc.Iterable):
1022 for d in data:
1023 self.sock.sendall(d)
1024 else:
1025 raise TypeError("data should be a bytes-like object "
1026 "or an iterable, got %r" % type(data))
1027
1028 def _output(self, s):
1029 """Add a line of output to the current request buffer.

Callers 3

_tunnelMethod · 0.95
_send_outputMethod · 0.95
request_chunkedMethod · 0.95

Calls 8

connectMethod · 0.95
_is_textIOMethod · 0.95
NotConnectedClass · 0.85
printFunction · 0.50
typeClass · 0.50
readMethod · 0.45
encodeMethod · 0.45
sendallMethod · 0.45

Tested by

no test coverage detected