Ticket #4280 task closed invalid
Remove pattern "except:"
| Reported by: | eYemZ | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | Branch: | ||
| Author: | Launchpad Bug: |
Description
This caught anything not only Exception. http://docs.python.org/howto/doanddont.html#except
find . -iname '*.py' -exec sed -i 's/except:/except Exception:/g' {} \;
# Import from the standard library
from logging import debug
from sys import exit
# Import from twisted
from twisted.internet import reactor
from twisted.names.srvconnect import SRVConnector
from twisted.words.protocols.jabber import xmlstream, client, jid
from twisted.words.xish import domish
# Import from here
from utils import get_template
class XMPPClientConnector(SRVConnector):
def __init__(self, reactor, domain, factory):
SRVConnector.__init__(self, reactor, 'xmpp-client', domain, factory)
def pickServer(self):
host, port = SRVConnector.pickServer(self)
if not self.servers and not self.orderedServers:
# no SRV record, fall back..
port = 5222
return host, port
class XMPPSession(object):
resource = 'SharingShell'
def __init__(self, client_jid, password):
debug('jid: "%s" password: "%s"' % (client_jid, len(password) * '*'))
client_jid = '%s/%s' % (client_jid, self.resource)
self.jid = jid.JID(client_jid, password)
session = client.XMPPClientFactory(self.jid, password)
session.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected)
session.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected)
session.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated)
session.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed)
connector = XMPPClientConnector(reactor, self.jid.host, session)
connector.connect()
def connected(self, message):
debug('Connected')
def disconnected(self, message):
debug('Disconnected')
def authenticated(self, stream):
debug('Authenticated')
self.xmpp_stream = stream
presence = domish.Element((None, 'presence'))
self.xmpp_stream.send(presence)
# Warn the contact when he try to speak to the bot client
self.xmpp_stream.addObserver('/message/body', self.warn_contact)
def init_failed(self, failure):
debug("Initialization failed.")
print failure
###########################################################
# exit is caught by "except:"
exit(3)
###########################################################
def warn_contact(self, message):
warn_template = get_template('warn.xml')
namespace = {'contact': message['from'],
'jid': self.jid}
warn_message = warn_template.render_unicode(**namespace)
self.xmpp_stream.send(warn_message)
def run(self):
reactor.run()
Change History
Note: See
TracTickets for help on using
tickets.
