summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2014-08-16 22:37:29 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-09-01 02:47:15 +0200
commit866014896091d83164a6503adf9035146cf49963 (patch)
tree23ab757e3a8d69a2741d0c907d2a0574c6be7002 /examples
parent67ca2dd0f45b112e206fb80eb4613960f312f721 (diff)
downloadslixmpp-866014896091d83164a6503adf9035146cf49963.tar.gz
slixmpp-866014896091d83164a6503adf9035146cf49963.tar.bz2
slixmpp-866014896091d83164a6503adf9035146cf49963.tar.xz
slixmpp-866014896091d83164a6503adf9035146cf49963.zip
Move examples from the deprecated optparse to argparse, and remove the redundant -v option.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/IoT_TestDevice.py67
-rwxr-xr-xexamples/adhoc_provider.py41
-rwxr-xr-xexamples/adhoc_user.py57
-rwxr-xr-xexamples/admin_commands.py49
-rwxr-xr-xexamples/custom_stanzas/custom_stanza_provider.py41
-rwxr-xr-xexamples/custom_stanzas/custom_stanza_user.py49
-rwxr-xr-xexamples/disco_browser.py67
-rwxr-xr-xexamples/download_avatars.py52
-rwxr-xr-xexamples/echo_client.py41
-rwxr-xr-xexamples/echo_component.py61
-rwxr-xr-xexamples/gtalk_custom_domain.py41
-rwxr-xr-xexamples/ibb_transfer/ibb_receiver.py41
-rwxr-xr-xexamples/ibb_transfer/ibb_sender.py57
-rwxr-xr-xexamples/migrate_roster.py59
-rwxr-xr-xexamples/muc.py57
-rwxr-xr-xexamples/ping.py47
-rwxr-xr-xexamples/proxy_echo_client.py85
-rwxr-xr-xexamples/pubsub_client.py81
-rwxr-xr-xexamples/pubsub_events.py41
-rwxr-xr-xexamples/register_account.py41
-rwxr-xr-xexamples/roster_browser.py52
-rwxr-xr-xexamples/send_client.py57
-rwxr-xr-xexamples/set_avatar.py60
-rwxr-xr-xexamples/thirdparty_auth.py45
-rwxr-xr-xexamples/user_location.py41
-rwxr-xr-xexamples/user_tune.py41
26 files changed, 636 insertions, 735 deletions
diff --git a/examples/IoT_TestDevice.py b/examples/IoT_TestDevice.py
index 17041956..b1968175 100755
--- a/examples/IoT_TestDevice.py
+++ b/examples/IoT_TestDevice.py
@@ -23,7 +23,7 @@ import datetime
from glob import glob
from os.path import splitext, basename, join as pjoin
-from optparse import OptionParser
+from argparse import ArgumentParser
from urllib import urlopen
import slixmpp
@@ -115,47 +115,44 @@ if __name__ == '__main__':
#
# "client" an IoT device or other party that would like to get data from another device
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
- optp.add_option('-t', '--pingto', help='set jid to ping',
- action='store', type='string', dest='pingjid',
- default=None)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
+ parser.add_argument("-t", "--pingto", help="set jid to ping",
+ action="store", type="string", dest="pingjid",
+ default=None)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
# IoT test
- optp.add_option("-c", "--sensorjid", dest="sensorjid",
- help="Another device to call for data on", default=None)
- optp.add_option("-n", "--nodeid", dest="nodeid",
- help="I am a device get ready to be called", default=None)
+ parser.add_argument("-c", "--sensorjid", dest="sensorjid",
+ help="Another device to call for data on", default=None)
+ parser.add_argument("-n", "--nodeid", dest="nodeid",
+ help="I am a device get ready to be called", default=None)
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
- xmpp = IoT_TestDevice(opts.jid,opts.password)
+ xmpp = IoT_TestDevice(args.jid,args.password)
xmpp.register_plugin('xep_0030')
#xmpp['xep_0030'].add_feature(feature='urn:xmpp:iot:sensordata',
# node=None,
@@ -163,27 +160,27 @@ if __name__ == '__main__':
xmpp.register_plugin('xep_0323')
xmpp.register_plugin('xep_0325')
- if opts.nodeid:
+ if args.nodeid:
# xmpp['xep_0030'].add_feature(feature='urn:xmpp:sn',
- # node=opts.nodeid,
+ # node=args.nodeid,
# jid=xmpp.boundjid.full)
- myDevice = TheDevice(opts.nodeid);
+ myDevice = TheDevice(args.nodeid);
# myDevice._add_field(name="Relay", typename="numeric", unit="Bool");
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"});
- xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10);
+ xmpp['xep_0323'].register_node(nodeId=args.nodeid, device=myDevice, commTimeout=10);
xmpp.beClientOrServer(server=True)
while not(xmpp.testForRelease()):
xmpp.connect()
xmpp.process(block=True)
logging.debug("lost connection")
- if opts.sensorjid:
+ if args.sensorjid:
logging.debug("will try to call another device for data")
- xmpp.beClientOrServer(server=False,clientJID=opts.sensorjid)
+ xmpp.beClientOrServer(server=False,clientJID=args.sensorjid)
xmpp.connect()
xmpp.process(block=True)
logging.debug("ready ending")
diff --git a/examples/adhoc_provider.py b/examples/adhoc_provider.py
index fa8135ac..72259555 100755
--- a/examples/adhoc_provider.py
+++ b/examples/adhoc_provider.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -132,40 +132,37 @@ class CommandBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = CommandBot(opts.jid, opts.password)
+ xmpp = CommandBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands
diff --git a/examples/adhoc_user.py b/examples/adhoc_user.py
index a1f35a59..91e2e1ac 100755
--- a/examples/adhoc_user.py
+++ b/examples/adhoc_user.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -131,48 +131,45 @@ class CommandUserBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-o", "--other", dest="other",
- help="JID providing commands")
- optp.add_option("-g", "--greeting", dest="greeting",
- help="Greeting")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-o", "--other", dest="other",
+ help="JID providing commands")
+ parser.add_argument("-g", "--greeting", dest="greeting",
+ help="Greeting")
- opts, args = optp.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("Password: ")
- if opts.other is None:
- opts.other = input("JID Providing Commands: ")
- if opts.greeting is None:
- opts.greeting = input("Greeting: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.other is None:
+ args.other = input("JID Providing Commands: ")
+ if args.greeting is None:
+ args.greeting = input("Greeting: ")
# Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = CommandUserBot(opts.jid, opts.password, opts.other, opts.greeting)
+ xmpp = CommandUserBot(args.jid, args.password, args.other, args.greeting)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands
diff --git a/examples/admin_commands.py b/examples/admin_commands.py
index 928c2fc6..72577f87 100755
--- a/examples/admin_commands.py
+++ b/examples/admin_commands.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -105,44 +105,41 @@ class AdminCommands(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-c", "--command", dest="command",
- help="admin command to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-c", "--command", dest="command",
+ help="admin command to use")
- opts, args = optp.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("Password: ")
- if opts.command is None:
- opts.command = input("Admin command: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.command is None:
+ args.command = input("Admin command: ")
# Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = AdminCommands(opts.jid, opts.password, opts.command)
+ xmpp = AdminCommands(args.jid, args.password, args.command)
xmpp.register_plugin('xep_0133') # Service Administration
# Connect to the XMPP server and start processing XMPP stanzas.
diff --git a/examples/custom_stanzas/custom_stanza_provider.py b/examples/custom_stanzas/custom_stanza_provider.py
index e9060c87..9927c449 100755
--- a/examples/custom_stanzas/custom_stanza_provider.py
+++ b/examples/custom_stanzas/custom_stanza_provider.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -96,40 +96,37 @@ class ActionBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = ActionBot(opts.jid, opts.password)
+ xmpp = ActionBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands
diff --git a/examples/custom_stanzas/custom_stanza_user.py b/examples/custom_stanzas/custom_stanza_user.py
index 6e5c3e0c..4e8337f2 100755
--- a/examples/custom_stanzas/custom_stanza_user.py
+++ b/examples/custom_stanzas/custom_stanza_user.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp import Iq
@@ -100,44 +100,41 @@ class ActionUserBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-o", "--other", dest="other",
- help="JID providing custom stanza")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-o", "--other", dest="other",
+ help="JID providing custom stanza")
- opts, args = optp.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("Password: ")
- if opts.other is None:
- opts.other = input("JID Providing custom stanza: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.other is None:
+ args.other = input("JID Providing custom stanza: ")
# Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = ActionUserBot(opts.jid, opts.password, opts.other)
+ xmpp = ActionUserBot(args.jid, args.password, args.other)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands
diff --git a/examples/disco_browser.py b/examples/disco_browser.py
index 7c126388..33134c99 100755
--- a/examples/disco_browser.py
+++ b/examples/disco_browser.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.exceptions import IqError, IqTimeout
@@ -124,52 +124,41 @@ class Disco(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
- optp.version = '%%prog 0.1'
- optp.usage = "Usage: %%prog [options] %s <jid> [<node>]" % \
- 'all|info|items|identities|features'
-
- optp.add_option('-q','--quiet', help='set logging to ERROR',
- action='store_const',
- dest='loglevel',
- const=logging.ERROR,
- default=logging.ERROR)
- optp.add_option('-d','--debug', help='set logging to DEBUG',
- action='store_const',
- dest='loglevel',
- const=logging.DEBUG,
- default=logging.ERROR)
- optp.add_option('-v','--verbose', help='set logging to COMM',
- action='store_const',
- dest='loglevel',
- const=5,
- default=logging.ERROR)
+ parser = ArgumentParser(description=Disco.__doc__)
+
+ parser.add_argument("-q","--quiet", help="set logging to ERROR",
+ action="store_const",
+ dest="loglevel",
+ const=logging.ERROR,
+ default=logging.ERROR)
+ parser.add_argument("-d","--debug", help="set logging to DEBUG",
+ action="store_const",
+ dest="loglevel",
+ const=logging.DEBUG,
+ default=logging.ERROR)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- opts,args = optp.parse_args()
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("query", choices=["all", "info", "items", "identities", "features"])
+ parser.add_argument("target-jid")
+ parser.add_argument("node", nargs='?')
+
+ args = parser.parse_args()
# Setup logging.
- logging.basicConfig(level=opts.loglevel,
+ logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s')
- if len(args) < 2:
- optp.print_help()
- exit()
-
- if len(args) == 2:
- args = (args[0], args[1], '')
-
- if opts.jid is None:
- opts.jid = input("Username: ")
- if opts.password is None:
- opts.password = getpass("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the Disco browser.
- xmpp = Disco(opts.jid, opts.password, args[1], args[2], args[0])
+ xmpp = Disco(args.jid, args.password, args.target_jid, args.node, args.query)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/download_avatars.py b/examples/download_avatars.py
index b002ff08..df722856 100755
--- a/examples/download_avatars.py
+++ b/examples/download_avatars.py
@@ -12,7 +12,7 @@
import logging
from getpass import getpass
import threading
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.exceptions import XMPPError
@@ -113,40 +113,36 @@ class AvatarDownloader(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
- optp.add_option('-q','--quiet', help='set logging to ERROR',
- action='store_const',
- dest='loglevel',
- const=logging.ERROR,
- default=logging.ERROR)
- optp.add_option('-d','--debug', help='set logging to DEBUG',
- action='store_const',
- dest='loglevel',
- const=logging.DEBUG,
- default=logging.ERROR)
- optp.add_option('-v','--verbose', help='set logging to COMM',
- action='store_const',
- dest='loglevel',
- const=5,
- default=logging.ERROR)
+ parser = ArgumentParser()
+ parser.add_argument("-q","--quiet", help="set logging to ERROR",
+ action="store_const",
+ dest="loglevel",
+ const=logging.ERROR,
+ default=logging.ERROR)
+ parser.add_argument("-d","--debug", help="set logging to DEBUG",
+ action="store_const",
+ dest="loglevel",
+ const=logging.DEBUG,
+ default=logging.ERROR)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- opts,args = optp.parse_args()
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+
+ 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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
- xmpp = AvatarDownloader(opts.jid, opts.password)
+ xmpp = AvatarDownloader(args.jid, args.password)
xmpp.register_plugin('xep_0054')
xmpp.register_plugin('xep_0153')
xmpp.register_plugin('xep_0084')
diff --git a/examples/echo_client.py b/examples/echo_client.py
index 6d2317c9..820ca014 100755
--- a/examples/echo_client.py
+++ b/examples/echo_client.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -72,40 +72,37 @@ class EchoBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser(description=EchoBot.__doc__)
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = EchoBot(opts.jid, opts.password)
+ xmpp = EchoBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub
diff --git a/examples/echo_component.py b/examples/echo_component.py
index b51e3b2c..ff379894 100755
--- a/examples/echo_component.py
+++ b/examples/echo_component.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.componentxmpp import ComponentXMPP
@@ -56,48 +56,45 @@ class EchoComponent(ComponentXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser(description=EchoComponent.__doc__)
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-s", "--server", dest="server",
- help="server to connect to")
- optp.add_option("-P", "--port", dest="port",
- help="port to connect to")
-
- opts, args = optp.parse_args()
-
- if opts.jid is None:
- opts.jid = input("Component JID: ")
- if opts.password is None:
- opts.password = getpass("Password: ")
- if opts.server is None:
- opts.server = input("Server: ")
- if opts.port is None:
- opts.port = int(input("Port: "))
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-s", "--server", dest="server",
+ help="server to connect to")
+ parser.add_argument("-P", "--port", dest="port",
+ help="port to connect to")
+
+ args = parser.parse_args()
+
+ if args.jid is None:
+ args.jid = input("Component JID: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.server is None:
+ args.server = input("Server: ")
+ if args.port is None:
+ args.port = int(input("Port: "))
# Setup logging.
- logging.basicConfig(level=opts.loglevel,
+ logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s')
# Setup the EchoComponent and register plugins. Note that while plugins
# may have interdependencies, the order in which you register them does
# not matter.
- xmpp = EchoComponent(opts.jid, opts.password, opts.server, opts.port)
+ xmpp = EchoComponent(args.jid, args.password, args.server, args.port)
xmpp.registerPlugin('xep_0030') # Service Discovery
xmpp.registerPlugin('xep_0004') # Data Forms
xmpp.registerPlugin('xep_0060') # PubSub
diff --git a/examples/gtalk_custom_domain.py b/examples/gtalk_custom_domain.py
index 3897c6d2..d25a5786 100755
--- a/examples/gtalk_custom_domain.py
+++ b/examples/gtalk_custom_domain.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -92,40 +92,37 @@ class GTalkBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the GTalkBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = GTalkBot(opts.jid, opts.password)
+ xmpp = GTalkBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub
diff --git a/examples/ibb_transfer/ibb_receiver.py b/examples/ibb_transfer/ibb_receiver.py
index add53675..46dec047 100755
--- a/examples/ibb_transfer/ibb_receiver.py
+++ b/examples/ibb_transfer/ibb_receiver.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -82,37 +82,34 @@ class IBBReceiver(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
- xmpp = IBBReceiver(opts.jid, opts.password)
+ xmpp = IBBReceiver(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/ibb_transfer/ibb_sender.py b/examples/ibb_transfer/ibb_sender.py
index 35a7f429..c7e87bb4 100755
--- a/examples/ibb_transfer/ibb_sender.py
+++ b/examples/ibb_transfer/ibb_sender.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -64,48 +64,45 @@ class IBBSender(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-r", "--receiver", dest="receiver",
- help="JID to use")
- optp.add_option("-f", "--file", dest="filename",
- help="JID to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-r", "--receiver", dest="receiver",
+ help="JID to use")
+ parser.add_argument("-f", "--file", dest="filename",
+ help="JID to use")
- opts, args = optp.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("Password: ")
- if opts.receiver is None:
- opts.receiver = input("Receiver: ")
- if opts.filename is None:
- opts.filename = input("File path: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.receiver is None:
+ args.receiver = input("Receiver: ")
+ if args.filename is None:
+ args.filename = input("File path: ")
# Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = IBBSender(opts.jid, opts.password, opts.receiver, opts.filename)
+ xmpp = IBBSender(args.jid, args.password, args.receiver, args.filename)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0047') # In-band Bytestreams
diff --git a/examples/migrate_roster.py b/examples/migrate_roster.py
index 599d9644..bd3bf7e6 100755
--- a/examples/migrate_roster.py
+++ b/examples/migrate_roster.py
@@ -4,55 +4,52 @@
import sys
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
# Setup the command line arguments.
-optp = OptionParser()
+parser = ArgumentParser()
# Output verbosity options.
-optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
-optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
-optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
-optp.add_option("--oldjid", dest="old_jid",
- help="JID of the old account")
-optp.add_option("--oldpassword", dest="old_password",
- help="password of the old account")
+parser.add_argument("--oldjid", dest="old_jid",
+ help="JID of the old account")
+parser.add_argument("--oldpassword", dest="old_password",
+ help="password of the old account")
-optp.add_option("--newjid", dest="new_jid",
- help="JID of the old account")
-optp.add_option("--newpassword", dest="new_password",
- help="password of the old account")
+parser.add_argument("--newjid", dest="new_jid",
+ help="JID of the old account")
+parser.add_argument("--newpassword", dest="new_password",
+ help="password of the old account")
-opts, args = optp.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.old_jid is None:
- opts.old_jid = input("Old JID: ")
-if opts.old_password is None:
- opts.old_password = getpass("Old Password: ")
+if args.old_jid is None:
+ args.old_jid = input("Old JID: ")
+if args.old_password is None:
+ args.old_password = getpass("Old Password: ")
-if opts.new_jid is None:
- opts.new_jid = input("New JID: ")
-if opts.new_password is None:
- opts.new_password = getpass("New Password: ")
+if args.new_jid is None:
+ args.new_jid = input("New JID: ")
+if args.new_password is None:
+ args.new_password = getpass("New Password: ")
-old_xmpp = slixmpp.ClientXMPP(opts.old_jid, opts.old_password)
+old_xmpp = slixmpp.ClientXMPP(args.old_jid, args.old_password)
# If you are connecting to Facebook and wish to use the
# X-FACEBOOK-PLATFORM authentication mechanism, you will need
@@ -88,7 +85,7 @@ if not roster:
print('No roster to migrate')
sys.exit()
-new_xmpp = slixmpp.ClientXMPP(opts.new_jid, opts.new_password)
+new_xmpp = slixmpp.ClientXMPP(args.new_jid, args.new_password)
def on_session2(event):
new_xmpp.get_roster()
new_xmpp.send_presence()
diff --git a/examples/muc.py b/examples/muc.py
index 4a1b36ca..5f18a143 100755
--- a/examples/muc.py
+++ b/examples/muc.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -121,48 +121,45 @@ class MUCBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-r", "--room", dest="room",
- help="MUC room to join")
- optp.add_option("-n", "--nick", dest="nick",
- help="MUC nickname")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-r", "--room", dest="room",
+ help="MUC room to join")
+ parser.add_argument("-n", "--nick", dest="nick",
+ help="MUC nickname")
- opts, args = optp.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("Password: ")
- if opts.room is None:
- opts.room = input("MUC room: ")
- if opts.nick is None:
- opts.nick = input("MUC nickname: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.room is None:
+ args.room = input("MUC room: ")
+ if args.nick is None:
+ args.nick = input("MUC nickname: ")
# Setup the MUCBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = MUCBot(opts.jid, opts.password, opts.room, opts.nick)
+ xmpp = MUCBot(args.jid, args.password, args.room, args.nick)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0045') # Multi-User Chat
xmpp.register_plugin('xep_0199') # XMPP Ping
diff --git a/examples/ping.py b/examples/ping.py
index bc35d975..06b03c51 100755
--- a/examples/ping.py
+++ b/examples/ping.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -68,43 +68,40 @@ class PingTest(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
- optp.add_option('-t', '--pingto', help='set jid to ping',
- action='store', type='string', dest='pingjid',
- default=None)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
+ parser.add_argument("-t", "--pingto", help="set jid to ping",
+ action="store", type="string", dest="pingjid",
+ default=None)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the PingTest and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = PingTest(opts.jid, opts.password, opts.pingjid)
+ xmpp = PingTest(args.jid, args.password, args.pingjid)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub
diff --git a/examples/proxy_echo_client.py b/examples/proxy_echo_client.py
index 34ed98a4..b149de31 100755
--- a/examples/proxy_echo_client.py
+++ b/examples/proxy_echo_client.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -71,58 +71,53 @@ class EchoBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("--phost", dest="proxy_host",
- help="Proxy hostname")
- optp.add_option("--pport", dest="proxy_port",
- help="Proxy port")
- optp.add_option("--puser", dest="proxy_user",
- help="Proxy username")
- optp.add_option("--ppass", dest="proxy_pass",
- help="Proxy password")
-
-
-
- opts, args = optp.parse_args()
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("--phost", dest="proxy_host",
+ help="Proxy hostname")
+ parser.add_argument("--pport", dest="proxy_port",
+ help="Proxy port")
+ parser.add_argument("--puser", dest="proxy_user",
+ help="Proxy username")
+ parser.add_argument("--ppass", dest="proxy_pass",
+ help="Proxy password")
+
+ 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("Password: ")
- if opts.proxy_host is None:
- opts.proxy_host = input("Proxy host: ")
- if opts.proxy_port is None:
- opts.proxy_port = input("Proxy port: ")
- if opts.proxy_user is None:
- opts.proxy_user = input("Proxy username: ")
- if opts.proxy_pass is None and opts.proxy_user:
- opts.proxy_pass = getpass("Proxy password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.proxy_host is None:
+ args.proxy_host = input("Proxy host: ")
+ if args.proxy_port is None:
+ args.proxy_port = input("Proxy port: ")
+ if args.proxy_user is None:
+ args.proxy_user = input("Proxy username: ")
+ if args.proxy_pass is None and args.proxy_user:
+ args.proxy_pass = getpass("Proxy password: ")
# Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = EchoBot(opts.jid, opts.password)
+ xmpp = EchoBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub
@@ -130,10 +125,10 @@ if __name__ == '__main__':
xmpp.use_proxy = True
xmpp.proxy_config = {
- 'host': opts.proxy_host,
- 'port': int(opts.proxy_port),
- 'username': opts.proxy_user,
- 'password': opts.proxy_pass}
+ 'host': args.proxy_host,
+ 'port': int(args.proxy_port),
+ 'username': args.proxy_user,
+ 'password': args.proxy_pass}
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/pubsub_client.py b/examples/pubsub_client.py
index d780ac71..fd215efd 100755
--- a/examples/pubsub_client.py
+++ b/examples/pubsub_client.py
@@ -3,7 +3,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.xmlstream import ET, tostring
@@ -111,62 +111,51 @@ class PubsubClient(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
- optp.version = '%%prog 0.1'
- optp.usage = "Usage: %%prog [options] <jid> " + \
+ parser = ArgumentParser()
+ parser.version = '%%prog 0.1'
+ parser.usage = "Usage: %%prog [options] <jid> " + \
'nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get' + \
' [<node> <data>]'
- optp.add_option('-q','--quiet', help='set logging to ERROR',
- action='store_const',
- dest='loglevel',
- const=logging.ERROR,
- default=logging.ERROR)
- optp.add_option('-d','--debug', help='set logging to DEBUG',
- action='store_const',
- dest='loglevel',
- const=logging.DEBUG,
- default=logging.ERROR)
- optp.add_option('-v','--verbose', help='set logging to COMM',
- action='store_const',
- dest='loglevel',
- const=5,
- default=logging.ERROR)
+ parser.add_argument("-q","--quiet", help="set logging to ERROR",
+ action="store_const",
+ dest="loglevel",
+ const=logging.ERROR,
+ default=logging.ERROR)
+ parser.add_argument("-d","--debug", help="set logging to DEBUG",
+ action="store_const",
+ dest="loglevel",
+ const=logging.DEBUG,
+ default=logging.ERROR)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- opts,args = optp.parse_args()
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- # Setup logging.
- logging.basicConfig(level=opts.loglevel,
- format='%(levelname)-8s %(message)s')
-
- if len(args) < 2:
- optp.print_help()
- exit()
+ parser.add_argument("server")
+ parser.add_argument("action", choice=["nodes", "create", "delete", "purge", "subscribe", "unsubscribe", "publish", "retract", "get"])
+ parser.add_argument("node", nargs='?')
+ parser.add_argument("data", nargs='?')
- if opts.jid is None:
- opts.jid = input("Username: ")
- if opts.password is None:
- opts.password = getpass("Password: ")
+ args = parser.parse_args()
- if len(args) == 2:
- args = (args[0], args[1], '', '', '')
- elif len(args) == 3:
- args = (args[0], args[1], args[2], '', '')
- elif len(args) == 4:
- args = (args[0], args[1], args[2], args[3], '')
+ # Setup logging.
+ logging.basicConfig(level=args.loglevel,
+ format='%(levelname)-8s %(message)s')
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the Pubsub client
- xmpp = PubsubClient(opts.jid, opts.password,
- server=args[0],
- node=args[2],
- action=args[1],
- data=args[3])
+ xmpp = PubsubClient(args.jid, args.password,
+ server=args.server,
+ node=args.node,
+ action=args.action,
+ data=args.data)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/pubsub_events.py b/examples/pubsub_events.py
index 20af1fbe..369d7114 100755
--- a/examples/pubsub_events.py
+++ b/examples/pubsub_events.py
@@ -3,7 +3,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.xmlstream import ET, tostring
@@ -84,41 +84,38 @@ class PubsubEvents(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
logging.info("Run this in conjunction with the pubsub_client.py " + \
"example to watch events happen as you give commands.")
# Setup the PubsubEvents listener
- xmpp = PubsubEvents(opts.jid, opts.password)
+ xmpp = PubsubEvents(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/register_account.py b/examples/register_account.py
index d26ce61e..9d6e3b8f 100755
--- a/examples/register_account.py
+++ b/examples/register_account.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.exceptions import IqError, IqTimeout
@@ -103,40 +103,37 @@ class RegisterBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
# Setup the RegisterBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = RegisterBot(opts.jid, opts.password)
+ xmpp = RegisterBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data forms
xmpp.register_plugin('xep_0066') # Out-of-band Data
diff --git a/examples/roster_browser.py b/examples/roster_browser.py
index 859ced3b..74d2839a 100755
--- a/examples/roster_browser.py
+++ b/examples/roster_browser.py
@@ -12,7 +12,7 @@
import logging
from getpass import getpass
import threading
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.exceptions import IqError, IqTimeout
@@ -101,40 +101,36 @@ class RosterBrowser(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
- optp.add_option('-q','--quiet', help='set logging to ERROR',
- action='store_const',
- dest='loglevel',
- const=logging.ERROR,
- default=logging.ERROR)
- optp.add_option('-d','--debug', help='set logging to DEBUG',
- action='store_const',
- dest='loglevel',
- const=logging.DEBUG,
- default=logging.ERROR)
- optp.add_option('-v','--verbose', help='set logging to COMM',
- action='store_const',
- dest='loglevel',
- const=5,
- default=logging.ERROR)
+ parser = ArgumentParser()
+ parser.add_argument("-q","--quiet", help="set logging to ERROR",
+ action="store_const",
+ dest="loglevel",
+ const=logging.ERROR,
+ default=logging.ERROR)
+ parser.add_argument("-d","--debug", help="set logging to DEBUG",
+ action="store_const",
+ dest="loglevel",
+ const=logging.DEBUG,
+ default=logging.ERROR)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- opts,args = optp.parse_args()
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+
+ 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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
- xmpp = RosterBrowser(opts.jid, opts.password)
+ xmpp = RosterBrowser(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/send_client.py b/examples/send_client.py
index 40bfea56..a3b11707 100755
--- a/examples/send_client.py
+++ b/examples/send_client.py
@@ -11,7 +11,7 @@
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
@@ -65,48 +65,45 @@ class SendMsgBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser(description=SendMsgBot.__doc__)
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-t", "--to", dest="to",
- help="JID to send the message to")
- optp.add_option("-m", "--message", dest="message",
- help="message to send")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-t", "--to", dest="to",
+ help="JID to send the message to")
+ parser.add_argument("-m", "--message", dest="message",
+ help="message to send")
- opts, args = optp.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("Password: ")
- if opts.to is None:
- opts.to = input("Send To: ")
- if opts.message is None:
- opts.message = input("Message: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.to is None:
+ args.to = input("Send To: ")
+ if args.message is None:
+ args.message = input("Message: ")
# Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does
# not matter.
- xmpp = SendMsgBot(opts.jid, opts.password, opts.to, opts.message)
+ xmpp = SendMsgBot(args.jid, args.password, args.to, args.message)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0199') # XMPP Ping
diff --git a/examples/set_avatar.py b/examples/set_avatar.py
index 4292c970..9a050e5a 100755
--- a/examples/set_avatar.py
+++ b/examples/set_avatar.py
@@ -14,7 +14,7 @@ import imghdr
import logging
from getpass import getpass
import threading
-from optparse import OptionParser
+from argparse import ArgumentParser
import slixmpp
from slixmpp.exceptions import XMPPError
@@ -99,44 +99,40 @@ class AvatarSetter(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
- optp.add_option('-q','--quiet', help='set logging to ERROR',
- action='store_const',
- dest='loglevel',
- const=logging.ERROR,
- default=logging.ERROR)
- optp.add_option('-d','--debug', help='set logging to DEBUG',
- action='store_const',
- dest='loglevel',
- const=logging.DEBUG,
- default=logging.ERROR)
- optp.add_option('-v','--verbose', help='set logging to COMM',
- action='store_const',
- dest='loglevel',
- const=5,
- default=logging.ERROR)
+ parser = ArgumentParser()
+ parser.add_argument("-q","--quiet", help="set logging to ERROR",
+ action="store_const",
+ dest="loglevel",
+ const=logging.ERROR,
+ default=logging.ERROR)
+ parser.add_argument("-d","--debug", help="set logging to DEBUG",
+ action="store_const",
+ dest="loglevel",
+ const=logging.DEBUG,
+ default=logging.ERROR)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
- optp.add_option("-f", "--file", dest="filepath",
- help="path to the avatar file")
- opts,args = optp.parse_args()
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
+ parser.add_argument("-f", "--file", dest="filepath",
+ help="path to the avatar file")
+
+ 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("Password: ")
- if opts.filepath is None:
- opts.filepath = input("Avatar file location: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
+ if args.filepath is None:
+ args.filepath = input("Avatar file location: ")
- xmpp = AvatarSetter(opts.jid, opts.password, opts.filepath)
+ xmpp = AvatarSetter(args.jid, args.password, args.filepath)
xmpp.register_plugin('xep_0054')
xmpp.register_plugin('xep_0153')
xmpp.register_plugin('xep_0084')
diff --git a/examples/thirdparty_auth.py b/examples/thirdparty_auth.py
index 8f402087..9318854b 100755
--- a/examples/thirdparty_auth.py
+++ b/examples/thirdparty_auth.py
@@ -12,7 +12,7 @@
import sys
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
try:
from httplib import HTTPSConnection
@@ -94,35 +94,32 @@ class ThirdPartyAuthBot(slixmpp.ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
access_token = None
@@ -146,8 +143,8 @@ if __name__ == '__main__':
params = urlencode({
'accountType': 'GOOGLE',
'service': 'mail',
- 'Email': JID(opts.jid).bare,
- 'Passwd': opts.password
+ 'Email': JID(args.jid).bare,
+ 'Passwd': args.password
})
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
@@ -198,7 +195,7 @@ if __name__ == '__main__':
# We're using an access token instead of a password, so we'll use `''` as
# a password argument filler.
- xmpp = ThirdPartyAuthBot(opts.jid, '')
+ xmpp = ThirdPartyAuthBot(args.jid, '')
xmpp.credentials['access_token'] = access_token
# The credentials dictionary is used to provide additional authentication
diff --git a/examples/user_location.py b/examples/user_location.py
index 8ad9f5c1..8840ec85 100755
--- a/examples/user_location.py
+++ b/examples/user_location.py
@@ -3,7 +3,7 @@
import sys
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
try:
import json
@@ -71,37 +71,34 @@ class LocationBot(ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
- xmpp = LocationBot(opts.jid, opts.password)
+ xmpp = LocationBot(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
diff --git a/examples/user_tune.py b/examples/user_tune.py
index a1411e9c..3f5e1c9e 100755
--- a/examples/user_tune.py
+++ b/examples/user_tune.py
@@ -3,7 +3,7 @@
import sys
import logging
from getpass import getpass
-from optparse import OptionParser
+from argparse import ArgumentParser
try:
from appscript import *
@@ -83,37 +83,34 @@ class TuneBot(ClientXMPP):
if __name__ == '__main__':
# Setup the command line arguments.
- optp = OptionParser()
+ parser = ArgumentParser()
# Output verbosity options.
- optp.add_option('-q', '--quiet', help='set logging to ERROR',
- action='store_const', dest='loglevel',
- const=logging.ERROR, default=logging.INFO)
- optp.add_option('-d', '--debug', help='set logging to DEBUG',
- action='store_const', dest='loglevel',
- const=logging.DEBUG, default=logging.INFO)
- optp.add_option('-v', '--verbose', help='set logging to COMM',
- action='store_const', dest='loglevel',
- const=5, default=logging.INFO)
+ parser.add_argument("-q", "--quiet", help="set logging to ERROR",
+ action="store_const", dest="loglevel",
+ const=logging.ERROR, default=logging.INFO)
+ parser.add_argument("-d", "--debug", help="set logging to DEBUG",
+ action="store_const", dest="loglevel",
+ const=logging.DEBUG, default=logging.INFO)
# JID and password options.
- optp.add_option("-j", "--jid", dest="jid",
- help="JID to use")
- optp.add_option("-p", "--password", dest="password",
- help="password to use")
+ parser.add_argument("-j", "--jid", dest="jid",
+ help="JID to use")
+ parser.add_argument("-p", "--password", dest="password",
+ help="password to use")
- opts, args = optp.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("Password: ")
+ if args.jid is None:
+ args.jid = input("Username: ")
+ if args.password is None:
+ args.password = getpass("Password: ")
- xmpp = TuneBot(opts.jid, opts.password)
+ xmpp = TuneBot(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()