def _init(self, subject, parent=None, *arg, **kw): self.reader = json.Reader(subject) self.writer = json.Writer(subject) dispatcher.Connection._init(self, subject=subject, parent=parent, *arg, **kw)
def test_return_on_closed_socket(self): server_socket = test_make_server_socket() echo_server = TestEchoServer(server_socket, name="TestEchoServer") client_socket = test_make_client_socket() writer = json.Writer(client_socket) writer.write_value({'foo': 1, 'bar': 2}) client_socket.close() echo_server.shutdown() echo_server.join()
def test_client(self): sockets = socket.socketpair() echo_server = TestEchoClient(sockets[1]) reader = json.Reader(sockets[0]) writer = json.Writer(sockets[0]) obj = {'foo': 1, 'bar': [1, 2]} writer.write_value(obj) return_obj = reader.read_value() self.assertEqual(obj, return_obj)
def test_server(self): for n in range(3): server_socket = test_make_server_socket() echo_server = TestEchoServer(server_socket, name="TestEchoServer") client_socket = test_make_client_socket() reader = json.Reader(client_socket) writer = json.Writer(client_socket) obj = {'foo': 1, 'bar': [1, 2]} writer.write_value(obj) return_obj = reader.read_value() self.assertEqual(obj, return_obj) echo_server.shutdown() echo_server.join()