diff options
author | mathieui <mathieui@mathieui.net> | 2015-09-23 23:14:26 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2015-09-23 23:15:09 +0200 |
commit | 4512248901700ce464716b79a2a1108194c91cda (patch) | |
tree | 93cf7524b52f2a25a5bfac99362202fe478830e3 /examples | |
parent | e42d651d7ed56375523f91076295fc5f388a8de0 (diff) | |
parent | 4305eddb4f634803423cd53d193125a63b00769a (diff) | |
download | slixmpp-4512248901700ce464716b79a2a1108194c91cda.tar.gz slixmpp-4512248901700ce464716b79a2a1108194c91cda.tar.bz2 slixmpp-4512248901700ce464716b79a2a1108194c91cda.tar.xz slixmpp-4512248901700ce464716b79a2a1108194c91cda.zip |
Merge branch 'develop' of https://github.com/fritzy/SleekXMPP into sleek-mergesleek-merge
Conflicts:
README.rst
examples/IoT_TestDevice.py
examples/disco_browser.py
setup.py
sleekxmpp/jid.py
sleekxmpp/plugins/google/auth/stanza.py
sleekxmpp/plugins/google/gmail/notifications.py
sleekxmpp/plugins/google/nosave/stanza.py
sleekxmpp/plugins/google/settings/settings.py
sleekxmpp/thirdparty/__init__.py
sleekxmpp/thirdparty/socks.py
sleekxmpp/thirdparty/statemachine.py
sleekxmpp/util/__init__.py
sleekxmpp/xmlstream/xmlstream.py
slixmpp/basexmpp.py
slixmpp/plugins/xep_0004/stanza/form.py
slixmpp/plugins/xep_0009/rpc.py
slixmpp/plugins/xep_0050/adhoc.py
slixmpp/plugins/xep_0065/proxy.py
slixmpp/plugins/xep_0084/stanza.py
slixmpp/plugins/xep_0202/time.py
slixmpp/plugins/xep_0323/sensordata.py
slixmpp/plugins/xep_0325/control.py
slixmpp/plugins/xep_0325/stanza/control.py
slixmpp/roster/single.py
slixmpp/stanza/atom.py
slixmpp/stanza/rootstanza.py
slixmpp/test/slixtest.py
slixmpp/util/sasl/mechanisms.py
slixmpp/version.py
slixmpp/xmlstream/stanzabase.py
tests/test_stanza_xep_0323.py
tests/test_stanza_xep_0325.py
tests/test_stream_xep_0323.py
tests/test_stream_xep_0325.py
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/IoT_TestDevice.py | 4 | ||||
-rwxr-xr-x | examples/disco_browser.py | 4 | ||||
-rw-r--r-- | examples/http_over_xmpp.py | 97 | ||||
-rwxr-xr-x | examples/migrate_roster.py | 2 | ||||
-rwxr-xr-x | examples/roster_browser.py | 2 |
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() |