raise ValueError(
"non-zero flags not allowed in calls to sendall() on %s" %
self.__class__)
- amount = len(data)
count = 0
- while (count < amount):
- v = self.send(data[count:])
- count += v
+ with memoryview(data) as view, view.cast("B") as byte_view:
+ amount = len(byte_view)
+ while count < amount:
+ v = self.send(byte_view[count:])
+ count += v
else:
return socket.sendall(self, data, flags)
import weakref
import platform
import functools
+try:
+ import ctypes
+except ImportError:
+ ctypes = None
ssl = support.import_module("ssl")
self.assertEqual(s.read(-1, buffer), len(data))
self.assertEqual(buffer, data)
+ # sendall accepts bytes-like objects
+ if ctypes is not None:
+ ubyte = ctypes.c_ubyte * len(data)
+ byteslike = ubyte.from_buffer_copy(data)
+ s.sendall(byteslike)
+ self.assertEqual(s.read(), data)
+
# Make sure sendmsg et al are disallowed to avoid
# inadvertent disclosure of data and/or corruption
# of the encrypted data stream
self.assertRaises(NotImplementedError, s.recvmsg, 100)
self.assertRaises(NotImplementedError,
s.recvmsg_into, bytearray(100))
-
s.write(b"over\n")
self.assertRaises(ValueError, s.recv, -1)