| 206 | self.handle_close() |
| 207 | |
| 208 | class DummyPOP3Server(asyncore.dispatcher, threading.Thread): |
| 209 | |
| 210 | handler = DummyPOP3Handler |
| 211 | |
| 212 | def __init__(self, address, af=socket.AF_INET): |
| 213 | threading.Thread.__init__(self) |
| 214 | asyncore.dispatcher.__init__(self) |
| 215 | self.daemon = True |
| 216 | self.create_socket(af, socket.SOCK_STREAM) |
| 217 | self.bind(address) |
| 218 | self.listen(5) |
| 219 | self.active = False |
| 220 | self.active_lock = threading.Lock() |
| 221 | self.host, self.port = self.socket.getsockname()[:2] |
| 222 | self.handler_instance = None |
| 223 | |
| 224 | def start(self): |
| 225 | assert not self.active |
| 226 | self.__flag = threading.Event() |
| 227 | threading.Thread.start(self) |
| 228 | self.__flag.wait() |
| 229 | |
| 230 | def run(self): |
| 231 | self.active = True |
| 232 | self.__flag.set() |
| 233 | try: |
| 234 | while self.active and asyncore.socket_map: |
| 235 | with self.active_lock: |
| 236 | asyncore.loop(timeout=0.1, count=1) |
| 237 | finally: |
| 238 | asyncore.close_all(ignore_all=True) |
| 239 | |
| 240 | def stop(self): |
| 241 | assert self.active |
| 242 | self.active = False |
| 243 | self.join() |
| 244 | |
| 245 | def handle_accepted(self, conn, addr): |
| 246 | self.handler_instance = self.handler(conn) |
| 247 | |
| 248 | def handle_connect(self): |
| 249 | self.close() |
| 250 | handle_read = handle_connect |
| 251 | |
| 252 | def writable(self): |
| 253 | return 0 |
| 254 | |
| 255 | def handle_error(self): |
| 256 | raise |
| 257 | |
| 258 | |
| 259 | class TestPOP3Class(TestCase): |