class FakeSocket: def __init__(self, address): self.address = address self.captured = b"" self.messages = MessageInbox(self, on_error=print) def getsockname(self): return "127.0.0.1", 0xFFFF def getpeername(self): return self.address def recv_into(self, buffer, nbytes): data = self.captured[:nbytes] actual = len(data) buffer[:actual] = data self.captured = self.captured[actual:] return actual def sendall(self, data): self.captured += data def close(self): return def pop_message(self): return self.messages.pop()
def __init__(self, address=None, on_send=None): self.address = address self.recv_buffer = bytearray() self._messages = MessageInbox(self, on_error=print) self.on_send = on_send
def __init__(self, address): self.address = address self.captured = b"" self.messages = MessageInbox(self, on_error=print)