From 765ee5db6fc39d77e55dcf4fe97fb96da2f46d30 Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 2 Apr 2014 02:44:29 +0530 Subject: multiplexing support --- python-tornado/unassembled/Platform.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index 62d3a26..f98befb 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -42,15 +42,24 @@ class Pubnub(PubnubCoreAsync): self.headers['Accept-Encoding'] = self.accept_encoding self.headers['V'] = self.version self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000) + self.id = None - def _request( self, request, callback ) : + def _request( self, request, callback, single=False ) : url = self.getUrl(request) - ## Send Request Expecting JSON Response - #print self.headers - request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=10, request_timeout=310 ) + if single is True: + id = time.time() + self.id = id def responseCallback(response): + if single is True: + if not id == self.id: + return None + + body = response._get_body() + if body is None: + return + def handle_exc(*args): return True if response.error is not None: @@ -58,9 +67,14 @@ class Pubnub(PubnubCoreAsync): response.rethrow() elif callback: callback(eval(response._get_body())) - + self.http.fetch( - request, - callback=responseCallback, + request=request, + callback=responseCallback ) + def abort(): + pass + + return abort + -- cgit v1.2.3 From 99096b8c11b9a541f6350639e8735495cf90091c Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 11 Apr 2014 14:49:43 +0530 Subject: v1 MX and async code for python, twisted, tornado --- python-tornado/unassembled/Platform.py | 1 + 1 file changed, 1 insertion(+) (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index f98befb..501993e 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -43,6 +43,7 @@ class Pubnub(PubnubCoreAsync): self.headers['V'] = self.version self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000) self.id = None + self._channel_list_lock = None def _request( self, request, callback, single=False ) : url = self.getUrl(request) -- cgit v1.2.3 From 150ae1566d813acbb773839e919db2c0f467931c Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 16 Apr 2014 00:00:40 +0530 Subject: adding code to support async and pam client capabilities with python v2 and v3 --- python-tornado/unassembled/Platform.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index 501993e..5200136 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -43,9 +43,13 @@ class Pubnub(PubnubCoreAsync): self.headers['V'] = self.version self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000) self.id = None - self._channel_list_lock = None + + def _request( self, request, callback=None, error=None, single=False ) : + + def _invoke(func, data): + if func is not None: + func(data) - def _request( self, request, callback, single=False ) : url = self.getUrl(request) request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=10, request_timeout=310 ) if single is True: @@ -56,18 +60,30 @@ class Pubnub(PubnubCoreAsync): if single is True: if not id == self.id: return None - + body = response._get_body() + if body is None: return - + #print(body) def handle_exc(*args): return True if response.error is not None: with ExceptionStackContext(handle_exc): response.rethrow() - elif callback: - callback(eval(response._get_body())) + return + try: + data = json.loads(body) + except TypeError as e: + try: + data = json.loads(body.decode("utf-8")) + except: + _invoke(error, {'error' : 'json decode error'}) + + if 'error' in data and 'status' in data and 'status' != 200: + _invoke(error, data) + else: + _invoke(callback, data) self.http.fetch( request=request, -- cgit v1.2.3 From 4926061ebebbc060d14feac9c9d6b13880205724 Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 22 Apr 2014 23:12:05 +0530 Subject: improvements to dev console --- python-tornado/unassembled/Platform.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index 5200136..02c374d 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -26,6 +26,7 @@ class Pubnub(PubnubCoreAsync): subscribe_key, secret_key = False, cipher_key = False, + auth_key = False, ssl_on = False, origin = 'pubsub.pubnub.com' ) : @@ -34,6 +35,7 @@ class Pubnub(PubnubCoreAsync): subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, + auth_key=auth_key, ssl_on=ssl_on, origin=origin, ) -- cgit v1.2.3 From 09cd0c015ae276aa849297a6a976065b2b3f247b Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 23 Apr 2014 14:03:13 +0530 Subject: modifying code for pep 8 compliance --- python-tornado/unassembled/Platform.py | 47 ++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index 02c374d..871a400 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -13,23 +13,28 @@ from tornado.stack_context import ExceptionStackContext ioloop = tornado.ioloop.IOLoop.instance() + class Pubnub(PubnubCoreAsync): - def stop(self): ioloop.stop() - def start(self): ioloop.start() - def timeout( self, delay, callback): - ioloop.add_timeout( time.time()+float(delay), callback ) - + def stop(self): + ioloop.stop() + + def start(self): + ioloop.start() + + def timeout(self, delay, callback): + ioloop.add_timeout(time.time() + float(delay), callback) + def __init__( self, publish_key, subscribe_key, - secret_key = False, - cipher_key = False, - auth_key = False, - ssl_on = False, - origin = 'pubsub.pubnub.com' - ) : + secret_key=False, + cipher_key=False, + auth_key=False, + ssl_on=False, + origin='pubsub.pubnub.com' + ): super(Pubnub, self).__init__( publish_key=publish_key, subscribe_key=subscribe_key, @@ -38,22 +43,26 @@ class Pubnub(PubnubCoreAsync): auth_key=auth_key, ssl_on=ssl_on, origin=origin, - ) + ) self.headers = {} self.headers['User-Agent'] = 'Python-Tornado' self.headers['Accept-Encoding'] = self.accept_encoding self.headers['V'] = self.version self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000) self.id = None - - def _request( self, request, callback=None, error=None, single=False ) : + + def _request(self, request, callback=None, error=None, single=False): def _invoke(func, data): if func is not None: func(data) url = self.getUrl(request) - request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=10, request_timeout=310 ) + request = tornado.httpclient.HTTPRequest( + url, 'GET', + self.headers, + connect_timeout=10, + request_timeout=310) if single is True: id = time.time() self.id = id @@ -61,13 +70,14 @@ class Pubnub(PubnubCoreAsync): def responseCallback(response): if single is True: if not id == self.id: - return None - + return None + body = response._get_body() if body is None: return #print(body) + def handle_exc(*args): return True if response.error is not None: @@ -80,7 +90,7 @@ class Pubnub(PubnubCoreAsync): try: data = json.loads(body.decode("utf-8")) except: - _invoke(error, {'error' : 'json decode error'}) + _invoke(error, {'error': 'json decode error'}) if 'error' in data and 'status' in data and 'status' != 200: _invoke(error, data) @@ -96,4 +106,3 @@ class Pubnub(PubnubCoreAsync): pass return abort - -- cgit v1.2.3 From f7b89bfafae34fa22509c1d1c59d1284ec62c5df Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 23 Apr 2014 21:35:06 +0530 Subject: exception handling changes --- python-tornado/unassembled/Platform.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index 871a400..b0e0be9 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -51,7 +51,8 @@ class Pubnub(PubnubCoreAsync): self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000) self.id = None - def _request(self, request, callback=None, error=None, single=False): + def _request(self, request, callback=None, error=None, + single=False, read_timeout=5, connect_timeout=5): def _invoke(func, data): if func is not None: @@ -61,8 +62,8 @@ class Pubnub(PubnubCoreAsync): request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, - connect_timeout=10, - request_timeout=310) + connect_timeout=connect_timeout, + request_timeout=read_timeout) if single is True: id = time.time() self.id = id @@ -76,20 +77,23 @@ class Pubnub(PubnubCoreAsync): if body is None: return - #print(body) def handle_exc(*args): return True if response.error is not None: with ExceptionStackContext(handle_exc): - response.rethrow() + if response.code in [403, 401]: + response.rethrow() + else: + _invoke(error, {"message": response.reason}) return + try: data = json.loads(body) except TypeError as e: try: data = json.loads(body.decode("utf-8")) - except: + except ValueError as ve: _invoke(error, {'error': 'json decode error'}) if 'error' in data and 'status' in data and 'status' != 200: -- cgit v1.2.3 From c5d2fb446378e78e9e164dbea969edd57314dc4b Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 00:59:50 +0530 Subject: removing files --- python-tornado/unassembled/Platform.py | 112 --------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 python-tornado/unassembled/Platform.py (limited to 'python-tornado/unassembled/Platform.py') diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py deleted file mode 100644 index b0e0be9..0000000 --- a/python-tornado/unassembled/Platform.py +++ /dev/null @@ -1,112 +0,0 @@ -import tornado.httpclient - -try: - from hashlib import sha256 - digestmod = sha256 -except ImportError: - import Crypto.Hash.SHA256 as digestmod - sha256 = digestmod.new - -import hmac -import tornado.ioloop -from tornado.stack_context import ExceptionStackContext - -ioloop = tornado.ioloop.IOLoop.instance() - - -class Pubnub(PubnubCoreAsync): - - def stop(self): - ioloop.stop() - - def start(self): - ioloop.start() - - def timeout(self, delay, callback): - ioloop.add_timeout(time.time() + float(delay), callback) - - def __init__( - self, - publish_key, - subscribe_key, - secret_key=False, - cipher_key=False, - auth_key=False, - ssl_on=False, - origin='pubsub.pubnub.com' - ): - super(Pubnub, self).__init__( - publish_key=publish_key, - subscribe_key=subscribe_key, - secret_key=secret_key, - cipher_key=cipher_key, - auth_key=auth_key, - ssl_on=ssl_on, - origin=origin, - ) - self.headers = {} - self.headers['User-Agent'] = 'Python-Tornado' - self.headers['Accept-Encoding'] = self.accept_encoding - self.headers['V'] = self.version - self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000) - self.id = None - - def _request(self, request, callback=None, error=None, - single=False, read_timeout=5, connect_timeout=5): - - def _invoke(func, data): - if func is not None: - func(data) - - url = self.getUrl(request) - request = tornado.httpclient.HTTPRequest( - url, 'GET', - self.headers, - connect_timeout=connect_timeout, - request_timeout=read_timeout) - if single is True: - id = time.time() - self.id = id - - def responseCallback(response): - if single is True: - if not id == self.id: - return None - - body = response._get_body() - - if body is None: - return - - def handle_exc(*args): - return True - if response.error is not None: - with ExceptionStackContext(handle_exc): - if response.code in [403, 401]: - response.rethrow() - else: - _invoke(error, {"message": response.reason}) - return - - try: - data = json.loads(body) - except TypeError as e: - try: - data = json.loads(body.decode("utf-8")) - except ValueError as ve: - _invoke(error, {'error': 'json decode error'}) - - if 'error' in data and 'status' in data and 'status' != 200: - _invoke(error, data) - else: - _invoke(callback, data) - - self.http.fetch( - request=request, - callback=responseCallback - ) - - def abort(): - pass - - return abort -- cgit v1.2.3