changeset ffa6dc7501b6 in /home/hg/repos/python-nbxmpp
details:http://hg.gajim.org/python-nbxmpp?cmd=changeset;node=ffa6dc7501b6 description: make xsend work with python3
diffstat:
README | 2 +- doc/examples/xsend.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-)
diffs (89 lines):
diff -r cd50e6d917aa -r ffa6dc7501b6 README --- a/README Thu Jul 16 21:11:51 2015 +0200 +++ b/README Sun Jul 26 13:10:42 2015 +0200 @@ -11,7 +11,7 @@
Usage
-You have to 'import xmpppy' in your program. Then look at examples in ths doc +You have to 'import xmpppy' in your program. Then look at examples in the doc folder.
2012-05-08 Yann Leboulanger diff -r cd50e6d917aa -r ffa6dc7501b6 doc/examples/xsend.py --- a/doc/examples/xsend.py Thu Jul 16 21:11:51 2015 +0200 +++ b/doc/examples/xsend.py Sun Jul 26 13:10:42 2015 +0200 @@ -1,11 +1,14 @@ -#!/usr/bin/python +#!/usr/bin/python3
import sys import os import nbxmpp import time import logging -import gobject +try: + from gi.repository import GObject as gobject +except Exception: + import gobject
consoleloghandler = logging.StreamHandler() root_log = logging.getLogger('nbxmpp') @@ -13,7 +16,7 @@ root_log.addHandler(consoleloghandler)
if len(sys.argv) < 2: - print "Syntax: xsend JID text" + print("Syntax: xsend JID text") sys.exit(0)
to_jid = sys.argv[1] @@ -28,7 +31,7 @@ for mandatory in ['jid', 'password']: if mandatory not in jidparams.keys(): open(os.environ['HOME']+'/.xsend','w').write('#Uncomment fields before use and type in correct credentials.\n#JID=romeo@montague.net/resource (/resource is optional)\n#PASSWORD=juliet\n') - print 'Please point ~/.xsend config file to valid JID for sending messages.' + print('Please point ~/.xsend config file to valid JID for sending messages.') sys.exit(0)
class Connection: @@ -40,20 +43,20 @@
def on_auth(self, con, auth): if not auth: - print 'could not authenticate!' + print('could not authenticate!') sys.exit() - print 'authenticated using', auth + print('authenticated using ' + auth) self.send_message(to_jid, text)
def on_connected(self, con, con_type): - print 'connected with', con_type + print('connected with ' + con_type) auth = self.client.auth(self.jid.getNode(), self.password, resource=self.jid.getResource(), sasl=1, on_auth=self.on_auth)
def get_password(self, cb, mech): cb(self.password)
def on_connection_failed(self): - print 'could not connect!' + print('could not connect!')
def _event_dispatcher(self, realm, event, data): pass @@ -61,11 +64,11 @@ def connect(self): idle_queue = nbxmpp.idlequeue.get_idlequeue() self.client = nbxmpp.NonBlockingClient(self.jid.getDomain(), idle_queue, caller=self) - self.con = self.client.connect(self.on_connected, self.on_connection_failed, secure_tuple=('tls', '', '', None)) + self.con = self.client.connect(self.on_connected, self.on_connection_failed, secure_tuple=('tls', '', '', None, None))
def send_message(self, to_jid, text): id_ = self.client.send(nbxmpp.protocol.Message(to_jid, text, typ='chat')) - print 'sent message with id', id_ + print('sent message with id ' + id_) gobject.timeout_add(1000, self.quit)
def quit(self):