diff options
| author | Devendra | 2014-04-02 02:44:29 +0530 |
|---|---|---|
| committer | Devendra | 2014-04-02 02:44:29 +0530 |
| commit | 765ee5db6fc39d77e55dcf4fe97fb96da2f46d30 (patch) | |
| tree | ec6e9e2d102e866ae1b54a43d805607f0c62b8c2 /python-twisted/unassembled/Platform.py | |
| parent | 9ac3ccf6283772b404a0c80945e3cdf3406ac5bf (diff) | |
| download | pubnub-python-765ee5db6fc39d77e55dcf4fe97fb96da2f46d30.tar.bz2 | |
multiplexing support
Diffstat (limited to 'python-twisted/unassembled/Platform.py')
| -rw-r--r-- | python-twisted/unassembled/Platform.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/python-twisted/unassembled/Platform.py b/python-twisted/unassembled/Platform.py index 7318703..3b84b30 100644 --- a/python-twisted/unassembled/Platform.py +++ b/python-twisted/unassembled/Platform.py @@ -7,10 +7,14 @@ from twisted.web.client import HTTPConnectionPool from twisted.web.http_headers import Headers from twisted.internet.ssl import ClientContextFactory from twisted.internet.task import LoopingCall +import twisted +from hashlib import sha256 +import time pnconn_pool = HTTPConnectionPool(reactor, persistent=True) -pnconn_pool.maxPersistentPerHost = 100 +pnconn_pool.maxPersistentPerHost = 100000 pnconn_pool.cachedConnectionTimeout = 310 +pnconn_pool.retryAutomatically = True class Pubnub(PubnubCoreAsync): @@ -41,7 +45,7 @@ class Pubnub(PubnubCoreAsync): #self.headers['Accept-Encoding'] = [self.accept_encoding] self.headers['V'] = [self.version] - def _request( self, request, callback ) : + def _request( self, request, callback, single=False ) : global pnconn_pool ## Build URL @@ -53,24 +57,42 @@ class Pubnub(PubnubCoreAsync): ]) for bit in request]) ''' url = self.getUrl(request) + agent = ContentDecoderAgent(RedirectAgent(Agent( reactor, contextFactory = WebClientContextFactory(), pool = self.ssl and None or pnconn_pool )), [('gzip', GzipDecoder)]) + request = agent.request( 'GET', url, Headers(self.headers), None ) + if single is True: + id = time.time() + self.id = id + def received(response): finished = Deferred() response.deliverBody(PubNubResponse(finished)) return finished def complete(data): - callback(eval(data)) + if single is True: + if not id == self.id: + return None + try: + callback(eval(data)) + except Exception as e: + pass + #need error handling here + + def abort(): + pass request.addCallback(received) request.addBoth(complete) + return abort + class WebClientContextFactory(ClientContextFactory): def getContext(self, hostname, port): return ClientContextFactory.getContext(self) |
