diff options
| author | Devendra | 2014-06-15 10:23:16 +0530 |
|---|---|---|
| committer | Devendra | 2014-06-15 10:23:16 +0530 |
| commit | 75033e11a429b52b0366d63bdd8f81b795a7145d (patch) | |
| tree | 7e7871fd7256c6fa9c835c996c0cee113a4eae6a | |
| parent | 646fdda7abbd997925e83a497ed70ca27fb64654 (diff) | |
| download | pubnub-python-75033e11a429b52b0366d63bdd8f81b795a7145d.tar.bz2 | |
fixing customer issue, making changes to dev console to print pretty
| -rw-r--r-- | Pubnub.py | 2 | ||||
| -rw-r--r-- | dist/pubnub-3.5.0-beta.tar.gz | bin | 9451 -> 0 bytes | |||
| -rw-r--r-- | python/examples/console.py | 111 | ||||
| -rw-r--r-- | python/examples/pubnub-console/dist/pubnub-console-3.5.0-beta.tar.gz | bin | 4647 -> 0 bytes | |||
| -rw-r--r-- | python/examples/pubnub-console/setup.py | 5 | ||||
| -rw-r--r-- | setup.py | 4 |
6 files changed, 100 insertions, 22 deletions
@@ -1406,7 +1406,7 @@ class Pubnub(PubnubCoreAsync): except ValueError: return [0, "JSON Error"] - if response[1] != 200 and 'status' in resp_json: + if response[1] != 200 and 'message' in resp_json and 'payload' in resp_json: return {'message': resp_json['message'], 'payload': resp_json['payload']} diff --git a/dist/pubnub-3.5.0-beta.tar.gz b/dist/pubnub-3.5.0-beta.tar.gz Binary files differdeleted file mode 100644 index 3ed2de3..0000000 --- a/dist/pubnub-3.5.0-beta.tar.gz +++ /dev/null diff --git a/python/examples/console.py b/python/examples/console.py index f67e168..bf82b5f 100644 --- a/python/examples/console.py +++ b/python/examples/console.py @@ -20,6 +20,17 @@ import os import readline import rlcompleter +import pygments +from pygments.lexers import JsonLexer +from pygments.formatters import TerminalFormatter + +lexer = JsonLexer() +formatter = TerminalFormatter() +def highlight(msg): + return pygments.highlight(msg, lexer, formatter) + + + historyPath = os.path.expanduser("~/.pubnub_console_history") @@ -79,8 +90,7 @@ def get_date(): return color.colorize(datetime.now().strftime( '%H:%M:%S'), "magenta") - -def print_ok(msg, channel=None): +def print_ok_normal(msg, channel=None): if msg is None: return chstr = color.colorize("[" + get_date() + "] ", "magenta") @@ -90,10 +100,11 @@ def print_ok(msg, channel=None): print_console(of, (chstr + color.colorize(str(msg), "green"))) except UnicodeEncodeError as e: print_console(of, (msg)) + of.flush() -def print_error(msg, channel=None): +def print_error_normal(msg, channel=None): if msg is None: return chstr = color.colorize("[" + get_date() + "] ", "magenta") @@ -106,6 +117,37 @@ def print_error(msg, channel=None): print_console(of, (msg)) of.flush() +def print_ok_pretty(msg, channel=None): + if msg is None: + return + chstr = color.colorize("[" + get_date() + "] ", "magenta") + chstr += color.colorize("[Channel : " + channel + + "] " if channel is not None else "", "cyan") + try: + print_console(of, (chstr + highlight(json.dumps(msg, indent=2)))) + except UnicodeEncodeError as e: + print_console(of, (msg)) + + of.flush() + + +def print_error_pretty(msg, channel=None): + if msg is None: + return + chstr = color.colorize("[" + get_date() + "] ", "magenta") + chstr += color.colorize("[Channel : " + channel + + "] " if channel is not None else "", "cyan") + try: + print_console(of, (chstr + color.colorize(color.colorize( + "ERROR: ", "red"), "bold") + + highlight(json.dumps(msg, indent=2)))) + except UnicodeEncodeError as e: + print_console(of, (msg)) + of.flush() + +print_ok = print_ok_pretty +print_error = print_error_pretty + class DefaultPubnub(object): def handlerFunctionClosure(self, name): @@ -295,6 +337,15 @@ class DevConsole(Cmd): pubnub = Pubnub("demo", "demo") self.channel_truncation = 3 self.prompt = self.get_prompt() + self.publish_key = "demo" + self.subscribe_key = "demo" + self.origin = "pubsub.pubnub.com" + self.auth_key = None + self.cipher_key = None + self.secret_key = "demo" + self.ssl = False + self.uuid = None + self.disable_pretty = False def get_channel_origin(self): cho = " [" @@ -341,34 +392,60 @@ class DevConsole(Cmd): kill_all_threads() @options([make_option('-p', '--publish-key', action="store", - default="demo", help="Publish Key"), + default=None, help="Publish Key"), make_option('-s', '--subscribe-key', action="store", - default="demo", help="Subscribe Key"), + default=None, help="Subscribe Key"), make_option('-k', '--secret-key', action="store", - default="demo", help="cipher Key"), + default=None, help="cipher Key"), make_option('-c', '--cipher-key', action="store", - default="", help="Secret Key"), + default=None, help="Secret Key"), make_option('-a', '--auth-key', action="store", default=None, help="Auth Key"), make_option('--ssl-on', dest='ssl', action='store_true', default=False, help="SSL Enabled ?"), make_option('-o', '--origin', action="store", - default="pubsub.pubnub.com", help="Origin"), + default=None, help="Origin"), make_option('-u', '--uuid', action="store", - default=None, help="UUID") + default=None, help="UUID"), + make_option('--disable-pretty-print', dest='disable_pretty', action='store_true', + default=False, help="Disable Pretty Print ?") ]) def do_init(self, command, opts): global pubnub - pubnub = Pubnub(opts.publish_key, - opts.subscribe_key, - opts.secret_key, - opts.cipher_key, - opts.auth_key, - opts.ssl, - opts.origin, - opts.uuid) + global print_ok + global print_error + global print_ok_normal + global print_error_normal + global print_error_pretty + global print_ok_pretty + + self.publish_key = opts.publish_key if opts.publish_key is not None else self.publish_key + self.subscribe_key = opts.subscribe_key if opts.subscribe_key is not None else self.subscribe_key + self.secret_key = opts.secret_key if opts.secret_key is not None else self.secret_key + self.cipher_key = opts.cipher_key if opts.cipher_key is not None else self.cipher_key + self.auth_key = opts.auth_key if opts.auth_key is not None else self.auth_key + self.origin = opts.origin if opts.origin is not None else self.origin + self.uuid = opts.uuid if opts.uuid is not None else self.uuid + self.ssl = opts.ssl if opts.ssl is not None else self.ssl + self.disable_pretty = opts.disable_pretty if opts.disable_pretty is not None else self.disable_pretty + + pubnub = Pubnub(self.publish_key, + self.subscribe_key, + self.secret_key, + self.cipher_key, + self.auth_key, + self.ssl, + self.origin, + self.uuid) self.prompt = self.get_prompt() + if opts.disable_pretty is True: + print_ok = print_ok_normal + print_error = print_error_normal + else: + print_ok = print_ok_pretty + print_error = print_error_pretty + def do_set_sync(self, command): """unset_async Unset Async mode""" diff --git a/python/examples/pubnub-console/dist/pubnub-console-3.5.0-beta.tar.gz b/python/examples/pubnub-console/dist/pubnub-console-3.5.0-beta.tar.gz Binary files differdeleted file mode 100644 index 278e9fa..0000000 --- a/python/examples/pubnub-console/dist/pubnub-console-3.5.0-beta.tar.gz +++ /dev/null diff --git a/python/examples/pubnub-console/setup.py b/python/examples/pubnub-console/setup.py index d46314e..e5a06ad 100644 --- a/python/examples/pubnub-console/setup.py +++ b/python/examples/pubnub-console/setup.py @@ -2,11 +2,11 @@ from setuptools import setup, find_packages setup( name='pubnub-console', - version='3.5.0-beta', + version='3.5.0-beta-1', description='PubNub Developer Console', author='Stephen Blum', author_email='support@pubnub.com', - url='https://github.com/pubnub/python/raw/async/python/examples/pubnub-console/dist/pubnub-console-3.5.0-beta.tar.gz', + url='http://pubnub.com', scripts=['pubnub-console'], license='MIT', classifiers=( @@ -21,6 +21,7 @@ setup( install_requires=[ 'pubnub==3.5.0-beta', 'cmd2>=0.6.7', + 'pygments >= 1.6' ], zip_safe=False, ) @@ -2,11 +2,11 @@ from setuptools import setup, find_packages setup( name='pubnub', - version='3.5.0-beta', + version='3.5.0-beta-1', description='PubNub Real-time push service in the cloud', author='Stephen Blum', author_email='support@pubnub.com', - url='https://github.com/pubnub/python/raw/async/dist/pubnub-3.5.0-beta.tar.gz', + url='http://pubnub.com', py_modules=['Pubnub'], license='MIT', classifiers=( |
