Lines Matching refs:self

31     def __init__(self, event):
32 threading.Thread.__init__(self)
33 self.event = event
34 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
35 self.port = socket_helper.bind_port(self.sock)
38 self.start_resend_event = None
40 def run(self):
41 self.sock.listen()
42 self.event.set()
43 conn, client = self.sock.accept()
44 self.buffer = b""
46 while SERVER_QUIT not in self.buffer:
50 self.buffer = self.buffer + data
53 self.buffer = self.buffer.replace(SERVER_QUIT, b'')
55 if self.start_resend_event:
56 self.start_resend_event.wait()
62 while self.buffer:
63 n = conn.send(self.buffer[:self.chunk_size])
65 self.buffer = self.buffer[n:]
70 self.sock.close()
74 def __init__(self, terminator, server_port):
75 asynchat.async_chat.__init__(self)
76 self.contents = []
77 self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
78 self.connect((HOST, server_port))
79 self.set_terminator(terminator)
80 self.buffer = b""
82 def handle_connect(self):
88 def handle_expt(self):
91 def collect_incoming_data(self, data):
92 self.buffer += data
94 def found_terminator(self):
95 self.contents.append(self.buffer)
96 self.buffer = b""
111 def setUp(self):
112 self._threads = threading_helper.threading_setup()
114 def tearDown(self):
115 threading_helper.threading_cleanup(*self._threads)
117 def line_terminator_check(self, term, server_chunk):
130 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
133 self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
139 def test_line_terminator1(self):
142 self.line_terminator_check(b'\n', l)
144 def test_line_terminator2(self):
147 self.line_terminator_check(b'\r\n', l)
149 def test_line_terminator3(self):
152 self.line_terminator_check(b'qqq', l)
154 def numeric_terminator_check(self, termlen):
161 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
164 self.assertEqual(c.contents, [data[:termlen]])
166 def test_numeric_terminator1(self):
169 self.numeric_terminator_check(1)
171 def test_numeric_terminator2(self):
172 self.numeric_terminator_check(6)
174 def test_none_terminator(self):
181 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
184 self.assertEqual(c.contents, [])
185 self.assertEqual(c.buffer, data)
187 def test_simple_producer(self):
193 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
196 self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
198 def test_string_producer(self):
203 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
206 self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
208 def test_empty_line(self):
214 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
217 self.assertEqual(c.contents,
220 def test_close_when_done(self):
227 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
236 self.assertEqual(c.contents, [])
240 self.assertGreater(len(s.buffer), 0)
242 def test_push(self):
251 self.assertRaises(TypeError, c.push, 10)
252 self.assertRaises(TypeError, c.push, 'unicode')
254 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
256 self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes'])
264 def test_blockingioerror(self):
271 self.addCleanup(dispatcher.del_channel)
275 self.assertFalse(error.called)
279 def test_find_prefix_at_end(self):
280 self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1)
281 self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0)
285 def test_disallow_negative_terminator(self):
288 self.assertRaises(ValueError, client.set_terminator, -1)