aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Pubnub.py41
-rw-r--r--python/examples/console.py16
2 files changed, 30 insertions, 27 deletions
diff --git a/Pubnub.py b/Pubnub.py
index 62a401d..cefe50b 100644
--- a/Pubnub.py
+++ b/Pubnub.py
@@ -22,6 +22,7 @@ import hashlib
import uuid
import sys
from base64 import urlsafe_b64encode
+from base64 import encodestring, decodestring
import hmac
from Crypto.Cipher import AES
from Crypto.Hash import MD5
@@ -85,6 +86,26 @@ try:
pnconn_pool.maxPersistentPerHost = 100000
pnconn_pool.cachedConnectionTimeout = 15
pnconn_pool.retryAutomatically = True
+
+ class WebClientContextFactory(ClientContextFactory):
+ def getContext(self, hostname, port):
+ return ClientContextFactory.getContext(self)
+
+
+ class PubNubPamResponse(Protocol):
+ def __init__(self, finished):
+ self.finished = finished
+
+ def dataReceived(self, bytes):
+ self.finished.callback(bytes)
+
+
+ class PubNubResponse(Protocol):
+ def __init__(self, finished):
+ self.finished = finished
+
+ def dataReceived(self, bytes):
+ self.finished.callback(bytes)
except ImportError:
pass
@@ -1297,26 +1318,6 @@ class PubnubTwisted(PubnubCoreAsync):
return abort
-class WebClientContextFactory(ClientContextFactory):
- def getContext(self, hostname, port):
- return ClientContextFactory.getContext(self)
-
-
-class PubNubPamResponse(Protocol):
- def __init__(self, finished):
- self.finished = finished
-
- def dataReceived(self, bytes):
- self.finished.callback(bytes)
-
-
-class PubNubResponse(Protocol):
- def __init__(self, finished):
- self.finished = finished
-
- def dataReceived(self, bytes):
- self.finished.callback(bytes)
-
# PubnubTornado
class PubnubTornado(PubnubCoreAsync):
diff --git a/python/examples/console.py b/python/examples/console.py
index 4dfd891..aa6fff3 100644
--- a/python/examples/console.py
+++ b/python/examples/console.py
@@ -12,7 +12,7 @@ from datetime import datetime
from cmd2 import Cmd, make_option, options, Cmd2TestCase
import optparse
-
+import json
of=sys.stdout
@@ -246,8 +246,7 @@ class DevConsole(Cmd):
_history_command_handler(opts.channel, opts.count)
- @options([make_option('-c', '--channel', action="store", help="Channel on which to publish"),
- make_option('-m', '--message', action="store", help="Message to be published")
+ @options([make_option('-c', '--channel', action="store", help="Channel on which to publish")
])
def do_publish(self, command, opts):
opts.channel = self.default_channel if opts.channel is None else opts.channel
@@ -255,11 +254,16 @@ class DevConsole(Cmd):
print_error("Missing channel")
return
- if opts.message is None:
+ if command is None:
print_error("Missing message")
return
- _publish_command_handler(opts.channel,opts.message)
+ try:
+ message = json.loads(str(command))
+ except ValueError as ve:
+ message = str(command)
+
+ _publish_command_handler(opts.channel,message)
@options([make_option('-c', '--channel', action="store", help="Channel on which to grant"),
make_option('-a', '--auth-key', dest="auth_key", action="store",
@@ -327,8 +331,6 @@ class DevConsole(Cmd):
_subscribe_command_handler(opts.channel)
-
-
def main():
app = DevConsole()
app.cmdloop()