MCPcopy Index your code
hub / github.com/python/cpython / write

Method write

Lib/_pyio.py:951–969  ·  view source on GitHub ↗
(self, b)

Source from the content-addressed store, hash-verified

949 return self.read(size)
950
951 def write(self, b):
952 if isinstance(b, str):
953 raise TypeError("can't write str to binary stream")
954 with memoryview(b) as view:
955 if self.closed:
956 raise ValueError("write to closed file")
957
958 n = view.nbytes # Size of any bytes-like object
959 if n == 0:
960 return 0
961
962 with self._lock:
963 pos = self._pos
964 if pos > len(self._buffer):
965 # Pad buffer to pos with null bytes.
966 self._buffer.resize(pos)
967 self._buffer[pos:pos + n] = view
968 self._pos += n
969 return n
970
971 def seek(self, pos, whence=0):
972 if self.closed:

Callers 15

optimizeFunction · 0.95
get_messageMethod · 0.95
get_bytesMethod · 0.95
_safe_readMethod · 0.95
list_directoryMethod · 0.95
test_writestrMethod · 0.95
test_writeMethod · 0.95

Calls 1

resizeMethod · 0.45

Tested by 11

test_writestrMethod · 0.76
test_writeMethod · 0.76
test_open_writeMethod · 0.76
construct_zoneMethod · 0.76
zone_from_tzstrMethod · 0.76
check_flush_and_readMethod · 0.76