aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/PubnubCoreAsync.py2
-rw-r--r--python-tornado/Pubnub.py15
-rw-r--r--python-tornado/examples/here-now-example.py6
-rw-r--r--python-tornado/unassembled/Platform.py13
-rw-r--r--python-twisted/Pubnub.py2
-rw-r--r--python/Pubnub.py12
-rw-r--r--python/examples/here-now-example.py8
-rw-r--r--python/unassembled/Platform.py12
8 files changed, 49 insertions, 21 deletions
diff --git a/common/PubnubCoreAsync.py b/common/PubnubCoreAsync.py
index e844b96..a7fbb7d 100644
--- a/common/PubnubCoreAsync.py
+++ b/common/PubnubCoreAsync.py
@@ -52,7 +52,7 @@ class PubnubCoreAsync(PubnubBase):
self.subscriptions = {}
self.timetoken = 0
- self.version = '3.4'
+ self.version = '3.3.4'
self.accept_encoding = 'gzip'
def subscribe( self, args ) :
diff --git a/python-tornado/Pubnub.py b/python-tornado/Pubnub.py
index 8f94000..a65b2b3 100644
--- a/python-tornado/Pubnub.py
+++ b/python-tornado/Pubnub.py
@@ -541,7 +541,7 @@ class PubnubCoreAsync(PubnubBase):
self.subscriptions = {}
self.timetoken = 0
- self.version = '3.4'
+ self.version = '3.3.4'
self.accept_encoding = 'gzip'
def subscribe( self, args ) :
@@ -680,6 +680,7 @@ except ImportError:
import hmac
import tornado.ioloop
+from tornado.stack_context import ExceptionStackContext
from PubnubCrypto import PubnubCrypto
ioloop = tornado.ioloop.IOLoop.instance()
@@ -718,9 +719,17 @@ class Pubnub(PubnubCoreAsync):
url = self.getUrl(request)
## Send Request Expecting JSON Response
#print self.headers
- request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=310, request_timeout=310 )
+
+ request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=10, request_timeout=310 )
+
def responseCallback(response):
- callback(eval(response._get_body()))
+ def handle_exc(*args):
+ return True
+ if response.error is not None:
+ with ExceptionStackContext(handle_exc):
+ response.rethrow()
+ else:
+ callback(eval(response._get_body()))
self.http.fetch(
request,
diff --git a/python-tornado/examples/here-now-example.py b/python-tornado/examples/here-now-example.py
index 4105776..85e3432 100644
--- a/python-tornado/examples/here-now-example.py
+++ b/python-tornado/examples/here-now-example.py
@@ -11,6 +11,8 @@
import sys
import tornado
+sys.path.append('..')
+sys.path.append('../../common')
from Pubnub import Pubnub
publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
@@ -30,7 +32,7 @@ crazy = 'hello_world'
## -----------------------------------------------------------------------
def here_now_complete(messages):
print(messages)
- tornado.ioloop.IOLoop.instance().stop()
+ pubnub.stop()
pubnub.here_now( {
'channel' : crazy,
@@ -40,4 +42,4 @@ pubnub.here_now( {
## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
-tornado.ioloop.IOLoop.instance().start()
+pubnub.start()
diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py
index 618927e..4df04b3 100644
--- a/python-tornado/unassembled/Platform.py
+++ b/python-tornado/unassembled/Platform.py
@@ -9,6 +9,7 @@ except ImportError:
import hmac
import tornado.ioloop
+from tornado.stack_context import ExceptionStackContext
from PubnubCrypto import PubnubCrypto
ioloop = tornado.ioloop.IOLoop.instance()
@@ -47,9 +48,17 @@ class Pubnub(PubnubCoreAsync):
url = self.getUrl(request)
## Send Request Expecting JSON Response
#print self.headers
- request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=310, request_timeout=310 )
+
+ request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=10, request_timeout=310 )
+
def responseCallback(response):
- callback(eval(response._get_body()))
+ def handle_exc(*args):
+ return True
+ if response.error is not None:
+ with ExceptionStackContext(handle_exc):
+ response.rethrow()
+ else:
+ callback(eval(response._get_body()))
self.http.fetch(
request,
diff --git a/python-twisted/Pubnub.py b/python-twisted/Pubnub.py
index 9a89aee..283e121 100644
--- a/python-twisted/Pubnub.py
+++ b/python-twisted/Pubnub.py
@@ -541,7 +541,7 @@ class PubnubCoreAsync(PubnubBase):
self.subscriptions = {}
self.timetoken = 0
- self.version = '3.4'
+ self.version = '3.3.4'
self.accept_encoding = 'gzip'
def subscribe( self, args ) :
diff --git a/python/Pubnub.py b/python/Pubnub.py
index 2eb0440..b1d1777 100644
--- a/python/Pubnub.py
+++ b/python/Pubnub.py
@@ -632,13 +632,15 @@ class Pubnub(PubnubCore):
## Send Request Expecting JSONP Response
try:
- try: usock = urllib2.urlopen( url, None, 200 )
+ try: usock = urllib2.urlopen( url, None, 310 )
except TypeError: usock = urllib2.urlopen( url, None )
response = usock.read()
usock.close()
- if (callback):
- callback(json.loads(response))
- else:
- return json.loads( response )
+ resp_json = json.loads(response)
except:
return None
+
+ if (callback):
+ callback(resp_json)
+ else:
+ return resp_json
diff --git a/python/examples/here-now-example.py b/python/examples/here-now-example.py
index 261500a..d2ca9bd 100644
--- a/python/examples/here-now-example.py
+++ b/python/examples/here-now-example.py
@@ -10,6 +10,7 @@
## -----------------------------------
import sys
+sys.path.append('../')
from twisted.internet import reactor
from Pubnub import Pubnub
@@ -26,8 +27,11 @@ pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
crazy = 'hello_world'
+def print_cb(message):
+ print message
-print pubnub.here_now( {
- 'channel' : crazy
+pubnub.here_now( {
+ 'channel' : crazy,
+ 'callback' : print_cb
})
diff --git a/python/unassembled/Platform.py b/python/unassembled/Platform.py
index ef69473..f598a98 100644
--- a/python/unassembled/Platform.py
+++ b/python/unassembled/Platform.py
@@ -26,13 +26,15 @@ class Pubnub(PubnubCore):
## Send Request Expecting JSONP Response
try:
- try: usock = urllib2.urlopen( url, None, 200 )
+ try: usock = urllib2.urlopen( url, None, 310 )
except TypeError: usock = urllib2.urlopen( url, None )
response = usock.read()
usock.close()
- if (callback):
- callback(json.loads(response))
- else:
- return json.loads( response )
+ resp_json = json.loads(response)
except:
return None
+
+ if (callback):
+ callback(resp_json)
+ else:
+ return resp_json