Python/CloseTestPong.py
author morrowa@betelgeuse.local
Tue Jun 23 11:44:30 2009 -0700 (2009-06-23)
changeset 51 de59ce19f42e
child 56 6c3b5372a307
permissions -rw-r--r--
BROKEN COMMIT. Majority of code to handle closing has been added. Listeners do not close correctly.
     1 # CloseTestPong.py
     2 # Tests the closing negotiation facilities of the BLIP 1.1 protocol
     3 
     4 from BLIP import Listener
     5 
     6 import logging
     7 import asyncore
     8 import unittest
     9 
    10 class CloseTestPong(unittest.TestCase):
    11     
    12     def shouldClose(self):
    13         logging.info("Allowed to close.")
    14         return True
    15     
    16     def handleConnection(self, conn):
    17         logging.info("Accepted connection.")
    18         conn.onCloseRequest = self.shouldClose
    19     
    20     def handleRequest(self, req):
    21         resp = req.response
    22         resp.body = "Pong"
    23         resp.send()
    24     
    25     def testClose(self):
    26         listen = Listener(1337)
    27         listen.onConnected = self.handleConnection
    28         listen.onRequest = self.handleRequest
    29         
    30         try:
    31             asyncore.loop()
    32         except KeyboardInterrupt:
    33             pass
    34 
    35 
    36 if __name__ == '__main__':
    37     logging.basicConfig(level=logging.DEBUG)
    38     unittest.main()