コード例 #1
0
ファイル: BLIPListenerTest.py プロジェクト: smorr/MYNetwork
    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")
コード例 #2
0
ファイル: BLIPListenerTest.py プロジェクト: sduret/letters
    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")
コード例 #3
0
 def testClose(self):
     listen = Listener(1337)
     listen.onConnected = self.handleConnection
     listen.onRequest = self.handleRequest
     
     try:
         asyncore.loop()
     except KeyboardInterrupt:
         pass
コード例 #4
0
ファイル: BLIPListenerTest.py プロジェクト: BJonny/flycode
 def testListener(self):
     def handleRequest(request):
         logging.info("Got request!: %r",request)
         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()
     
     listener = Listener(46353)
     listener.onRequest = handleRequest
     logging.info("Listener is waiting...")
     
     try:
         asyncore.loop()
     except KeyboardInterrupt:
         logging.info("KeyboardInterrupt")