Python/CloseTestPong.py
author morrowa
Thu Jul 02 19:58:11 2009 -0700 (2009-07-02)
changeset 56 6c3b5372a307
parent 51 de59ce19f42e
permissions -rw-r--r--
Removed unnecessary files. Toned down logging. Added null logging handler to BLIP so client code doesn't have to use logging. Modified test drivers to work against Cocoa versions.
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()