summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-10-02 19:07:45 +0200
committermathieui <mathieui@mathieui.net>2015-10-02 19:07:45 +0200
commitada9444bf84bd238238c4d22561f69184dd22cdd (patch)
treeceb4f86446b4129ec22cb348f1cb1bd7a151e2da /examples
parent1100ff1febf7e605e03fd9565bdac5fdaa3bf1e0 (diff)
parentacc52fd935b7e74919ad748f3a630596f66c62af (diff)
downloadslixmpp-ada9444bf84bd238238c4d22561f69184dd22cdd.tar.gz
slixmpp-ada9444bf84bd238238c4d22561f69184dd22cdd.tar.bz2
slixmpp-ada9444bf84bd238238c4d22561f69184dd22cdd.tar.xz
slixmpp-ada9444bf84bd238238c4d22561f69184dd22cdd.zip
Merge branch 'sleek-merge'
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/IoT_TestDevice.py4
-rwxr-xr-xexamples/disco_browser.py4
-rw-r--r--examples/http_over_xmpp.py97
-rwxr-xr-xexamples/migrate_roster.py2
-rwxr-xr-xexamples/roster_browser.py2
5 files changed, 101 insertions, 8 deletions
diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py
index 5b72994c..b9546017 100755
--- a/examples/IoT_TestDevice.py
+++ b/examples/IoT_TestDevice.py
@@ -160,9 +160,9 @@ if __name__ == '__main__':
myDevice = TheDevice(args.nodeid);
# myDevice._add_field(name="Relay", typename="numeric", unit="Bool");
- myDevice._add_field(name="Temperature", typename="numeric", unit="C");
+ 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"});
+ myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"})
xmpp['xep_0323'].register_node(nodeId=args.nodeid, device=myDevice, commTimeout=10);
xmpp.beClientOrServer(server=True)
diff --git a/examples/disco_browser.py b/examples/disco_browser.py
index 54f6c933..a9e8711f 100755
--- a/examples/disco_browser.py
+++ b/examples/disco_browser.py
@@ -76,10 +76,6 @@ class Disco(slixmpp.ClientXMPP):
try:
if self.get in self.info_types:
- # By using block=True, the result stanza will be
- # returned. Execution will block until the reply is
- # received. Non-blocking options would be to listen
- # for the disco_info event, or passing a handler
# function using the callback parameter.
info = yield from self['xep_0030'].get_info(jid=self.target_jid,
node=self.target_node)
diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py
new file mode 100644
index 00000000..73e4a612
--- /dev/null
+++ b/examples/http_over_xmpp.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+ Slixmpp: The Slick XMPP Library
+ Implementation of HTTP over XMPP transport
+ http://xmpp.org/extensions/xep-0332.html
+ Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com
+ This file is part of slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp import ClientXMPP
+
+from optparse import OptionParser
+import logging
+import getpass
+
+
+class HTTPOverXMPPClient(ClientXMPP):
+ def __init__(self, jid, password):
+ ClientXMPP.__init__(self, jid, password)
+ self.register_plugin('xep_0332') # HTTP over XMPP Transport
+ self.add_event_handler(
+ 'session_start', self.session_start, threaded=True
+ )
+ self.add_event_handler('http_request', self.http_request_received)
+ self.add_event_handler('http_response', self.http_response_received)
+
+ def http_request_received(self, iq):
+ pass
+
+ def http_response_received(self, iq):
+ print('HTTP Response Received : %s' % iq)
+ print('From : %s' % iq['from'])
+ print('To : %s' % iq['to'])
+ print('Type : %s' % iq['type'])
+ print('Headers : %s' % iq['resp']['headers'])
+ print('Code : %s' % iq['resp']['code'])
+ print('Message : %s' % iq['resp']['message'])
+ print('Data : %s' % iq['resp']['data'])
+
+ def session_start(self, event):
+ # TODO: Fill in the blanks
+ self['xep_0332'].send_request(
+ to='?', method='?', resource='?', headers={}
+ )
+ self.disconnect()
+
+
+if __name__ == '__main__':
+
+ #
+ # NOTE: To run this example, fill up the blanks in session_start() and
+ # use the following command.
+ #
+ # ./http_over_xmpp.py -J <jid> -P <pwd> -i <ip> -p <port> [-v]
+ #
+
+ parser = OptionParser()
+
+ # Output verbosity options.
+ parser.add_option(
+ '-v', '--verbose', help='set logging to DEBUG', action='store_const',
+ dest='loglevel', const=logging.DEBUG, default=logging.ERROR
+ )
+
+ # JID and password options.
+ parser.add_option('-J', '--jid', dest='jid', help='JID')
+ parser.add_option('-P', '--password', dest='password', help='Password')
+
+ # XMPP server ip and port options.
+ parser.add_option(
+ '-i', '--ipaddr', dest='ipaddr',
+ help='IP Address of the XMPP server', default=None
+ )
+ parser.add_option(
+ '-p', '--port', dest='port',
+ help='Port of the XMPP server', default=None
+ )
+
+ opts, args = parser.parse_args()
+
+ # Setup logging.
+ logging.basicConfig(level=opts.loglevel,
+ format='%(levelname)-8s %(message)s')
+
+ if opts.jid is None:
+ opts.jid = input('Username: ')
+ if opts.password is None:
+ opts.password = getpass.getpass('Password: ')
+
+ xmpp = HTTPOverXMPPClient(opts.jid, opts.password)
+ xmpp.connect()
+ xmpp.process()
+
diff --git a/examples/migrate_roster.py b/examples/migrate_roster.py
index e6c66f2e..d599b10c 100755
--- a/examples/migrate_roster.py
+++ b/examples/migrate_roster.py
@@ -100,7 +100,7 @@ def on_session2(event):
new_xmpp.update_roster(jid,
name = item['name'],
groups = item['groups'])
- new_xmpp.disconnect()
+ new_xmpp.disconnect()
new_xmpp.add_event_handler('session_start', on_session2)
new_xmpp.connect()
diff --git a/examples/roster_browser.py b/examples/roster_browser.py
index 4d07de11..eb92ad2a 100755
--- a/examples/roster_browser.py
+++ b/examples/roster_browser.py
@@ -59,7 +59,7 @@ class RosterBrowser(slixmpp.ClientXMPP):
self.get_roster(callback=callback)
yield from future
except IqError as err:
- print('Error: %' % err.iq['error']['condition'])
+ print('Error: %s' % err.iq['error']['condition'])
except IqTimeout:
print('Error: Request timed out')
self.send_presence()