This commit is contained in:
2026-08-02 18:57:40 +02:00
parent 5e5ab8681a
commit 6fa59321c0
5759 changed files with 712133 additions and 66 deletions
@@ -0,0 +1,27 @@
import typing
import OpenSSL.SSL
class SendWrap:
def __init__(self, sock: OpenSSL.SSL.Connection):
self.__sock = sock
self.__cached_write = None # type: typing.Optional[typing.Tuple[bytes, typing.Any]] # noqa
def send(self, buf: typing.Union[bytes, memoryview]) -> int:
if self.__cached_write is not None:
as_bytes, prev_buf = self.__cached_write
if prev_buf is not buf:
raise ValueError(
"this looks like a mistake: the previous send received a "
"different buffer object"
)
self.__cached_write = None
else:
as_bytes = bytes(buf)
try:
return self.__sock.send(as_bytes)
except (OpenSSL.SSL.WantWriteError, OpenSSL.SSL.WantReadError):
self.__cached_write = as_bytes, buf
raise