mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 11:09:56 +00:00
Tidy up the examples.
This commit is contained in:
parent
d6f2e51b05
commit
4916a12b6f
3 changed files with 19 additions and 14 deletions
|
@ -113,7 +113,7 @@ class Disco(sleekxmpp.ClientXMPP):
|
||||||
if self.get in self.identity_types:
|
if self.get in self.identity_types:
|
||||||
print('Identities:')
|
print('Identities:')
|
||||||
for identity in info['disco_info']['identities']:
|
for identity in info['disco_info']['identities']:
|
||||||
print(' - ', identity)
|
print(' - %s' % str(identity))
|
||||||
|
|
||||||
if self.get in self.feature_types:
|
if self.get in self.feature_types:
|
||||||
print('Features:')
|
print('Features:')
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
import getpass
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
|
@ -60,8 +61,8 @@ class EchoBot(sleekxmpp.ClientXMPP):
|
||||||
event does not provide any additional
|
event does not provide any additional
|
||||||
data.
|
data.
|
||||||
"""
|
"""
|
||||||
self.getRoster()
|
self.send_presence()
|
||||||
self.sendPresence()
|
self.get_roster()
|
||||||
|
|
||||||
def message(self, msg):
|
def message(self, msg):
|
||||||
"""
|
"""
|
||||||
|
@ -105,18 +106,19 @@ if __name__ == '__main__':
|
||||||
logging.basicConfig(level=opts.loglevel,
|
logging.basicConfig(level=opts.loglevel,
|
||||||
format='%(levelname)-8s %(message)s')
|
format='%(levelname)-8s %(message)s')
|
||||||
|
|
||||||
if None in [opts.jid, opts.password]:
|
if opts.jid is None:
|
||||||
optp.print_help()
|
opts.jid = raw_input("Username: ")
|
||||||
sys.exit(1)
|
if opts.password is None:
|
||||||
|
opts.password = getpass.getpass("Password: ")
|
||||||
|
|
||||||
# Setup the EchoBot and register plugins. Note that while plugins may
|
# Setup the EchoBot and register plugins. Note that while plugins may
|
||||||
# have interdependencies, the order in which you register them does
|
# have interdependencies, the order in which you register them does
|
||||||
# not matter.
|
# not matter.
|
||||||
xmpp = EchoBot(opts.jid, opts.password)
|
xmpp = EchoBot(opts.jid, opts.password)
|
||||||
xmpp.registerPlugin('xep_0030') # Service Discovery
|
xmpp.register_plugin('xep_0030') # Service Discovery
|
||||||
xmpp.registerPlugin('xep_0004') # Data Forms
|
xmpp.register_plugin('xep_0004') # Data Forms
|
||||||
xmpp.registerPlugin('xep_0060') # PubSub
|
xmpp.register_plugin('xep_0060') # PubSub
|
||||||
xmpp.registerPlugin('xep_0199') # XMPP Ping
|
xmpp.register_plugin('xep_0199') # XMPP Ping
|
||||||
|
|
||||||
# If you are working with an OpenFire server, you may need
|
# If you are working with an OpenFire server, you may need
|
||||||
# to adjust the SSL version used:
|
# to adjust the SSL version used:
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
import getpass
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
|
@ -58,7 +59,8 @@ class PingTest(sleekxmpp.ClientXMPP):
|
||||||
event does not provide any additional
|
event does not provide any additional
|
||||||
data.
|
data.
|
||||||
"""
|
"""
|
||||||
self.sendPresence()
|
self.send_presence()
|
||||||
|
self.get_roster()
|
||||||
result = self['xep_0199'].send_ping(self.pingjid,
|
result = self['xep_0199'].send_ping(self.pingjid,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
errorfalse=True)
|
errorfalse=True)
|
||||||
|
@ -102,9 +104,10 @@ if __name__ == '__main__':
|
||||||
logging.basicConfig(level=opts.loglevel,
|
logging.basicConfig(level=opts.loglevel,
|
||||||
format='%(levelname)-8s %(message)s')
|
format='%(levelname)-8s %(message)s')
|
||||||
|
|
||||||
if None in [opts.jid, opts.password]:
|
if opts.jid is None:
|
||||||
optp.print_help()
|
opts.jid = raw_input("Username: ")
|
||||||
sys.exit(1)
|
if opts.password is None:
|
||||||
|
opts.password = getpass.getpass("Password: ")
|
||||||
|
|
||||||
# Setup the PingTest and register plugins. Note that while plugins may
|
# Setup the PingTest and register plugins. Note that while plugins may
|
||||||
# have interdependencies, the order in which you register them does
|
# have interdependencies, the order in which you register them does
|
||||||
|
|
Loading…
Reference in a new issue