| 405 | # |
| 406 | |
| 407 | class Server(asyncore.dispatcher): |
| 408 | if 1: |
| 409 | """Copied from http_server in medusa""" |
| 410 | def __init__ (self, ip, port, handler): |
| 411 | self.ip = ip |
| 412 | self.port = port |
| 413 | self.handler = handler |
| 414 | asyncore.dispatcher.__init__ (self) |
| 415 | self.create_socket (socket.AF_INET, socket.SOCK_STREAM) |
| 416 | |
| 417 | self.set_reuse_addr() |
| 418 | self.bind ((ip, port)) |
| 419 | |
| 420 | # Quoting the socket module documentation... |
| 421 | # listen(backlog) |
| 422 | # Listen for connections made to the socket. The backlog argument |
| 423 | # specifies the maximum number of queued connections and should |
| 424 | # be at least 1; the maximum value is system-dependent (usually |
| 425 | # 5). |
| 426 | self.listen (5) |
| 427 | |
| 428 | def handle_accept (self): |
| 429 | try: |
| 430 | conn, addr = self.accept() |
| 431 | except socket.error: |
| 432 | self.log_info ('warning: server accept() threw an exception', 'warning') |
| 433 | return |
| 434 | except TypeError: |
| 435 | self.log_info ('warning: server accept() threw EWOULDBLOCK', 'warning') |
| 436 | return |
| 437 | # creates an instance of the handler class to handle the request/response |
| 438 | # on the incoming connexion |
| 439 | self.handler(conn,addr,self) |
| 440 | |
| 441 | favicon = zlib.decompress( |
| 442 | 'x\x9c\xb5\x93\xcdN\xdb@\x14\x85\x07\x95\x07\xc8\x8amYv\xc9#\xe4\x11x\x04\x96}' |