summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRobert Robinson <rerobins@gmail.com>2015-09-18 13:30:30 -0600
committerRobert Robinson <rerobins@gmail.com>2015-09-18 13:30:30 -0600
commit5fc14de32e7fbd4e33a0e1ed92d8fb23871a2a2d (patch)
treed21287dbbb7882b766098e0a81c0d1d3677d28d3 /examples
parente5582694c07236e6830c20361840360a1dde37f3 (diff)
parentd245558fd5eeee4fa34731ccea47c4c3132d805f (diff)
downloadslixmpp-5fc14de32e7fbd4e33a0e1ed92d8fb23871a2a2d.tar.gz
slixmpp-5fc14de32e7fbd4e33a0e1ed92d8fb23871a2a2d.tar.bz2
slixmpp-5fc14de32e7fbd4e33a0e1ed92d8fb23871a2a2d.tar.xz
slixmpp-5fc14de32e7fbd4e33a0e1ed92d8fb23871a2a2d.zip
Merge pull request #3 from fritzy/develop
Merge to fritzy_master
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/IoT_TestDevice.py22
-rwxr-xr-xexamples/disco_browser.py2
-rw-r--r--examples/http_over_xmpp.py101
-rwxr-xr-xexamples/migrate_roster.py2
-rwxr-xr-xexamples/roster_browser.py2
-rwxr-xr-xexamples/set_avatar.py2
6 files changed, 111 insertions, 20 deletions
diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py
index 8105aaff..b85a0b7c 100755
--- a/examples/IoT_TestDevice.py
+++ b/examples/IoT_TestDevice.py
@@ -11,18 +11,10 @@
See the file LICENSE for copying permission.
"""
-import os
-import sys
-# This can be used when you are in a test environment and need to make paths right
-sys.path=['/Users/jocke/Dropbox/06_dev/SleekXMPP']+sys.path
-
+import getpass
import logging
-import unittest
-import distutils.core
-import datetime
+import sys
-from glob import glob
-from os.path import splitext, basename, join as pjoin
from optparse import OptionParser
from urllib import urlopen
@@ -39,8 +31,6 @@ else:
from sleekxmpp.plugins.xep_0323.device import Device
-#from sleekxmpp.exceptions import IqError, IqTimeout
-
class IoT_TestDevice(sleekxmpp.ClientXMPP):
"""
@@ -179,13 +169,13 @@ if __name__ == '__main__':
# node=opts.nodeid,
# jid=xmpp.boundjid.full)
- myDevice = TheDevice(opts.nodeid);
+ myDevice = TheDevice(opts.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=opts.nodeid, device=myDevice, commTimeout=10);
+ xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10)
xmpp.beClientOrServer(server=True)
while not(xmpp.testForRelease()):
xmpp.connect()
diff --git a/examples/disco_browser.py b/examples/disco_browser.py
index aeb4fb5e..78626e7c 100755
--- a/examples/disco_browser.py
+++ b/examples/disco_browser.py
@@ -94,7 +94,7 @@ class Disco(sleekxmpp.ClientXMPP):
info = self['xep_0030'].get_info(jid=self.target_jid,
node=self.target_node,
block=True)
- elif self.get in self.items_types:
+ if self.get in self.items_types:
# The same applies from above. Listen for the
# disco_items event or pass a callback function
# if you need to process a non-blocking request.
diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py
new file mode 100644
index 00000000..a2fbf664
--- /dev/null
+++ b/examples/http_over_xmpp.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ SleekXMPP: The Sleek 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 SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp 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 : ', iq
+ print 'From : ', iq['from']
+ print 'To : ', iq['to']
+ print 'Type : ', iq['type']
+ print 'Headers : ', iq['resp']['headers']
+ print 'Code : ', iq['resp']['code']
+ print 'Message : ', iq['resp']['message']
+ print 'Data : ', 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 = raw_input('Username: ')
+ if opts.password is None:
+ opts.password = getpass.getpass('Password: ')
+
+ xmpp = HTTPOverXMPPClient(opts.jid, opts.password)
+ if xmpp.connect((opts.ipaddr, int(opts.port))):
+ print 'Connected!'
+ xmpp.process(block=True)
+ else:
+ print 'Not connected!'
+ print 'Goodbye....'
+
diff --git a/examples/migrate_roster.py b/examples/migrate_roster.py
index 797e4f44..9f679523 100755
--- a/examples/migrate_roster.py
+++ b/examples/migrate_roster.py
@@ -113,7 +113,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)
if new_xmpp.connect():
diff --git a/examples/roster_browser.py b/examples/roster_browser.py
index 485ac941..a16de24c 100755
--- a/examples/roster_browser.py
+++ b/examples/roster_browser.py
@@ -68,7 +68,7 @@ class RosterBrowser(sleekxmpp.ClientXMPP):
try:
self.get_roster()
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()
diff --git a/examples/set_avatar.py b/examples/set_avatar.py
index cae93c99..08e0b664 100755
--- a/examples/set_avatar.py
+++ b/examples/set_avatar.py
@@ -63,7 +63,7 @@ class AvatarSetter(sleekxmpp.ClientXMPP):
avatar_file = None
try:
- avatar_file = open(os.path.expanduser(self.filepath))
+ avatar_file = open(os.path.expanduser(self.filepath), 'rb')
except IOError:
print('Could not find file: %s' % self.filepath)
return self.disconnect()