aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Pubnub.py17
-rw-r--r--python-tornado/examples/history.py5
-rw-r--r--python-tornado/examples/publish.py5
-rw-r--r--python-tornado/examples/subscribe.py11
-rw-r--r--python-twisted/examples/history.py5
-rw-r--r--python-twisted/examples/publish.py5
-rw-r--r--python-twisted/examples/subscribe.py11
-rw-r--r--python/examples/console.py38
-rw-r--r--python/examples/here-now.py3
-rw-r--r--python/examples/history.py5
-rw-r--r--python/examples/publish.py7
-rw-r--r--python/examples/subscribe.py11
12 files changed, 69 insertions, 54 deletions
diff --git a/Pubnub.py b/Pubnub.py
index a759f75..9cd33af 100644
--- a/Pubnub.py
+++ b/Pubnub.py
@@ -1,5 +1,5 @@
-## www.pubnub.com - PubNub Real-time push service in the cloud.
+## www.pubnub.com - PubNub Real-time push service in the cloud.
# coding=utf8
## PubNub Real-time Push APIs and Notifications Framework
@@ -11,7 +11,6 @@
## -----------------------------------
-
try:
import json
except ImportError:
@@ -96,7 +95,6 @@ try:
def getContext(self, hostname, port):
return ClientContextFactory.getContext(self)
-
class PubNubPamResponse(Protocol):
def __init__(self, finished):
self.finished = finished
@@ -104,7 +102,6 @@ try:
def dataReceived(self, bytes):
self.finished.callback(bytes)
-
class PubNubResponse(Protocol):
def __init__(self, finished):
self.finished = finished
@@ -760,10 +757,10 @@ class PubnubCoreAsync(PubnubBase):
def _invoke(func, msg=None, channel=None):
if func is not None:
if msg is not None and channel is not None:
- func(msg,channel)
+ func(msg, channel)
elif msg is not None:
func(msg)
- else :
+ else:
func()
def _invoke_connect():
@@ -779,7 +776,7 @@ class PubnubCoreAsync(PubnubBase):
if chobj['disconnected'] is True:
chobj['disconnected'] = False
_invoke(chobj['reconnect'], chobj['name'])
-
+
def _invoke_disconnect():
if self._channel_list_lock:
with self._channel_list_lock:
@@ -805,7 +802,8 @@ class PubnubCoreAsync(PubnubBase):
chobj = self.subscriptions[ch]
if chobj['subscribed'] is True:
return chobj
- channels = channels if isinstance(channels,list) else channels.split(",")
+ channels = channels if isinstance(
+ channels, list) else channels.split(",")
for channel in channels:
## New Channel?
if not channel in self.subscriptions or \
@@ -1125,6 +1123,8 @@ 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, timeout=timeout)
@@ -1370,7 +1370,6 @@ class PubnubTwisted(PubnubCoreAsync):
return abort
-
# PubnubTornado
class PubnubTornado(PubnubCoreAsync):
diff --git a/python-tornado/examples/history.py b/python-tornado/examples/history.py
index da3d6a5..daf1c6e 100644
--- a/python-tornado/examples/history.py
+++ b/python-tornado/examples/history.py
@@ -20,13 +20,14 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'a'
+channel = 'a'
# Asynchronous usage
+
def callback(message):
print(message)
-pubnub.history(channel, count=2 , callback=callback, error=callback)
+pubnub.history(channel, count=2, callback=callback, error=callback)
pubnub.start()
diff --git a/python-tornado/examples/publish.py b/python-tornado/examples/publish.py
index 4e662fd..04e88fd 100644
--- a/python-tornado/examples/publish.py
+++ b/python-tornado/examples/publish.py
@@ -20,11 +20,12 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'hello_world'
-message = 'Hello World !!!'
+channel = 'hello_world'
+message = 'Hello World !!!'
# Asynchronous usage
+
def callback(message):
print(message)
diff --git a/python-tornado/examples/subscribe.py b/python-tornado/examples/subscribe.py
index 9288836..72f0fc1 100644
--- a/python-tornado/examples/subscribe.py
+++ b/python-tornado/examples/subscribe.py
@@ -21,28 +21,31 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'a'
-
+channel = 'a'
# Asynchronous usage
-
def callback(message, channel):
print(message)
+
def error(message):
print("ERROR : " + str(message))
+
def connect(message):
print("CONNECTED")
+
def reconnect(message):
print("RECONNECTED")
+
def disconnect(message):
print("DISCONNECTED")
-pubnub.subscribe(channel, callback=callback, error=callback, connect=connect, reconnect=reconnect, disconnect=disconnect)
+pubnub.subscribe(channel, callback=callback, error=callback,
+ connect=connect, reconnect=reconnect, disconnect=disconnect)
pubnub.start()
diff --git a/python-twisted/examples/history.py b/python-twisted/examples/history.py
index 10e86b3..81974ec 100644
--- a/python-twisted/examples/history.py
+++ b/python-twisted/examples/history.py
@@ -20,13 +20,14 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'a'
+channel = 'a'
# Asynchronous usage
+
def callback(message):
print(message)
-pubnub.history(channel, count=2 , callback=callback, error=callback)
+pubnub.history(channel, count=2, callback=callback, error=callback)
pubnub.start()
diff --git a/python-twisted/examples/publish.py b/python-twisted/examples/publish.py
index f7b746f..13b5357 100644
--- a/python-twisted/examples/publish.py
+++ b/python-twisted/examples/publish.py
@@ -20,11 +20,12 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'hello_world'
-message = 'Hello World !!!'
+channel = 'hello_world'
+message = 'Hello World !!!'
# Asynchronous usage
+
def callback(message):
print(message)
diff --git a/python-twisted/examples/subscribe.py b/python-twisted/examples/subscribe.py
index 1462a69..9c73439 100644
--- a/python-twisted/examples/subscribe.py
+++ b/python-twisted/examples/subscribe.py
@@ -21,28 +21,31 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'a'
-
+channel = 'a'
# Asynchronous usage
-
def callback(message, channel):
print(message)
+
def error(message):
print("ERROR : " + str(message))
+
def connect(message):
print("CONNECTED")
+
def reconnect(message):
print("RECONNECTED")
+
def disconnect(message):
print("DISCONNECTED")
-pubnub.subscribe(channel, callback=callback, error=callback, connect=connect, reconnect=reconnect, disconnect=disconnect)
+pubnub.subscribe(channel, callback=callback, error=callback,
+ connect=connect, reconnect=reconnect, disconnect=disconnect)
pubnub.start()
diff --git a/python/examples/console.py b/python/examples/console.py
index 084c49a..342c70f 100644
--- a/python/examples/console.py
+++ b/python/examples/console.py
@@ -37,12 +37,16 @@ color = Cmd()
stop = None
+full_date = False
+
def stop_2(th):
th._Thread__stop()
def stop_3(th):
th._stop()
+
+
def print_console_2(of,message):
print >>of, message
@@ -63,11 +67,20 @@ else:
print_console = print_console_3
stop = stop_3
+
+def get_date():
+ if full_date is True:
+ return color.colorize(datetime.now().strftime(
+ '%Y-%m-%d %H:%M:%S'), "magenta")
+ else:
+ return color.colorize(datetime.now().strftime(
+ '%H:%M:%S'), "magenta")
+
+
def print_ok(msg, channel=None):
if msg is None:
return
- chstr = color.colorize("[" + datetime.now().strftime(
- '%Y-%m-%d %H:%M:%S') + "] ","magenta")
+ chstr = color.colorize("[" + get_date() + "] ","magenta")
chstr += color.colorize("[Channel : " + channel + \
"] " if channel is not None else "", "cyan")
try:
@@ -79,8 +92,7 @@ def print_ok(msg, channel=None):
def print_error(msg, channel=None):
if msg is None:
return
- chstr = color.colorize("[" + datetime.now().strftime(
- '%Y-%m-%d %H:%M:%S') + "] ", "magenta")
+ chstr = color.colorize("[" + get_date() + "] ", "magenta")
chstr += color.colorize("[Channel : " + channel + \
"] " if channel is not None else "", "cyan")
try:
@@ -237,15 +249,6 @@ def kill_all_threads():
stop(thread)
-def get_date(full=False):
- if full is True:
- return color.colorize("[" + datetime.now().strftime(
- '%Y-%m-%d %H:%M:%S') + "] ", "magenta")
- else:
- return color.colorize("[" + datetime.now().strftime(
- '%H:%M:%S') + "] ", "magenta")
-
-
class DevConsole(Cmd):
def __init__(self):
@@ -255,7 +258,6 @@ class DevConsole(Cmd):
self.default_channel = None
self.async = False
pubnub = Pubnub("demo", "demo")
- self.full_date = False
self.channel_truncation = 3
self.prompt = self.get_prompt()
@@ -279,7 +281,7 @@ class DevConsole(Cmd):
def get_prompt(self):
- prompt = get_date(self.full_date)
+ prompt = "[" + get_date() + "]"
if self.default_channel is not None and len(self.default_channel) > 0:
prompt += " [default channel: " + color.colorize(self.default_channel,"bold") + "]"
@@ -352,15 +354,17 @@ class DevConsole(Cmd):
self.prompt = self.get_prompt()
def do_set_full_date(self, command):
+ global full_date
"""do_set_full_date
Set Full Date"""
- self.full_date = True
+ full_date = True
self.prompt = self.get_prompt()
def do_unset_full_date(self, command):
+ global full_date
"""do_unset_full_date
Unset Full Date"""
- self.full_date = False
+ full_date = False
self.prompt = self.get_prompt()
@options([make_option('-c', '--channel', action="store", help="Default Channel")
diff --git a/python/examples/here-now.py b/python/examples/here-now.py
index f573389..d03a110 100644
--- a/python/examples/here-now.py
+++ b/python/examples/here-now.py
@@ -23,13 +23,12 @@ pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
channel = 'hello_world'
-
# Synchronous usage
-
print pubnub.here_now(channel)
# Asynchronous usage
+
def callback(message):
print(message)
diff --git a/python/examples/history.py b/python/examples/history.py
index 3d6addf..7f7466b 100644
--- a/python/examples/history.py
+++ b/python/examples/history.py
@@ -20,7 +20,7 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'a'
+channel = 'a'
# Synchronous usage
@@ -28,7 +28,8 @@ print pubnub.history(channel, count=2)
# Asynchronous usage
+
def callback(message):
print(message)
-pubnub.history(channel, count=2 , callback=callback, error=callback)
+pubnub.history(channel, count=2, callback=callback, error=callback)
diff --git a/python/examples/publish.py b/python/examples/publish.py
index 029c17a..a1b913b 100644
--- a/python/examples/publish.py
+++ b/python/examples/publish.py
@@ -20,17 +20,16 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'hello_world'
-message = 'Hello World !!!'
-
+channel = 'hello_world'
+message = 'Hello World !!!'
# Synchronous usage
-
print pubnub.publish(channel, message)
# Asynchronous usage
+
def callback(message):
print(message)
diff --git a/python/examples/subscribe.py b/python/examples/subscribe.py
index a410297..6cf93b1 100644
--- a/python/examples/subscribe.py
+++ b/python/examples/subscribe.py
@@ -21,26 +21,29 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
-channel = 'a'
-
+channel = 'a'
# Asynchronous usage
-
def callback(message, channel):
print(message)
+
def error(message):
print("ERROR : " + str(message))
+
def connect(message):
print("CONNECTED")
+
def reconnect(message):
print("RECONNECTED")
+
def disconnect(message):
print("DISCONNECTED")
-pubnub.subscribe(channel, callback=callback, error=callback, connect=connect, reconnect=reconnect, disconnect=disconnect)
+pubnub.subscribe(channel, callback=callback, error=callback,
+ connect=connect, reconnect=reconnect, disconnect=disconnect)