summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/custom_stanzas/custom_stanza_provider.py19
-rwxr-xr-xexamples/custom_stanzas/custom_stanza_user.py12
-rw-r--r--examples/custom_stanzas/stanza.py2
-rwxr-xr-xexamples/gtalk_custom_domain.py4
-rw-r--r--examples/http_over_xmpp.py30
5 files changed, 35 insertions, 32 deletions
diff --git a/examples/custom_stanzas/custom_stanza_provider.py b/examples/custom_stanzas/custom_stanza_provider.py
index 9927c449..bca4a904 100755
--- a/examples/custom_stanzas/custom_stanza_provider.py
+++ b/examples/custom_stanzas/custom_stanza_provider.py
@@ -50,7 +50,7 @@ class ActionBot(slixmpp.ClientXMPP):
register_stanza_plugin(Iq, Action)
- def start(self, event):
+ async def start(self, event):
"""
Process the session_start event.
@@ -73,7 +73,7 @@ class ActionBot(slixmpp.ClientXMPP):
"""
self.event('custom_action', iq)
- def _handle_action_event(self, iq):
+ async def _handle_action_event(self, iq):
"""
Respond to the custom action event.
"""
@@ -82,17 +82,20 @@ class ActionBot(slixmpp.ClientXMPP):
if method == 'is_prime' and param == '2':
print("got message: %s" % iq)
- iq.reply()
- iq['action']['status'] = 'done'
- iq.send()
+ rep = iq.reply()
+ rep['action']['status'] = 'done'
+ await rep.send()
elif method == 'bye':
print("got message: %s" % iq)
+ rep = iq.reply()
+ rep['action']['status'] = 'done'
+ await rep.send()
self.disconnect()
else:
print("got message: %s" % iq)
- iq.reply()
- iq['action']['status'] = 'error'
- iq.send()
+ rep = iq.reply()
+ rep['action']['status'] = 'error'
+ await rep.send()
if __name__ == '__main__':
# Setup the command line arguments.
diff --git a/examples/custom_stanzas/custom_stanza_user.py b/examples/custom_stanzas/custom_stanza_user.py
index c5630584..4119aa97 100755
--- a/examples/custom_stanzas/custom_stanza_user.py
+++ b/examples/custom_stanzas/custom_stanza_user.py
@@ -43,7 +43,7 @@ class ActionUserBot(slixmpp.ClientXMPP):
register_stanza_plugin(Iq, Action)
- def start(self, event):
+ async def start(self, event):
"""
Process the session_start event.
@@ -57,11 +57,11 @@ class ActionUserBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
- self.get_roster()
+ await self.get_roster()
- self.send_custom_iq()
+ await self.send_custom_iq()
- def send_custom_iq(self):
+ async def send_custom_iq(self):
"""Create and send two custom actions.
If the first action was successful, then send
@@ -74,14 +74,14 @@ class ActionUserBot(slixmpp.ClientXMPP):
iq['action']['param'] = '2'
try:
- resp = iq.send()
+ resp = await iq.send()
if resp['action']['status'] == 'done':
#sending bye
iq2 = self.Iq()
iq2['to'] = self.action_provider
iq2['type'] = 'set'
iq2['action']['method'] = 'bye'
- iq2.send(block=False)
+ await iq2.send()
self.disconnect()
except XMPPError:
diff --git a/examples/custom_stanzas/stanza.py b/examples/custom_stanzas/stanza.py
index b2c6f766..17b7c7de 100644
--- a/examples/custom_stanzas/stanza.py
+++ b/examples/custom_stanzas/stanza.py
@@ -41,7 +41,7 @@ class Action(ElementBase):
#: del action['status']
#:
#: to set, get, or remove its values.
- interfaces = set(('method', 'param', 'status'))
+ interfaces = {'method', 'param', 'status'}
#: By default, values in the `interfaces` set are mapped to
#: attribute values. This can be changed such that an interface
diff --git a/examples/gtalk_custom_domain.py b/examples/gtalk_custom_domain.py
index d25a5786..f055159b 100755
--- a/examples/gtalk_custom_domain.py
+++ b/examples/gtalk_custom_domain.py
@@ -55,8 +55,8 @@ class GTalkBot(slixmpp.ClientXMPP):
cert.verify('talk.google.com', der_cert)
logging.debug("CERT: Found GTalk certificate")
except cert.CertificateError as err:
- log.error(err.message)
- self.disconnect(send_close=False)
+ logging.error(err.message)
+ self.disconnect()
def start(self, event):
"""
diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py
index 73e4a612..013f301b 100644
--- a/examples/http_over_xmpp.py
+++ b/examples/http_over_xmpp.py
@@ -13,7 +13,7 @@
from slixmpp import ClientXMPP
-from optparse import OptionParser
+from argparse import ArgumentParser
import logging
import getpass
@@ -23,7 +23,7 @@ class HTTPOverXMPPClient(ClientXMPP):
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
+ 'session_start', self.session_start
)
self.add_event_handler('http_request', self.http_request_received)
self.add_event_handler('http_response', self.http_response_received)
@@ -58,40 +58,40 @@ if __name__ == '__main__':
# ./http_over_xmpp.py -J <jid> -P <pwd> -i <ip> -p <port> [-v]
#
- parser = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- parser.add_option(
+ parser.add_argument(
'-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')
+ parser.add_argument('-J', '--jid', dest='jid', help='JID')
+ parser.add_argument('-P', '--password', dest='password', help='Password')
# XMPP server ip and port options.
- parser.add_option(
+ parser.add_argument(
'-i', '--ipaddr', dest='ipaddr',
help='IP Address of the XMPP server', default=None
)
- parser.add_option(
+ parser.add_argument(
'-p', '--port', dest='port',
help='Port of the XMPP server', default=None
)
- opts, args = parser.parse_args()
+ args = parser.parse_args()
# Setup logging.
- logging.basicConfig(level=opts.loglevel,
+ logging.basicConfig(level=args.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: ')
+ if args.jid is None:
+ args.jid = input('Username: ')
+ if args.password is None:
+ args.password = getpass.getpass('Password: ')
- xmpp = HTTPOverXMPPClient(opts.jid, opts.password)
+ xmpp = HTTPOverXMPPClient(args.jid, args.password)
xmpp.connect()
xmpp.process()