Lines Matching refs:self
15 def new_loop(self):
18 def run_loop_briefly(self, *, delay=0.01):
19 self.loop.run_until_complete(asyncio.sleep(delay))
21 def loop_exception_handler(self, loop, context):
22 self.__unhandled_exceptions.append(context)
23 self.loop.default_exception_handler(context)
25 def setUp(self):
26 self.loop = self.new_loop()
29 self.loop.set_exception_handler(self.loop_exception_handler)
30 self.__unhandled_exceptions = []
32 def tearDown(self):
34 self.loop.close()
36 if self.__unhandled_exceptions:
38 pprint.pprint(self.__unhandled_exceptions)
39 self.fail('unexpected calls to loop.call_exception_handler()')
43 self.loop = None
45 def tcp_server(self, server_prog, *,
67 self, sock, server_prog, timeout, max_clients)
69 def tcp_client(self, client_prog,
82 self, sock, client_prog, timeout)
84 def unix_server(self, *args, **kwargs):
87 return self.tcp_server(*args, family=socket.AF_UNIX, **kwargs)
89 def unix_client(self, *args, **kwargs):
92 return self.tcp_client(*args, family=socket.AF_UNIX, **kwargs)
95 def unix_sock_name(self):
106 def _abort_socket_test(self, ex):
108 self.loop.stop()
110 self.fail(ex)
120 def __init__(self, sock):
121 self.__sock = sock
123 def recv_all(self, n):
126 data = self.recv(n - len(buf))
132 def start_tls(self, ssl_context, *,
137 self.__sock, server_side=server_side,
147 self.__sock.close()
149 self.__sock = ssl_sock
151 def __getattr__(self, name):
152 return getattr(self.__sock, name)
154 def __repr__(self):
155 return '<{} {!r}>'.format(type(self).__name__, self.__sock)
160 def stop(self):
161 self._active = False
162 self.join()
164 def __enter__(self):
165 self.start()
166 return self
168 def __exit__(self, *exc):
169 self.stop()
174 def __init__(self, test, sock, prog, timeout):
175 threading.Thread.__init__(self, None, None, 'test-client')
176 self.daemon = True
178 self._timeout = timeout
179 self._sock = sock
180 self._active = True
181 self._prog = prog
182 self._test = test
184 def run(self):
186 self._prog(TestSocketWrapper(self._sock))
188 self._test._abort_socket_test(ex)
193 def __init__(self, test, sock, prog, timeout, max_clients):
194 threading.Thread.__init__(self, None, None, 'test-server')
195 self.daemon = True
197 self._clients = 0
198 self._finished_clients = 0
199 self._max_clients = max_clients
200 self._timeout = timeout
201 self._sock = sock
202 self._active = True
204 self._prog = prog
206 self._s1, self._s2 = socket.socketpair()
207 self._s1.setblocking(False)
209 self._test = test
211 def stop(self):
213 if self._s2 and self._s2.fileno() != -1:
215 self._s2.send(b'stop')
221 def run(self):
223 with self._sock:
224 self._sock.setblocking(False)
225 self._run()
227 self._s1.close()
228 self._s2.close()
230 def _run(self):
231 while self._active:
232 if self._clients >= self._max_clients:
236 [self._sock, self._s1], [], [], self._timeout)
238 if self._s1 in r:
241 if self._sock in r:
243 conn, addr = self._sock.accept()
247 if not self._active:
252 self._clients += 1
253 conn.settimeout(self._timeout)
256 self._handle_client(conn)
258 self._active = False
262 self._test._abort_socket_test(ex)
264 def _handle_client(self, sock):
265 self._prog(TestSocketWrapper(sock))
268 def addr(self):
269 return self._sock.getsockname()