aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevendra2014-04-09 17:57:44 +0530
committerDevendra2014-04-09 17:58:29 +0530
commitbfd5c64bdf7ed45f21207cb53c653e7220e39eff (patch)
tree52cc326a7a3f6c959d220c35ae7a7e39fe8e1fba
parent4b2eedbf98f3d774bc7f1552426955525feb2cd6 (diff)
downloadpubnub-python-bfd5c64bdf7ed45f21207cb53c653e7220e39eff.tar.bz2
added decryption for history and detailedHistory
-rw-r--r--python/examples/pn-test-gae/Pubnub.py37
-rw-r--r--python/examples/pn-test-gae/main.py34
2 files changed, 62 insertions, 9 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) :
"""
diff --git a/python/examples/pn-test-gae/main.py b/python/examples/pn-test-gae/main.py
index b3d2088..6476cb8 100644
--- a/python/examples/pn-test-gae/main.py
+++ b/python/examples/pn-test-gae/main.py
@@ -15,21 +15,47 @@
# limitations under the License.
#
import webapp2
-
+import time
from Pubnub import Pubnub
-pubnub = Pubnub( publish_key='demo', subscribe_key='demo', cipher_key='enigma', ssl_on=False )
+pubnub = Pubnub( publish_key='demo', subscribe_key='demo', ssl_on=False )
+pubnub_enc = Pubnub( publish_key='demo', subscribe_key='demo', cipher_key='enigma', ssl_on=False )
+channel = 'gae-test-channel-' + str(time.time())
class MainHandler(webapp2.RequestHandler):
def get(self):
info = pubnub.publish({
- 'channel' : 'hello_world',
+ 'channel' : channel,
+ 'message' : {
+ 'some_text' : 'Hello my World'
+ }
+ })
+ info_enc = pubnub_enc.publish({
+ 'channel' : channel,
'message' : {
'some_text' : 'Hello my World'
}
})
- self.response.write(info)
+ hn = pubnub.here_now({
+ 'channel' : channel
+ })
+ history = pubnub.detailedHistory({
+ 'channel' : channel
+ })
+ history_enc = pubnub_enc.detailedHistory({
+ 'channel' : channel
+ })
+ self.response.write('Message published to channel ' + channel + '<br>' + str(info))
+ self.response.write('<br><br>')
+ self.response.write('Encrypted message published to channel ' + channel + '<br>' + str(info_enc))
+ self.response.write('<br><br>')
+ self.response.write('Here now data for channel : '+ channel + '<br>' + str(hn))
+ self.response.write('<br><br>')
+ self.response.write('History for channel : '+ channel + '<br>' + str(history))
+ self.response.write('<br><br>')
+ self.response.write('History with decryption enabled for channel : '+ channel + '<br>' + str(history_enc))
+
app = webapp2.WSGIApplication([
('/', MainHandler)