aboutsummaryrefslogtreecommitdiffstats
path: root/Pubnub.py
diff options
context:
space:
mode:
authorDevendra2014-04-30 17:14:09 +0530
committerDevendra2014-04-30 17:14:09 +0530
commit10f345fcf4edb489cf9b86039c030baa62a6881c (patch)
tree222417d67b02affa861351042e98075eaeeed2ea /Pubnub.py
parente2ccbc05b6ed2696dd8d2d2134b2023c528e1b70 (diff)
downloadpubnub-python-10f345fcf4edb489cf9b86039c030baa62a6881c.tar.bz2
adding persistent connectino support
Diffstat (limited to 'Pubnub.py')
-rw-r--r--Pubnub.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Pubnub.py b/Pubnub.py
index 6c082dc..06a594b 100644
--- a/Pubnub.py
+++ b/Pubnub.py
@@ -46,6 +46,11 @@ try:
except ImportError:
import urllib2
+try:
+ import requests
+except ImportError:
+ pass
+
import threading
from threading import current_thread
@@ -1092,6 +1097,18 @@ def _urllib_request_2(url, timeout=320):
return (resp.read(), resp.code)
+s = requests.Session()
+def _requests_request(url, timeout=320):
+ try:
+ resp = s.get(url)
+ except requests.exceptions.HTTPError as http_error:
+ resp = http_error
+ except requests.exceptions.ConnectionError as error:
+ msg = {"message": str(error.reason)}
+ return (json.dumps(msg), 0)
+
+ return (resp.text, resp.status_code)
+
def _urllib_request_3(url, timeout=320):
try:
@@ -1116,7 +1133,8 @@ class PubnubAsync(PubnubCoreAsync):
auth_key=None,
ssl_on=False,
origin='pubsub.pubnub.com',
- pres_uuid=None
+ pres_uuid=None,
+ pooling=True
):
super(PubnubAsync, self).__init__(
publish_key=publish_key,
@@ -1136,6 +1154,9 @@ class PubnubAsync(PubnubCoreAsync):
else:
_urllib_request = _urllib_request_3
+ if pooling is True:
+ _urllib_request = _requests_request
+
def timeout(self, interval, func):
def cb():
time.sleep(interval)