coding standards

This commit is contained in:
Yann Leboulanger 2010-10-06 21:11:23 +02:00
parent 3876638860
commit d39a962157

View file

@ -124,8 +124,8 @@ class ConnectionDisco:
iq.setID(id_)
# Wait the answer during 30 secondes
self.awaiting_timeouts[gajim.idlequeue.current_time() + 30] = (id_,
_('Registration information for transport %s has not arrived in time')\
% agent)
_('Registration information for transport %s has not arrived in '
'time') % agent)
self.connection.SendAndCallForResponse(iq, self._ReceivedRegInfo,
{'agent': agent})
@ -140,9 +140,9 @@ class ConnectionDisco:
p = self.add_sha(p)
self.connection.send(p)
if resp.getType() == 'error':
self.dispatch('ERROR', (_('Registration failed'), _('Registration with'
' agent %(agent)s failed with error %(error)s: %(error_msg)s') % {
'agent': agent, 'error': resp.getError(),
self.dispatch('ERROR', (_('Registration failed'), _('Registration '
'with agent %(agent)s failed with error %(error)s: '
'%(error_msg)s') % {'agent': agent, 'error': resp.getError(),
'error_msg': resp.getErrorMsg()}))
def register_agent(self, agent, info, is_form=False):
@ -153,8 +153,8 @@ class ConnectionDisco:
query = iq.getTag('query')
info.setAttr('type', 'submit')
query.addChild(node=info)
self.connection.SendAndCallForResponse(iq, self._agent_registered_cb,
{'agent': agent})
self.connection.SendAndCallForResponse(iq,
self._agent_registered_cb, {'agent': agent})
else:
# fixed: blocking
common.xmpp.features_nb.register(self.connection, agent, info,
@ -190,7 +190,8 @@ class ConnectionDisco:
frm=to)
iq.setAttr('id', id_)
query = iq.setTag('query')
query.setAttr('node', 'http://gajim.org#' + gajim.version.split('-', 1)[0])
query.setAttr('node', 'http://gajim.org#' + gajim.version.split('-', 1)[
0])
for f in (common.xmpp.NS_BYTESTREAM, common.xmpp.NS_SI,
common.xmpp.NS_FILE, common.xmpp.NS_COMMANDS):
feature = common.xmpp.Node('feature')
@ -320,12 +321,10 @@ class ConnectionDisco:
attr = {}
for key in i.getAttrs().keys():
attr[key] = i.getAttr(key)
if 'category' in attr and \
attr['category'] in ('gateway', 'headline') and \
'type' in attr:
if 'category' in attr and attr['category'] in ('gateway',
'headline') and 'type' in attr:
transport_type = attr['type']
if 'category' in attr and \
attr['category'] == 'conference' and \
if 'category' in attr and attr['category'] == 'conference' and \
'type' in attr and attr['type'] == 'text':
is_muc = True
identities.append(attr)
@ -341,9 +340,11 @@ class ConnectionDisco:
gajim.logger.save_transport_type(jid, transport_type)
id_ = iq_obj.getID()
if id_ is None:
log.warn('Invalid IQ received without an ID. Ignoring it: %s' % iq_obj)
log.warn('Invalid IQ received without an ID. Ignoring it: %s' % \
iq_obj)
return
if not identities: # ejabberd doesn't send identities when we browse online users
if not identities:
# ejabberd doesn't send identities when we browse online users
#FIXME: see http://www.jabber.ru/bugzilla/show_bug.cgi?id=225
identities = [{'category': 'server', 'type': 'im', 'name': node}]
if id_[:6] == 'Gajim_':
@ -354,8 +355,8 @@ class ConnectionDisco:
if features.__contains__(common.xmpp.NS_SECLABEL):
self.seclabel_supported = True
for identity in identities:
if identity['category'] == 'pubsub' and identity.get('type') == \
'pep':
if identity['category'] == 'pubsub' and identity.get(
'type') == 'pep':
self.pep_supported = True
break
if features.__contains__(common.xmpp.NS_VCARD):
@ -397,15 +398,16 @@ class ConnectionDisco:
self.privacy_rules_requested = True
self._request_privacy()
self.dispatch('AGENT_INFO_INFO', (jid, node, identities,
features, data))
self.dispatch('AGENT_INFO_INFO', (jid, node, identities, features,
data))
self._capsDiscoCB(jid, node, identities, features, data)
class ConnectionVcard:
def __init__(self):
self.vcard_sha = None
self.vcard_shas = {} # sha of contacts
self.room_jids = [] # list of gc jids so that vcard are saved in a folder
# list of gc jids so that vcard are saved in a folder
self.room_jids = []
def add_sha(self, p, send_caps=True):
c = p.setTag('x', namespace=common.xmpp.NS_VCARD_UPDATE)
@ -591,7 +593,8 @@ class ConnectionVcard:
if iq_obj.getType() == 'result':
vcard_iq = self.awaiting_answers[id_][1]
# Save vcard to HD
if vcard_iq.getTag('PHOTO') and vcard_iq.getTag('PHOTO').getTag('SHA'):
if vcard_iq.getTag('PHOTO') and vcard_iq.getTag('PHOTO').getTag(
'SHA'):
new_sha = vcard_iq.getTag('PHOTO').getTagData('SHA')
else:
new_sha = ''
@ -601,12 +604,13 @@ class ConnectionVcard:
self._save_vcard_to_hd(our_jid, vcard_iq)
# Send new presence if sha changed and we are not invisible
if self.vcard_sha != new_sha and gajim.SHOW_LIST[self.connected] !=\
'invisible':
if self.vcard_sha != new_sha and gajim.SHOW_LIST[
self.connected] != 'invisible':
if not self.connection or self.connected < 2:
return
self.vcard_sha = new_sha
sshow = helpers.get_xmpp_show(gajim.SHOW_LIST[self.connected])
sshow = helpers.get_xmpp_show(gajim.SHOW_LIST[
self.connected])
p = common.xmpp.Presence(typ=None, priority=self.priority,
show=sshow, status=self.status)
p = self.add_sha(p)
@ -696,11 +700,13 @@ class ConnectionVcard:
self.get_privacy_list('block')
elif self.continue_connect_info:
if self.continue_connect_info[0] == 'invisible':
# Trying to login as invisible but privacy list not supported
# Trying to login as invisible but privacy list not
# supported
self.disconnect(on_purpose=True)
self.dispatch('STATUS', 'offline')
self.dispatch('ERROR', (_('Invisibility not supported'),
_('Account %s doesn\'t support invisibility.') % self.name))
_('Account %s doesn\'t support invisibility.') % \
self.name))
return
# Ask metacontacts before roster
self.get_metacontacts()
@ -825,7 +831,8 @@ class ConnectionVcard:
# Save it to file
self._save_vcard_to_hd(who, card)
# Save the decoded avatar to a separate file too, and generate files for dbus notifications
# Save the decoded avatar to a separate file too, and generate files
# for dbus notifications
puny_jid = helpers.sanitize_filename(frm)
puny_nick = None
begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid)
@ -992,7 +999,8 @@ class ConnectionHandlersBase:
if chat_sessions:
# return the session that we last sent a message in
return sorted(chat_sessions, key=operator.attrgetter("last_send"))[-1]
return sorted(chat_sessions, key=operator.attrgetter('last_send'))[
-1]
else:
return None
@ -1074,7 +1082,6 @@ ConnectionJingle, ConnectionIBBytestream):
try:
self.sleeper = common.sleepy.Sleepy()
# idle.init()
HAS_IDLE = True
except Exception:
HAS_IDLE = False
@ -1237,8 +1244,8 @@ ConnectionJingle, ConnectionIBBytestream):
for jid in obj.items:
item = obj.items[jid]
gajim.nec.push_incoming_event(RosterInfoEvent(None, conn=self,
jid=jid, nickname=item['name'], sub=item['sub'], ask=item['ask'],
groups=item['groups']))
jid=jid, nickname=item['name'], sub=item['sub'],
ask=item['ask'], groups=item['groups']))
account_jid = gajim.get_jid_from_account(self.name)
gajim.logger.add_or_update_contact(account_jid, jid, item['name'],
item['sub'], item['ask'], item['groups'])
@ -1250,8 +1257,8 @@ ConnectionJingle, ConnectionIBBytestream):
log.debug('VersionCB')
if not self.connection or self.connected < 2:
return
gajim.nec.push_incoming_event(VersionRequestEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(VersionRequestEvent(None, conn=self,
iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _nec_version_request_received(self, obj):
@ -1270,8 +1277,8 @@ ConnectionJingle, ConnectionIBBytestream):
log.debug('LastCB')
if not self.connection or self.connected < 2:
return
gajim.nec.push_incoming_event(LastRequestEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(LastRequestEvent(None, conn=self,
iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _nec_last_request_received(self, obj):
@ -1299,8 +1306,8 @@ ConnectionJingle, ConnectionIBBytestream):
log.debug('TimeCB')
if not self.connection or self.connected < 2:
return
gajim.nec.push_incoming_event(TimeRequestEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(TimeRequestEvent(None, conn=self,
iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _nec_time_request_received(self, obj):
@ -1318,8 +1325,8 @@ ConnectionJingle, ConnectionIBBytestream):
log.debug('TimeRevisedCB')
if not self.connection or self.connected < 2:
return
gajim.nec.push_incoming_event(TimeRevisedRequestEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(TimeRevisedRequestEvent(None, conn=self,
iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _nec_time_revised_request_received(self, obj):
@ -1336,16 +1343,16 @@ ConnectionJingle, ConnectionIBBytestream):
def _TimeRevisedResultCB(self, con, iq_obj):
log.debug('TimeRevisedResultCB')
gajim.nec.push_incoming_event(TimeResultReceivedEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(TimeResultReceivedEvent(None, conn=self,
iq_obj=iq_obj))
def _gMailNewMailCB(self, con, iq_obj):
"""
Called when we get notified of new mail messages in gmail account
"""
log.debug('gMailNewMailCB')
gajim.nec.push_incoming_event(GmailNewMailReceivedEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(GmailNewMailReceivedEvent(None, conn=self,
iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _nec_gmail_new_mail_received(self, obj):
@ -1373,8 +1380,8 @@ ConnectionJingle, ConnectionIBBytestream):
in gmail account
"""
log.debug('gMailQueryCB')
gajim.nec.push_incoming_event(GMailQueryReceivedEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(GMailQueryReceivedEvent(None, conn=self,
iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _rosterItemExchangeCB(self, con, msg):
@ -1382,8 +1389,8 @@ ConnectionJingle, ConnectionIBBytestream):
XEP-0144 Roster Item Echange
"""
log.debug('rosterItemExchangeCB')
gajim.nec.push_incoming_event(RosterItemExchangeEvent(None,
conn=self, iq_obj=msg))
gajim.nec.push_incoming_event(RosterItemExchangeEvent(None, conn=self,
iq_obj=msg))
raise common.xmpp.NodeProcessed
def _messageCB(self, con, msg):
@ -1412,7 +1419,8 @@ ConnectionJingle, ConnectionIBBytestream):
jid = helpers.get_jid_from_iq(msg)
except helpers.InvalidFormat:
self.dispatch('ERROR', (_('Invalid Jabber ID'),
_('A message from a non-valid JID arrived, it has been ignored.')))
_('A message from a non-valid JID arrived, it has been '
'ignored.')))
return
addressTag = msg.getTag('addresses', namespace=common.xmpp.NS_ADDRESS)
@ -1424,7 +1432,8 @@ ConnectionJingle, ConnectionIBBytestream):
try:
frm = helpers.parse_jid(address.getAttr('jid'))
except common.helpers.InvalidFormat:
log.warn('Invalid JID: %s, ignoring it' % address.getAttr('jid'))
log.warn('Invalid JID: %s, ignoring it' % address.getAttr(
'jid'))
return
jid = gajim.get_jid_without_resource(frm)
@ -1446,7 +1455,8 @@ ConnectionJingle, ConnectionIBBytestream):
try:
room_jid = helpers.parse_jid(xtag.getAttr('jid'))
except common.helpers.InvalidFormat:
log.warn('Invalid JID: %s, ignoring it' % xtag.getAttr('jid'))
log.warn('Invalid JID: %s, ignoring it' % xtag.getAttr(
'jid'))
continue
is_continued = False
if xtag.getTag('continue'):
@ -1463,7 +1473,8 @@ ConnectionJingle, ConnectionIBBytestream):
msgtxt = msg.getBody()
encrypted = False
xep_200_encrypted = msg.getTag('c', namespace=common.xmpp.NS_STANZA_CRYPTO)
xep_200_encrypted = msg.getTag('c',
namespace=common.xmpp.NS_STANZA_CRYPTO)
session = None
gc_control = gajim.interface.msg_win_mgr.get_gc_control(jid, self.name)
@ -1485,7 +1496,8 @@ ConnectionJingle, ConnectionIBBytestream):
# check if the message is a XEP-0020 feature negotiation request
if msg.getTag('feature', namespace=common.xmpp.NS_FEATURE):
if gajim.HAVE_PYCRYPTO:
feature = msg.getTag(name='feature', namespace=common.xmpp.NS_FEATURE)
feature = msg.getTag(name='feature',
namespace=common.xmpp.NS_FEATURE)
form = common.xmpp.DataForm(node=feature.getTag('x'))
if form['FORM_TYPE'] == 'urn:xmpp:ssn':
@ -1495,7 +1507,8 @@ ConnectionJingle, ConnectionIBBytestream):
reply.setType('error')
reply.addChild(feature)
err = common.xmpp.ErrorNode('service-unavailable', typ='cancel')
err = common.xmpp.ErrorNode('service-unavailable',
typ='cancel')
reply.addChild(node=err)
con.send(reply)
@ -1505,7 +1518,8 @@ ConnectionJingle, ConnectionIBBytestream):
return
if msg.getTag('init', namespace=common.xmpp.NS_ESESSION_INIT):
init = msg.getTag(name='init', namespace=common.xmpp.NS_ESESSION_INIT)
init = msg.getTag(name='init',
namespace=common.xmpp.NS_ESESSION_INIT)
form = common.xmpp.DataForm(node=init.getTag('x'))
session.handle_negotiation(form)
@ -1564,8 +1578,8 @@ ConnectionJingle, ConnectionIBBytestream):
self._on_message_decrypted, [mtype, msg, session, frm, jid,
invite, tim])
return
self._on_message_decrypted((msgtxt, encrypted), mtype, msg, session, frm,
jid, invite, tim)
self._on_message_decrypted((msgtxt, encrypted), mtype, msg, session,
frm, jid, invite, tim)
def _on_message_decrypted(self, output, mtype, msg, session, frm, jid,
invite, tim):
@ -1601,9 +1615,10 @@ ConnectionJingle, ConnectionIBBytestream):
self.dispatch('DB_ERROR', (_('Disk Write Error'), str(e)))
except exceptions.DatabaseMalformed:
pritext = _('Database Error')
sectext = _('The database file (%s) cannot be read. Try to repair '
'it (see http://trac.gajim.org/wiki/DatabaseBackup) or remove '
'it (all history will be lost).') % common.logger.LOG_DB_PATH
sectext = _('The database file (%s) cannot be read. Try to '
'repair it (see http://trac.gajim.org/wiki/DatabaseBackup) '
'or remove it (all history will be lost).') % \
common.logger.LOG_DB_PATH
self.dispatch('DB_ERROR', (pritext, sectext))
self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt,
tim, session))
@ -1680,7 +1695,9 @@ ConnectionJingle, ConnectionIBBytestream):
displaymarking = None
seclabel = msg.getTag('securitylabel')
if seclabel and seclabel.getNamespace() == common.xmpp.NS_SECLABEL:
displaymarking = seclabel.getTag('displaymarking') # Ignore message from room in which we are not
# Ignore message from room in which we are not
displaymarking = seclabel.getTag('displaymarking')
if jid not in self.last_history_time:
return
@ -1724,9 +1741,10 @@ ConnectionJingle, ConnectionIBBytestream):
self.dispatch('DB_ERROR', (_('Disk Write Error'), str(e)))
except exceptions.DatabaseMalformed:
pritext = _('Database Error')
sectext = _('The database file (%s) cannot be read. Try to repair '
'it (see http://trac.gajim.org/wiki/DatabaseBackup) or remove '
'it (all history will be lost).') % common.logger.LOG_DB_PATH
sectext = _('The database file (%s) cannot be read. Try to '
'repair it (see http://trac.gajim.org/wiki/DatabaseBackup) '
'or remove it (all history will be lost).') % \
common.logger.LOG_DB_PATH
self.dispatch('DB_ERROR', (pritext, sectext))
def dispatch_invite_message(self, invite, frm):
@ -1914,9 +1932,8 @@ ConnectionJingle, ConnectionIBBytestream):
except exceptions.DatabaseMalformed:
pritext = _('Database Error')
sectext = _('The database file (%s) cannot be read. Try to '
'repair it (see '
'http://trac.gajim.org/wiki/DatabaseBackup) or remove '
'it (all history will be lost).') % LOG_DB_PATH
'repair it (see http://trac.gajim.org/wiki/DatabaseBackup) '
'or remove it (all history will be lost).') % LOG_DB_PATH
self.dispatch('DB_ERROR', (pritext, sectext))
our_jid = gajim.get_jid_from_account(self.name)
@ -2013,13 +2030,13 @@ ConnectionJingle, ConnectionIBBytestream):
def _MucOwnerCB(self, con, iq_obj):
log.debug('MucOwnerCB')
gajim.nec.push_incoming_event(MucOwnerReceivedEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(MucOwnerReceivedEvent(None, conn=self,
iq_obj=iq_obj))
def _MucAdminCB(self, con, iq_obj):
log.debug('MucAdminCB')
gajim.nec.push_incoming_event(MucAdminReceivedEvent(None,
conn=self, iq_obj=iq_obj))
gajim.nec.push_incoming_event(MucAdminReceivedEvent(None, conn=self,
iq_obj=iq_obj))
def _IqPingCB(self, con, iq_obj):
log.debug('IqPingCB')
@ -2085,11 +2102,13 @@ ConnectionJingle, ConnectionIBBytestream):
signed = ''
send_first_presence = True
if sign_msg:
signed = self.get_signed_presence(msg, self._send_first_presence)
signed = self.get_signed_presence(msg,
self._send_first_presence)
if signed is None:
self.dispatch('GPG_PASSWORD_REQUIRED',
(self._send_first_presence,))
# _send_first_presence will be called when user enter passphrase
# _send_first_presence will be called when user enter
# passphrase
send_first_presence = False
if send_first_presence:
self._send_first_presence(signed)
@ -2185,7 +2204,6 @@ ConnectionJingle, ConnectionIBBytestream):
query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
self.connection.send(iq)
def _SearchCB(self, con, iq_obj):
log.debug('SearchCB')
gajim.nec.push_incoming_event(SearchFormReceivedEvent(None,
@ -2204,23 +2222,18 @@ ConnectionJingle, ConnectionIBBytestream):
con.RegisterHandler('presence', self._capsPresenceCB)
# We use makefirst so that this handler is called before _messageCB, and
# can prevent calling it when it's not needed.
# We also don't check for namespace, else it cannot stop _messageCB to be
# called
# We also don't check for namespace, else it cannot stop _messageCB to
# be called
con.RegisterHandler('message', self._pubsubEventCB, makefirst=True)
con.RegisterHandler('iq', self._vCardCB, 'result',
common.xmpp.NS_VCARD)
con.RegisterHandler('iq', self._vCardCB, 'result', common.xmpp.NS_VCARD)
con.RegisterHandler('iq', self._rosterSetCB, 'set',
common.xmpp.NS_ROSTER)
con.RegisterHandler('iq', self._siSetCB, 'set',
common.xmpp.NS_SI)
con.RegisterHandler('iq', self._siSetCB, 'set', common.xmpp.NS_SI)
con.RegisterHandler('iq', self._rosterItemExchangeCB, 'set',
common.xmpp.NS_ROSTERX)
con.RegisterHandler('iq', self._siErrorCB, 'error',
common.xmpp.NS_SI)
con.RegisterHandler('iq', self._siResultCB, 'result',
common.xmpp.NS_SI)
con.RegisterHandler('iq', self._discoGetCB, 'get',
common.xmpp.NS_DISCO)
con.RegisterHandler('iq', self._siErrorCB, 'error', common.xmpp.NS_SI)
con.RegisterHandler('iq', self._siResultCB, 'result', common.xmpp.NS_SI)
con.RegisterHandler('iq', self._discoGetCB, 'get', common.xmpp.NS_DISCO)
con.RegisterHandler('iq', self._bytestreamSetCB, 'set',
common.xmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamResultCB, 'result',
@ -2241,12 +2254,10 @@ ConnectionJingle, ConnectionIBBytestream):
common.xmpp.NS_DISCO_INFO)
con.RegisterHandler('iq', self._VersionCB, 'get',
common.xmpp.NS_VERSION)
con.RegisterHandler('iq', self._TimeCB, 'get',
common.xmpp.NS_TIME)
con.RegisterHandler('iq', self._TimeCB, 'get', common.xmpp.NS_TIME)
con.RegisterHandler('iq', self._TimeRevisedCB, 'get',
common.xmpp.NS_TIME_REVISED)
con.RegisterHandler('iq', self._LastCB, 'get',
common.xmpp.NS_LAST)
con.RegisterHandler('iq', self._LastCB, 'get', common.xmpp.NS_LAST)
con.RegisterHandler('iq', self._LastResultCB, 'result',
common.xmpp.NS_LAST)
con.RegisterHandler('iq', self._VersionResultCB, 'result',
@ -2273,8 +2284,7 @@ ConnectionJingle, ConnectionIBBytestream):
common.xmpp.NS_DISCO_INFO)
con.RegisterHandler('iq', self._DiscoverItemsGetCB, 'get',
common.xmpp.NS_DISCO_ITEMS)
con.RegisterHandler('iq', self._IqPingCB, 'get',
common.xmpp.NS_PING)
con.RegisterHandler('iq', self._IqPingCB, 'get', common.xmpp.NS_PING)
con.RegisterHandler('iq', self._SearchCB, 'result',
common.xmpp.NS_SEARCH)
con.RegisterHandler('iq', self._PrivacySetCB, 'set',
@ -2284,12 +2294,12 @@ ConnectionJingle, ConnectionIBBytestream):
con.RegisterHandler('iq', self._PubSubErrorCB, 'error')
con.RegisterHandler('iq', self._JingleCB, 'result')
con.RegisterHandler('iq', self._JingleCB, 'error')
con.RegisterHandler('iq', self._JingleCB, 'set',
common.xmpp.NS_JINGLE)
con.RegisterHandler('iq', self._JingleCB, 'set', common.xmpp.NS_JINGLE)
con.RegisterHandler('iq', self._ErrorCB, 'error')
con.RegisterHandler('iq', self._IqCB)
con.RegisterHandler('iq', self._StanzaArrivedCB)
con.RegisterHandler('iq', self._ResultCB, 'result')
con.RegisterHandler('presence', self._StanzaArrivedCB)
con.RegisterHandler('message', self._StanzaArrivedCB)
con.RegisterHandler('unknown', self._StreamCB, 'urn:ietf:params:xml:ns:xmpp-streams', xmlns='http://etherx.jabber.org/streams')
con.RegisterHandler('unknown', self._StreamCB,
common.xmpp.NS_XMPP_STREAMS, xmlns=common.xmpp.NS_STREAMS)