aboutsummaryrefslogtreecommitdiffstats
path: root/python/examples/pn-test-gae/Pubnub.py
diff options
context:
space:
mode:
authorDevendra2014-04-09 17:57:44 +0530
committerDevendra2014-04-09 17:58:29 +0530
commitbfd5c64bdf7ed45f21207cb53c653e7220e39eff (patch)
tree52cc326a7a3f6c959d220c35ae7a7e39fe8e1fba /python/examples/pn-test-gae/Pubnub.py
parent4b2eedbf98f3d774bc7f1552426955525feb2cd6 (diff)
downloadpubnub-python-bfd5c64bdf7ed45f21207cb53c653e7220e39eff.tar.bz2
added decryption for history and detailedHistory
Diffstat (limited to 'python/examples/pn-test-gae/Pubnub.py')
-rw-r--r--python/examples/pn-test-gae/Pubnub.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/python/examples/pn-test-gae/Pubnub.py b/python/examples/pn-test-gae/Pubnub.py
index 59a38af..73f1832 100644
--- a/python/examples/pn-test-gae/Pubnub.py
+++ b/python/examples/pn-test-gae/Pubnub.py
@@ -172,8 +172,12 @@ class PubnubBase(object):
return message;
def decrypt(self, message):
+
if self.cipher_key:
- message = self.pc.decrypt(self.cipher_key, message)
+ try:
+ message = self.pc.decrypt(self.cipher_key, message)
+ except:
+ pass
return message
@@ -343,14 +347,26 @@ class PubnubBase(object):
else :
callback = None
+ def _history_decryption_wrapper(response):
+ if response is None: return
+ for i,v in enumerate(response):
+ response[i] = self.decrypt(v)
+ if callback is not None:
+ callback(response)
+ else:
+ return response
+
+
## Get History
- return self._request({ "urlcomponents" : [
+ response = self._request({ "urlcomponents" : [
'history',
self.subscribe_key,
channel,
'0',
str(limit)
- ] }, callback);
+ ] }, _history_decryption_wrapper if callback is not None else None );
+
+ return _history_decryption_wrapper(response)
def detailedHistory(self, args) :
"""
@@ -402,15 +418,26 @@ class PubnubBase(object):
else :
callback = None
+ def _history_decryption_wrapper(response):
+ if response is None: return
+ for i,v in enumerate(response[0]):
+ response[0][i] = self.decrypt(v)
+ if callback is not None:
+ callback(response)
+ else:
+ return response
+
## Get History
- return self._request({ 'urlcomponents' : [
+ response = self._request({ 'urlcomponents' : [
'v2',
'history',
'sub-key',
self.subscribe_key,
'channel',
channel,
- ],'urlparams' : params }, callback=callback);
+ ],'urlparams' : params }, callback=_history_decryption_wrapper if callback is not None else None);
+
+ return _history_decryption_wrapper(response)
def time(self, args = None) :
"""