summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-18 01:06:59 -0700
committerLance Stout <lancestout@gmail.com>2011-08-18 01:06:59 -0700
commit015f662249eec9a0504bea1d614ad1138d8e19ab (patch)
treefa3da93e6dabd8a27aead8f034bb02e636d849e5 /examples
parent8d998d71a3f21a8ee6e887b87daaed3285329522 (diff)
downloadslixmpp-015f662249eec9a0504bea1d614ad1138d8e19ab.tar.gz
slixmpp-015f662249eec9a0504bea1d614ad1138d8e19ab.tar.bz2
slixmpp-015f662249eec9a0504bea1d614ad1138d8e19ab.tar.xz
slixmpp-015f662249eec9a0504bea1d614ad1138d8e19ab.zip
Update examples to work with Python3 (raw_input vs input)
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/adhoc_provider.py25
-rwxr-xr-xexamples/adhoc_user.py2
-rwxr-xr-xexamples/config_component.py2
-rwxr-xr-xexamples/disco_browser.py2
-rwxr-xr-xexamples/echo_client.py4
-rwxr-xr-xexamples/muc.py16
-rwxr-xr-xexamples/ping.py2
-rwxr-xr-xexamples/proxy_echo_client.py2
-rw-r--r--examples/roster_browser.py2
-rwxr-xr-xexamples/send_client.py2
10 files changed, 49 insertions, 10 deletions
diff --git a/examples/adhoc_provider.py b/examples/adhoc_provider.py
index 3316a0c6..5fa26334 100755
--- a/examples/adhoc_provider.py
+++ b/examples/adhoc_provider.py
@@ -24,6 +24,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class CommandBot(sleekxmpp.ClientXMPP):
@@ -79,9 +81,21 @@ class CommandBot(sleekxmpp.ClientXMPP):
here to persist across handler callbacks.
"""
form = self['xep_0004'].makeForm('form', 'Greeting')
+ form['instructions'] = 'Send a custom greeting to a JID'
form.addField(var='greeting',
ftype='text-single',
label='Your greeting')
+ form.addField(var='recipient',
+ ftype='jid-single',
+ label='Who to greet')
+ form.addField(var='message',
+ ftype='text-multi',
+ label='Your message')
+ form.addField(var='demobool',
+ ftype='boolean',
+ label='Test booleans',
+ desc='Test default values too',
+ value=True)
session['payload'] = form
session['next'] = self._handle_command_complete
@@ -123,8 +137,14 @@ class CommandBot(sleekxmpp.ClientXMPP):
form = payload
greeting = form['values']['greeting']
- self.send_message(mto=session['from'],
- mbody="%s, World!" % greeting)
+ recipient = form['values']['recipient']
+ message = '\n'.join(form['values']['message'])
+
+ if recipient is None:
+ recipient = session['from']
+ self.send_message(mto=recipient,
+ mbody="%s, %s!\n%s" % (greeting, recipient, message),
+ mtype='chat')
# Having no return statement is the same as unsetting the 'payload'
# and 'next' session values and returning the session.
@@ -176,6 +196,7 @@ if __name__ == '__main__':
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands
+ xmpp.register_plugin('xep_0199', {'keepalive': True, 'frequency':15})
# If you are working with an OpenFire server, you may need
# to adjust the SSL version used:
diff --git a/examples/adhoc_user.py b/examples/adhoc_user.py
index 5fba78d2..ac157edd 100755
--- a/examples/adhoc_user.py
+++ b/examples/adhoc_user.py
@@ -24,6 +24,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class CommandUserBot(sleekxmpp.ClientXMPP):
diff --git a/examples/config_component.py b/examples/config_component.py
index cbb8e628..7a28739f 100755
--- a/examples/config_component.py
+++ b/examples/config_component.py
@@ -27,6 +27,8 @@ from sleekxmpp.xmlstream.stanzabase import ET, registerStanzaPlugin
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class Config(ElementBase):
diff --git a/examples/disco_browser.py b/examples/disco_browser.py
index b2b96f95..0526bfc4 100755
--- a/examples/disco_browser.py
+++ b/examples/disco_browser.py
@@ -25,6 +25,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class Disco(sleekxmpp.ClientXMPP):
diff --git a/examples/echo_client.py b/examples/echo_client.py
index cd1b1d02..122b20f0 100755
--- a/examples/echo_client.py
+++ b/examples/echo_client.py
@@ -24,6 +24,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class EchoBot(sleekxmpp.ClientXMPP):
@@ -34,7 +36,7 @@ class EchoBot(sleekxmpp.ClientXMPP):
"""
def __init__(self, jid, password):
- sleekxmpp.ClientXMPP.__init__(self, jid, password)
+ sleekxmpp.ClientXMPP.__init__(self, jid, password, plugin_config={'feature_mechanisms': {'use_mech': 'PLAIN'}})
# The session_start event will be triggered when
# the bot establishes its connection with the server
diff --git a/examples/muc.py b/examples/muc.py
index 8296cb6d..96b5fb83 100755
--- a/examples/muc.py
+++ b/examples/muc.py
@@ -23,6 +23,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class MUCBot(sleekxmpp.ClientXMPP):
@@ -59,7 +61,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
# muc::room@server::got_online, or muc::room@server::got_offline.
self.add_event_handler("muc::%s::got_online" % self.room,
self.muc_online)
-
+
def start(self, event):
"""
@@ -76,15 +78,15 @@ class MUCBot(sleekxmpp.ClientXMPP):
"""
self.getRoster()
self.sendPresence()
- self.plugin['xep_0045'].joinMUC(self.room,
- self.nick,
+ self.plugin['xep_0045'].joinMUC(self.room,
+ self.nick,
# If a room password is needed, use:
# password=the_room_password,
wait=True)
def muc_message(self, msg):
"""
- Process incoming message stanzas from any chat room. Be aware
+ Process incoming message stanzas from any chat room. Be aware
that if you also have any handlers for the 'message' event,
message stanzas may be processed by both handlers, so check
the 'type' attribute when using a 'message' event handler.
@@ -96,7 +98,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
otherwise you will create an infinite loop responding
to your own messages.
- This handler will reply to messages that mention
+ This handler will reply to messages that mention
the bot's nickname.
Arguments:
@@ -112,12 +114,12 @@ class MUCBot(sleekxmpp.ClientXMPP):
def muc_online(self, presence):
"""
Process a presence stanza from a chat room. In this case,
- presences from users that have just come online are
+ presences from users that have just come online are
handled by sending a welcome message that includes
the user's nickname and role in the room.
Arguments:
- presence -- The received presence stanza. See the
+ presence -- The received presence stanza. See the
documentation for the Presence stanza
to see how else it may be used.
"""
diff --git a/examples/ping.py b/examples/ping.py
index ae030c0f..68772e6b 100755
--- a/examples/ping.py
+++ b/examples/ping.py
@@ -24,6 +24,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class PingTest(sleekxmpp.ClientXMPP):
diff --git a/examples/proxy_echo_client.py b/examples/proxy_echo_client.py
index 4db9a552..3466dc9b 100755
--- a/examples/proxy_echo_client.py
+++ b/examples/proxy_echo_client.py
@@ -24,6 +24,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class EchoBot(sleekxmpp.ClientXMPP):
diff --git a/examples/roster_browser.py b/examples/roster_browser.py
index a428324e..4a58cc1c 100644
--- a/examples/roster_browser.py
+++ b/examples/roster_browser.py
@@ -27,6 +27,8 @@ from sleekxmpp.exceptions import IqError, IqTimeout
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class RosterBrowser(sleekxmpp.ClientXMPP):
diff --git a/examples/send_client.py b/examples/send_client.py
index b3673512..d1dafee6 100755
--- a/examples/send_client.py
+++ b/examples/send_client.py
@@ -24,6 +24,8 @@ import sleekxmpp
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
+else:
+ raw_input = input
class SendMsgBot(sleekxmpp.ClientXMPP):