Python/CloseTestPong.py
author Jens Alfke <jens@mooseyard.com>
Mon Jul 20 13:26:29 2009 -0700 (2009-07-20)
changeset 59 46c7844cb592
parent 51 de59ce19f42e
permissions -rw-r--r--
* MYBonjourBrowser: Added delegate (no methods for it yet, just for client use.)
* MYBonjourRegistration: Added +canonicalFormOfTXTRecordDictionary:.
* MYBonjourService: Added back-reference to browser.
* IPAddress: Added conversions to/from struct sockaddr.
     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.INFO)
    38     unittest.main()