From 7265682a4d57d88956cb54f98f7a470465bbf417 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 00:52:24 +0200 Subject: cleanup semicolons, whitespace and mutable default arguments --- examples/IoT_TestDevice.py | 8 ++++---- examples/roster_browser.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py index 8105aaff..cd80cee2 100755 --- a/examples/IoT_TestDevice.py +++ b/examples/IoT_TestDevice.py @@ -179,13 +179,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/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() -- cgit v1.2.3 From 3dd379cdf12d885e26f8ec26c54879a95d5f0b84 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 15:15:14 +0200 Subject: Revert "cleanup semicolons, whitespace and mutable default arguments" This reverts commit 7265682a4d57d88956cb54f98f7a470465bbf417. --- examples/IoT_TestDevice.py | 8 ++++---- examples/roster_browser.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py index cd80cee2..8105aaff 100755 --- a/examples/IoT_TestDevice.py +++ b/examples/IoT_TestDevice.py @@ -179,13 +179,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/roster_browser.py b/examples/roster_browser.py index a16de24c..485ac941 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: %s' % err.iq['error']['condition']) + print('Error: %' % err.iq['error']['condition']) except IqTimeout: print('Error: Request timed out') self.send_presence() -- cgit v1.2.3 From afc939708ff71e168f9204f1eab8823b7dc9f875 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 00:52:24 +0200 Subject: cleanup semicolons, whitespace and mutable default arguments --- examples/IoT_TestDevice.py | 8 ++++---- examples/roster_browser.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py index 8105aaff..cd80cee2 100755 --- a/examples/IoT_TestDevice.py +++ b/examples/IoT_TestDevice.py @@ -179,13 +179,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/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() -- cgit v1.2.3 From 1ce42d3a2fe62f82030268923d307cb35896d4d4 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 11:30:38 +0530 Subject: Boilerplate example. --- examples/http_over_xmpp_transport.py | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/http_over_xmpp_transport.py (limited to 'examples') diff --git a/examples/http_over_xmpp_transport.py b/examples/http_over_xmpp_transport.py new file mode 100644 index 00000000..7a60c6fc --- /dev/null +++ b/examples/http_over_xmpp_transport.py @@ -0,0 +1,69 @@ +from sleekxmpp import ClientXMPP +import logging + + +# def tracefunc(frame, event, arg, indent=[0]): +# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" +# if not frame.f_code.co_filename.startswith(prefix): +# return tracefunc +# if event == "call": +# indent[0] += 2 +# cn = getattr( +# getattr(frame.f_locals.get("self"), "__class__", None), +# "__name__", None +# ) +# print "{}{} {} {}".format( +# "." * indent[0], frame.f_code.co_filename[len(prefix):], +# cn, frame.f_code.co_name +# ) +# elif event == "return": +# indent[0] -= 2 +# return tracefunc +# +# +# import sys +# sys.settrace(tracefunc) + + +class HTTPOverXMPPClient(ClientXMPP): + def __init__(self, jid, password): + ClientXMPP.__init__(self, jid, password) + + # self.register_plugin('xep_0030') # Service Discovery + # self.register_plugin('xep_0004') # Data Forms + # self.register_plugin('xep_0060') # PubSub + # self.register_plugin('xep_0199') # XMPP Ping + # + # self.add_event_handler("session_start", self.session_start) + # self.add_event_handler("connected", self.connected) + # + # def session_start(self, event): + # print "Client::session_start()" + # self.send_presence() + # print self.get_roster() + # + # def connected(self, event): + # print "Client::connected()" + + +def get_cred(filename="/tmp/.cred"): + with open(filename, "r") as f: + return f.readline().split() + + +if __name__ == "__main__": + + logging.basicConfig( + level=logging.DEBUG, format='%(levelname)-8s %(message)s' + ) + + jid, password = get_cred() + xmpp = HTTPOverXMPPClient(jid, password) + if xmpp.connect(("talk.l.google.com", 5222)): + print "Connected!" + xmpp.process(block=True) + else: + print "Not connected!" + print "Goodbye...." + + -- cgit v1.2.3 From 8afba7de853be4eb3c5cb2467fa17db64cf84abc Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 16:38:16 +0530 Subject: renamed example for convenience. --- examples/http_over_xmpp.py | 70 ++++++++++++++++++++++++++++++++++++ examples/http_over_xmpp_transport.py | 69 ----------------------------------- 2 files changed, 70 insertions(+), 69 deletions(-) create mode 100644 examples/http_over_xmpp.py delete mode 100644 examples/http_over_xmpp_transport.py (limited to 'examples') diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py new file mode 100644 index 00000000..5de8713e --- /dev/null +++ b/examples/http_over_xmpp.py @@ -0,0 +1,70 @@ +from sleekxmpp import ClientXMPP +import logging + + +# def tracefunc(frame, event, arg, indent=[0]): +# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" +# if not frame.f_code.co_filename.startswith(prefix): +# return tracefunc +# if event == "call": +# indent[0] += 2 +# cn = getattr( +# getattr(frame.f_locals.get("self"), "__class__", None), +# "__name__", None +# ) +# print "{}{} {} {}".format( +# "." * indent[0], frame.f_code.co_filename[len(prefix):], +# cn, frame.f_code.co_name +# ) +# elif event == "return": +# indent[0] -= 2 +# return tracefunc +# +# +# import sys +# sys.settrace(tracefunc) + + +class HTTPOverXMPPClient(ClientXMPP): + def __init__(self, jid, password): + ClientXMPP.__init__(self, jid, password) + + self.register_plugin('xep_0332') # HTTP over XMPP + # self.register_plugin('xep_0030') # Service Discovery + # self.register_plugin('xep_0004') # Data Forms + # self.register_plugin('xep_0060') # PubSub + # self.register_plugin('xep_0199') # XMPP Ping + # + # self.add_event_handler("session_start", self.session_start) + # self.add_event_handler("connected", self.connected) + # + # def session_start(self, event): + # print "Client::session_start()" + # self.send_presence() + # print self.get_roster() + # + # def connected(self, event): + # print "Client::connected()" + + +def get_cred(filename="/tmp/.cred"): + with open(filename, "r") as f: + return f.readline().split() + + +if __name__ == "__main__": + + logging.basicConfig( + level=logging.DEBUG, format='%(levelname)-8s %(message)s' + ) + + jid, password = get_cred() + xmpp = HTTPOverXMPPClient(jid, password) + if xmpp.connect(("talk.l.google.com", 5222)): + print "Connected!" + xmpp.process(block=True) + else: + print "Not connected!" + print "Goodbye...." + + diff --git a/examples/http_over_xmpp_transport.py b/examples/http_over_xmpp_transport.py deleted file mode 100644 index 7a60c6fc..00000000 --- a/examples/http_over_xmpp_transport.py +++ /dev/null @@ -1,69 +0,0 @@ -from sleekxmpp import ClientXMPP -import logging - - -# def tracefunc(frame, event, arg, indent=[0]): -# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" -# if not frame.f_code.co_filename.startswith(prefix): -# return tracefunc -# if event == "call": -# indent[0] += 2 -# cn = getattr( -# getattr(frame.f_locals.get("self"), "__class__", None), -# "__name__", None -# ) -# print "{}{} {} {}".format( -# "." * indent[0], frame.f_code.co_filename[len(prefix):], -# cn, frame.f_code.co_name -# ) -# elif event == "return": -# indent[0] -= 2 -# return tracefunc -# -# -# import sys -# sys.settrace(tracefunc) - - -class HTTPOverXMPPClient(ClientXMPP): - def __init__(self, jid, password): - ClientXMPP.__init__(self, jid, password) - - # self.register_plugin('xep_0030') # Service Discovery - # self.register_plugin('xep_0004') # Data Forms - # self.register_plugin('xep_0060') # PubSub - # self.register_plugin('xep_0199') # XMPP Ping - # - # self.add_event_handler("session_start", self.session_start) - # self.add_event_handler("connected", self.connected) - # - # def session_start(self, event): - # print "Client::session_start()" - # self.send_presence() - # print self.get_roster() - # - # def connected(self, event): - # print "Client::connected()" - - -def get_cred(filename="/tmp/.cred"): - with open(filename, "r") as f: - return f.readline().split() - - -if __name__ == "__main__": - - logging.basicConfig( - level=logging.DEBUG, format='%(levelname)-8s %(message)s' - ) - - jid, password = get_cred() - xmpp = HTTPOverXMPPClient(jid, password) - if xmpp.connect(("talk.l.google.com", 5222)): - print "Connected!" - xmpp.process(block=True) - else: - print "Not connected!" - print "Goodbye...." - - -- cgit v1.2.3 From 24264d3a07f8a1576637e6a5703682e8735c2be1 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 5 Feb 2015 18:10:10 +0530 Subject: Updated Example.. --- examples/http_over_xmpp.py | 138 ++++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 57 deletions(-) (limited to 'examples') diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py index 5de8713e..5630f778 100644 --- a/examples/http_over_xmpp.py +++ b/examples/http_over_xmpp.py @@ -1,70 +1,94 @@ -from sleekxmpp import ClientXMPP -import logging +#!/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 -# def tracefunc(frame, event, arg, indent=[0]): -# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" -# if not frame.f_code.co_filename.startswith(prefix): -# return tracefunc -# if event == "call": -# indent[0] += 2 -# cn = getattr( -# getattr(frame.f_locals.get("self"), "__class__", None), -# "__name__", None -# ) -# print "{}{} {} {}".format( -# "." * indent[0], frame.f_code.co_filename[len(prefix):], -# cn, frame.f_code.co_name -# ) -# elif event == "return": -# indent[0] -= 2 -# return tracefunc -# -# -# import sys -# sys.settrace(tracefunc) +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() + - self.register_plugin('xep_0332') # HTTP over XMPP - # self.register_plugin('xep_0030') # Service Discovery - # self.register_plugin('xep_0004') # Data Forms - # self.register_plugin('xep_0060') # PubSub - # self.register_plugin('xep_0199') # XMPP Ping - # - # self.add_event_handler("session_start", self.session_start) - # self.add_event_handler("connected", self.connected) - # - # def session_start(self, event): - # print "Client::session_start()" - # self.send_presence() - # print self.get_roster() - # - # def connected(self, event): - # print "Client::connected()" - - -def get_cred(filename="/tmp/.cred"): - with open(filename, "r") as f: - return f.readline().split() - - -if __name__ == "__main__": - - logging.basicConfig( - level=logging.DEBUG, format='%(levelname)-8s %(message)s' +if __name__ == '__main__': + + 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') - jid, password = get_cred() - xmpp = HTTPOverXMPPClient(jid, password) - if xmpp.connect(("talk.l.google.com", 5222)): - print "Connected!" + 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...." - + print 'Not connected!' + print 'Goodbye....' -- cgit v1.2.3 From 904480712157d762d35de16ce55202d641a56b3c Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 5 Feb 2015 18:11:41 +0530 Subject: Added help for running example.. --- examples/http_over_xmpp.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'examples') diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py index 5630f778..a2fbf664 100644 --- a/examples/http_over_xmpp.py +++ b/examples/http_over_xmpp.py @@ -51,6 +51,13 @@ class HTTPOverXMPPClient(ClientXMPP): 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 -P -i -p [-v] + # + parser = OptionParser() # Output verbosity options. -- cgit v1.2.3 From 81b7b2c1908e0f6a5435ce67745b5f4dafb59816 Mon Sep 17 00:00:00 2001 From: Richard Kellner Date: Wed, 25 Mar 2015 14:04:46 +0100 Subject: Fixed bug #353 Python3 XEP-0084 error --- examples/set_avatar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') 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() -- cgit v1.2.3 From a0c6bf15e97a71787ffa4fec1850a995ba1d5446 Mon Sep 17 00:00:00 2001 From: Joshua Downer Date: Wed, 13 May 2015 17:24:06 -0400 Subject: Fixed imports Removed unused modules/packages and added getpass, which was missing. --- examples/IoT_TestDevice.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py index cd80cee2..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): """ -- cgit v1.2.3 From 92901637ec068bb529c7a86fa8e348930f951e78 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Mon, 25 May 2015 01:01:08 +0200 Subject: Change to roster migration example I did have the chance to test the script yet, but it seems like that line should be outside the for loop. --- examples/migrate_roster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') 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(): -- cgit v1.2.3 From edd9199be83a0d62c5e18f830021bc13c34f2e00 Mon Sep 17 00:00:00 2001 From: elya5 Date: Thu, 9 Jul 2015 17:15:36 +0200 Subject: Fix UnboundlocalError in disco_browser.py example If self.get is in self.info_types and self.items_types, only self['xep_0030'].get_info is executed and not self['xep_0030'].get_items. So the condition in line 129 is successful but items is not assigned. --- examples/disco_browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') 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. -- cgit v1.2.3