summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]examples/IoT_TestDevice.py29
-rwxr-xr-x[-rw-r--r--]examples/download_avatars.py0
-rwxr-xr-xexamples/echo_client.py2
-rwxr-xr-x[-rw-r--r--]examples/migrate_roster.py3
-rwxr-xr-x[-rw-r--r--]examples/pubsub_client.py7
-rwxr-xr-x[-rw-r--r--]examples/pubsub_events.py5
-rwxr-xr-x[-rw-r--r--]examples/register_account.py0
-rwxr-xr-x[-rw-r--r--]examples/roster_browser.py0
-rwxr-xr-x[-rw-r--r--]examples/rpc_async.py29
-rwxr-xr-x[-rw-r--r--]examples/rpc_client_side.py29
-rwxr-xr-x[-rw-r--r--]examples/rpc_server_side.py31
-rwxr-xr-x[-rw-r--r--]examples/set_avatar.py0
-rwxr-xr-x[-rw-r--r--]examples/thirdparty_auth.py0
-rwxr-xr-x[-rw-r--r--]examples/user_location.py0
-rwxr-xr-x[-rw-r--r--]examples/user_tune.py0
15 files changed, 77 insertions, 58 deletions
diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py
index c754cfb4..8105aaff 100644..100755
--- a/examples/IoT_TestDevice.py
+++ b/examples/IoT_TestDevice.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+# -*- coding: utf-8 -*-
"""
SleekXMPP: The Sleek XMPP Library
@@ -35,7 +36,7 @@ if sys.version_info < (3, 0):
setdefaultencoding('utf8')
else:
raw_input = input
-
+
from sleekxmpp.plugins.xep_0323.device import Device
#from sleekxmpp.exceptions import IqError, IqTimeout
@@ -68,7 +69,7 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
else:
self.beServer=False
self.clientJID=clientJID
-
+
def testForRelease(self):
# todo thread safe
return self.releaseMe
@@ -76,14 +77,14 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
def doReleaseMe(self):
# todo thread safe
self.releaseMe=True
-
+
def addDevice(self, device):
self.device=device
-
+
def session_start(self, event):
self.send_presence()
self.get_roster()
- # tell your preffered friend that you are alive
+ # tell your preffered friend that you are alive
self.send_message(mto='jocke@jabber.sust.se', mbody=self.boundjid.bare +' is now online use xep_323 stanza to talk to me')
if not(self.beServer):
@@ -96,7 +97,7 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
msg.reply("Hi I am " + self.boundjid.full + " and I am on IP " + ip).send()
else:
logging.debug("got unknown message type %s", str(msg['type']))
-
+
class TheDevice(Device):
"""
This is the actual device object that you will use to get information from your real hardware
@@ -112,8 +113,8 @@ class TheDevice(Device):
"""
self._set_momentary_timestamp(self._get_timestamp())
self.counter+=self.counter
- self._add_field_momentary_data(self, "Temperature", self.counter)
-
+ self._add_field_momentary_data(self, "Temperature", self.counter)
+
if __name__ == '__main__':
# Setup the command line arguments.
@@ -123,7 +124,7 @@ if __name__ == '__main__':
# python IoT_TestDevice.py -j "serverjid@yourdomain.com" -p "password" -n "TestIoT" --debug
#
# "client" an IoT device or other party that would like to get data from another device
-
+
optp = OptionParser()
# Output verbosity options.
@@ -151,7 +152,7 @@ if __name__ == '__main__':
help="Another device to call for data on", default=None)
optp.add_option("-n", "--nodeid", dest="nodeid",
help="I am a device get ready to be called", default=None)
-
+
opts, args = optp.parse_args()
# Setup logging.
@@ -162,7 +163,7 @@ if __name__ == '__main__':
opts.jid = raw_input("Username: ")
if opts.password is None:
opts.password = getpass.getpass("Password: ")
-
+
xmpp = IoT_TestDevice(opts.jid,opts.password)
xmpp.register_plugin('xep_0030')
@@ -183,12 +184,12 @@ if __name__ == '__main__':
myDevice._add_field(name="Temperature", typename="numeric", unit="C");
myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});
-
+
xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10);
xmpp.beClientOrServer(server=True)
while not(xmpp.testForRelease()):
xmpp.connect()
- xmpp.process(block=True)
+ xmpp.process(block=True)
logging.debug("lost connection")
if opts.sensorjid:
logging.debug("will try to call another device for data")
@@ -196,7 +197,7 @@ if __name__ == '__main__':
xmpp.connect()
xmpp.process(block=True)
logging.debug("ready ending")
-
+
else:
print "noopp didn't happen"
diff --git a/examples/download_avatars.py b/examples/download_avatars.py
index 64300cff..64300cff 100644..100755
--- a/examples/download_avatars.py
+++ b/examples/download_avatars.py
diff --git a/examples/echo_client.py b/examples/echo_client.py
index f2d38847..18125a0d 100755
--- a/examples/echo_client.py
+++ b/examples/echo_client.py
@@ -151,7 +151,7 @@ if __name__ == '__main__':
#
# if xmpp.connect(('talk.google.com', 5222)):
# ...
- xmpp.process(block=True)
+ xmpp.process(block=False)
print("Done")
else:
print("Unable to connect.")
diff --git a/examples/migrate_roster.py b/examples/migrate_roster.py
index a93bdecd..797e4f44 100644..100755
--- a/examples/migrate_roster.py
+++ b/examples/migrate_roster.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
import sys
import logging
import getpass
diff --git a/examples/pubsub_client.py b/examples/pubsub_client.py
index 2fa419fb..9a65553b 100644..100755
--- a/examples/pubsub_client.py
+++ b/examples/pubsub_client.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
import sys
import logging
import getpass
@@ -20,7 +23,7 @@ else:
class PubsubClient(sleekxmpp.ClientXMPP):
- def __init__(self, jid, password, server,
+ def __init__(self, jid, password, server,
node=None, action='list', data=''):
super(PubsubClient, self).__init__(jid, password)
@@ -28,7 +31,7 @@ class PubsubClient(sleekxmpp.ClientXMPP):
self.register_plugin('xep_0059')
self.register_plugin('xep_0060')
- self.actions = ['nodes', 'create', 'delete',
+ self.actions = ['nodes', 'create', 'delete',
'publish', 'get', 'retract',
'purge', 'subscribe', 'unsubscribe']
diff --git a/examples/pubsub_events.py b/examples/pubsub_events.py
index 0dfb6c65..12c33a76 100644..100755
--- a/examples/pubsub_events.py
+++ b/examples/pubsub_events.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
import sys
import logging
import getpass
@@ -77,7 +80,7 @@ class PubsubEvents(sleekxmpp.ClientXMPP):
"""Handle receiving a node deletion event."""
print('Deleted node %s' % (
msg['pubsub_event']['delete']['node']))
-
+
def _config(self, msg):
"""Handle receiving a node configuration event."""
print('Configured node %s:' % (
diff --git a/examples/register_account.py b/examples/register_account.py
index 422e5602..422e5602 100644..100755
--- a/examples/register_account.py
+++ b/examples/register_account.py
diff --git a/examples/roster_browser.py b/examples/roster_browser.py
index 485ac941..485ac941 100644..100755
--- a/examples/roster_browser.py
+++ b/examples/roster_browser.py
diff --git a/examples/rpc_async.py b/examples/rpc_async.py
index 0b6d1936..e3e23b69 100644..100755
--- a/examples/rpc_async.py
+++ b/examples/rpc_async.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Dann Martens
@@ -11,34 +14,34 @@ from sleekxmpp.plugins.xep_0009.remote import Endpoint, remote, Remote, \
import time
class Boomerang(Endpoint):
-
+
def FQN(self):
return 'boomerang'
-
+
@remote
def throw(self):
print "Duck!"
-
+
def main():
session = Remote.new_session('kangaroo@xmpp.org/rpc', '*****')
- session.new_handler(ANY_ALL, Boomerang)
-
+ session.new_handler(ANY_ALL, Boomerang)
+
boomerang = session.new_proxy('kangaroo@xmpp.org/rpc', Boomerang)
-
+
callback = Future()
-
+
boomerang.async(callback).throw()
-
+
time.sleep(10)
-
+
session.close()
-
-
-
+
+
+
if __name__ == '__main__':
main()
- \ No newline at end of file
+
diff --git a/examples/rpc_client_side.py b/examples/rpc_client_side.py
index 135d6237..e792fc94 100644..100755
--- a/examples/rpc_client_side.py
+++ b/examples/rpc_client_side.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Dann Martens
@@ -12,18 +15,18 @@ import threading
import time
class Thermostat(Endpoint):
-
+
def FQN(self):
return 'thermostat'
-
+
def __init__(self, initial_temperature):
self._temperature = initial_temperature
- self._event = threading.Event()
-
+ self._event = threading.Event()
+
@remote
def set_temperature(self, temperature):
return NotImplemented
-
+
@remote
def get_temperature(self):
return NotImplemented
@@ -31,23 +34,23 @@ class Thermostat(Endpoint):
@remote(False)
def release(self):
return NotImplemented
-
+
def main():
session = Remote.new_session('operator@xmpp.org/rpc', '*****')
-
+
thermostat = session.new_proxy('thermostat@xmpp.org/rpc', Thermostat)
-
+
print("Current temperature is %s" % thermostat.get_temperature())
-
+
thermostat.set_temperature(20)
-
+
time.sleep(10)
-
+
session.close()
-
+
if __name__ == '__main__':
main()
-
+
diff --git a/examples/rpc_server_side.py b/examples/rpc_server_side.py
index d1a11c17..9e8b48d6 100644..100755
--- a/examples/rpc_server_side.py
+++ b/examples/rpc_server_side.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Dann Martens
@@ -11,42 +14,42 @@ from sleekxmpp.plugins.xep_0009.remote import Endpoint, remote, Remote, \
import threading
class Thermostat(Endpoint):
-
+
def FQN(self):
return 'thermostat'
-
+
def __init__(self, initial_temperature):
self._temperature = initial_temperature
- self._event = threading.Event()
-
+ self._event = threading.Event()
+
@remote
def set_temperature(self, temperature):
print("Setting temperature to %s" % temperature)
self._temperature = temperature
-
+
@remote
def get_temperature(self):
return self._temperature
@remote(False)
def release(self):
- self._event.set()
-
+ self._event.set()
+
def wait_for_release(self):
- self._event.wait()
-
+ self._event.wait()
+
def main():
session = Remote.new_session('sleek@xmpp.org/rpc', '*****')
-
+
thermostat = session.new_handler(ANY_ALL, Thermostat, 18)
-
+
thermostat.wait_for_release()
-
+
session.close()
-
+
if __name__ == '__main__':
main()
-
+
diff --git a/examples/set_avatar.py b/examples/set_avatar.py
index cae93c99..cae93c99 100644..100755
--- a/examples/set_avatar.py
+++ b/examples/set_avatar.py
diff --git a/examples/thirdparty_auth.py b/examples/thirdparty_auth.py
index f4d5c400..f4d5c400 100644..100755
--- a/examples/thirdparty_auth.py
+++ b/examples/thirdparty_auth.py
diff --git a/examples/user_location.py b/examples/user_location.py
index 2a64cada..2a64cada 100644..100755
--- a/examples/user_location.py
+++ b/examples/user_location.py
diff --git a/examples/user_tune.py b/examples/user_tune.py
index 09e050f0..09e050f0 100644..100755
--- a/examples/user_tune.py
+++ b/examples/user_tune.py