aboutsummaryrefslogtreecommitdiffstats
path: root/python-tornado/unassembled/Platform.py
diff options
context:
space:
mode:
Diffstat (limited to 'python-tornado/unassembled/Platform.py')
-rw-r--r--python-tornado/unassembled/Platform.py28
1 files changed, 22 insertions, 6 deletions
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,