Python implementation much improved. Can send requests now. Fully interoperable with Obj-C implementation's test cases.
6 Created by Jens Alfke on 2008-06-04.
7 This source file is test/example code, and is in the public domain.
10 from BLIP import Connection, OutgoingRequest, kOpening
13 from cStringIO import StringIO
14 from datetime import datetime
23 return random.randint(0,1) == 1
26 class BLIPConnectionTest(unittest.TestCase):
29 self.connection = Connection( ('localhost',46353) )
31 def sendRequest(self):
32 size = random.randint(0,32767)
34 for i in xrange(0,size):
35 io.write( chr(i % 256) )
39 req = OutgoingRequest(self.connection, body,{'Content-Type': 'application/octet-stream',
40 'User-Agent': 'PyBLIP',
41 'Date': datetime.now(),
43 req.compressed = randbool()
44 req.urgent = randbool()
45 req.response.onComplete = self.gotResponse
48 def gotResponse(self, response):
49 logging.info("Got response!: %s",response)
50 request = response.request
51 assert response.body == request.body
57 asyncore.loop(timeout=kSendInterval,count=1)
60 if self.connection.status!=kOpening and not lastReqTime or (now-lastReqTime).seconds >= kSendInterval:
62 if not self.sendRequest():
63 logging.warn("Couldn't send request (connection is probably closed)")
68 self.connection.close()
70 if __name__ == '__main__':
71 logging.basicConfig(level=logging.INFO)