summaryrefslogtreecommitdiff
path: root/examples/http_over_xmpp.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/http_over_xmpp.py')
-rw-r--r--examples/http_over_xmpp.py30
1 files changed, 15 insertions, 15 deletions
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()