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.
morrowa@51
     1
# CloseTestPong.py
morrowa@51
     2
# Tests the closing negotiation facilities of the BLIP 1.1 protocol
morrowa@51
     3
morrowa@51
     4
from BLIP import Listener
morrowa@51
     5
morrowa@51
     6
import logging
morrowa@51
     7
import asyncore
morrowa@51
     8
import unittest
morrowa@51
     9
morrowa@51
    10
class CloseTestPong(unittest.TestCase):
morrowa@51
    11
    
morrowa@51
    12
    def shouldClose(self):
morrowa@51
    13
        logging.info("Allowed to close.")
morrowa@51
    14
        return True
morrowa@51
    15
    
morrowa@51
    16
    def handleConnection(self, conn):
morrowa@51
    17
        logging.info("Accepted connection.")
morrowa@51
    18
        conn.onCloseRequest = self.shouldClose
morrowa@51
    19
    
morrowa@51
    20
    def handleRequest(self, req):
morrowa@51
    21
        resp = req.response
morrowa@51
    22
        resp.body = "Pong"
morrowa@51
    23
        resp.send()
morrowa@51
    24
    
morrowa@51
    25
    def testClose(self):
morrowa@51
    26
        listen = Listener(1337)
morrowa@51
    27
        listen.onConnected = self.handleConnection
morrowa@51
    28
        listen.onRequest = self.handleRequest
morrowa@51
    29
        
morrowa@51
    30
        try:
morrowa@51
    31
            asyncore.loop()
morrowa@51
    32
        except KeyboardInterrupt:
morrowa@51
    33
            pass
morrowa@51
    34
morrowa@51
    35
morrowa@51
    36
if __name__ == '__main__':
morrowa@56
    37
    logging.basicConfig(level=logging.INFO)
morrowa@51
    38
    unittest.main()