def testListener(self): def handleConnection(conn): logging.info("Got new connection: %r", conn) conn.ListenerTestNumRequests = 0 def handleRequest(request): logging.info("Got request!: %r", request) request.connection.ListenerTestNumRequests += 1 body = request.body assert len(body) < 32768 assert request.contentType == 'application/octet-stream' assert int(request['Size']) == len(body) assert request['User-Agent'] != None for i in xrange(0, len(request.body)): assert ord(body[i]) == i % 256 response = request.response response.body = request.body response['Content-Type'] = request.contentType response.send() if request.connection.ListenerTestNumRequests >= 50: request.connection.close() listener = Listener(46353) listener.onConnected = handleConnection listener.onRequest = handleRequest logging.info("Listener is waiting...") try: asyncore.loop() except KeyboardInterrupt: logging.info("KeyboardInterrupt")
def testListener(self): def handleConnection(conn): logging.info("Got new connection: %r", conn) conn.ListenerTestNumRequests = 0 def handleRequest(request): logging.info("Got request!: %r", request) request.connection.ListenerTestNumRequests += 1 body = request.body assert len(body) < 32768 assert request.contentType == "application/octet-stream" assert int(request["Size"]) == len(body) assert request["User-Agent"] != None for i in xrange(0, len(request.body)): assert ord(body[i]) == i % 256 response = request.response response.body = request.body response["Content-Type"] = request.contentType response.send() if request.connection.ListenerTestNumRequests >= 50: request.connection.close() listener = Listener(46353) listener.onConnected = handleConnection listener.onRequest = handleRequest logging.info("Listener is waiting...") try: asyncore.loop() except KeyboardInterrupt: logging.info("KeyboardInterrupt")
def testClose(self): listen = Listener(1337) listen.onConnected = self.handleConnection listen.onRequest = self.handleRequest try: asyncore.loop() except KeyboardInterrupt: pass