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

Method write

Lib/asyncio/selector_events.py:1051–1088  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

1049 self.close()
1050
1051 def write(self, data):
1052 if not isinstance(data, (bytes, bytearray, memoryview)):
1053 raise TypeError(f'data argument must be a bytes, bytearray, or memoryview '
1054 f'object, not {type(data).__name__!r}')
1055 if self._eof:
1056 raise RuntimeError('Cannot call write() after write_eof()')
1057 if self._empty_waiter is not None:
1058 raise RuntimeError('unable to write; sendfile is in progress')
1059 if not data:
1060 return
1061
1062 if self._conn_lost:
1063 if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
1064 logger.warning('socket.send() raised exception.')
1065 self._conn_lost += 1
1066 return
1067
1068 if not self._buffer:
1069 # Optimization: try to send now.
1070 try:
1071 n = self._sock.send(data)
1072 except (BlockingIOError, InterruptedError):
1073 pass
1074 except (SystemExit, KeyboardInterrupt):
1075 raise
1076 except BaseException as exc:
1077 self._fatal_error(exc, 'Fatal write error on socket transport')
1078 return
1079 else:
1080 data = memoryview(data)[n:]
1081 if not data:
1082 return
1083 # Not all was written; register write handler.
1084 self._loop._add_writer(self._sock_fd, self._write_ready)
1085
1086 # Add it to the buffer.
1087 self._buffer.append(data)
1088 self._maybe_pause_protocol()
1089
1090 def _get_sendmsg_buffer(self):
1091 return itertools.islice(self._buffer, SC_IOV_MAX)

Callers

nothing calls this directly

Calls 7

isinstanceFunction · 0.85
_maybe_pause_protocolMethod · 0.80
warningMethod · 0.45
sendMethod · 0.45
_fatal_errorMethod · 0.45
_add_writerMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected