refactor a var

This commit is contained in:
Yann Leboulanger 2005-10-04 10:49:58 +00:00
parent eab959790e
commit c4e9be83cd

View file

@ -260,6 +260,7 @@ class Connection:
tim = msg.getTimestamp() tim = msg.getTimestamp()
tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') tim = time.strptime(tim, '%Y%m%dT%H:%M:%S')
tim = time.localtime(timegm(tim)) tim = time.localtime(timegm(tim))
frm = unicode(msg.getFrom())
encrypted = False encrypted = False
chatstate = None chatstate = None
xtags = msg.getTags('x') xtags = msg.getTags('x')
@ -293,28 +294,27 @@ class Connection:
msgtxt = decmsg msgtxt = decmsg
encrypted = True encrypted = True
if mtype == 'error': if mtype == 'error':
self.dispatch('MSGERROR', (unicode(msg.getFrom()), self.dispatch('MSGERROR', (frm, msg.getErrorCode(), msg.getError(),
msg.getErrorCode(), msg.getError(), msgtxt, tim)) msgtxt, tim))
elif mtype == 'groupchat': elif mtype == 'groupchat':
if subject: if subject:
self.dispatch('GC_SUBJECT', (unicode(msg.getFrom()), subject)) self.dispatch('GC_SUBJECT', (frm, subject))
else: else:
if not msg.getTag('body'): #no <body> if not msg.getTag('body'): #no <body>
return return
self.dispatch('GC_MSG', (unicode(msg.getFrom()), msgtxt, tim)) self.dispatch('GC_MSG', (frm, msgtxt, tim))
gajim.logger.write('gc', msgtxt, unicode(msg.getFrom()), gajim.logger.write('gc', msgtxt, unicode(msg.getFrom()),
tim = tim) tim = tim)
elif mtype == 'normal': # it's single message elif mtype == 'normal': # it's single message
log_msgtxt = msgtxt log_msgtxt = msgtxt
if subject: if subject:
log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt)
gajim.logger.write('incoming', log_msgtxt, unicode(msg.getFrom()), gajim.logger.write('incoming', log_msgtxt, frm, tim = tim)
tim = tim)
if invite is not None: if invite is not None:
self.dispatch('GC_INVITATION',(unicode(msg.getFrom()), invite)) self.dispatch('GC_INVITATION',(frm, invite))
else: else:
self.dispatch('MSG', (unicode(msg.getFrom()), msgtxt, tim, self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject,
encrypted, mtype, subject, None)) None))
else: # it's type 'chat' else: # it's type 'chat'
if not msg.getTag('body') and chatstate is None: #no <body> if not msg.getTag('body') and chatstate is None: #no <body>
return return
@ -322,10 +322,9 @@ class Connection:
if subject: if subject:
log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt)
if msg.getTag('body'): if msg.getTag('body'):
gajim.logger.write('incoming', log_msgtxt, gajim.logger.write('incoming', log_msgtxt, frm, tim = tim)
unicode(msg.getFrom()), tim = tim) self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject,
self.dispatch('MSG', (unicode(msg.getFrom()), msgtxt, tim, chatstate))
encrypted, mtype, subject, chatstate))
# END messageCB # END messageCB
def _presenceCB(self, con, prs): def _presenceCB(self, con, prs):
@ -1328,6 +1327,9 @@ class Connection:
def connect(self): def connect(self):
"""Connect and authenticate to the Jabber server """Connect and authenticate to the Jabber server
Returns connection, and connection type ('tls', 'ssl', 'tcp', '')""" Returns connection, and connection type ('tls', 'ssl', 'tcp', '')"""
if self.connection:
return self.connection
name = gajim.config.get_per('accounts', self.name, 'name') name = gajim.config.get_per('accounts', self.name, 'name')
hostname = gajim.config.get_per('accounts', self.name, 'hostname') hostname = gajim.config.get_per('accounts', self.name, 'hostname')
resource = gajim.config.get_per('accounts', self.name, 'resource') resource = gajim.config.get_per('accounts', self.name, 'resource')
@ -1336,8 +1338,6 @@ class Connection:
'try_connecting_for_foo_secs') 'try_connecting_for_foo_secs')
#create connection if it doesn't already exist #create connection if it doesn't already exist
if self.connection:
return self.connection
self.connected = 1 self.connected = 1
p = gajim.config.get_per('accounts', self.name, 'proxy') p = gajim.config.get_per('accounts', self.name, 'proxy')
if p and p in gajim.config.get_per('proxies'): if p and p in gajim.config.get_per('proxies'):
@ -1456,7 +1456,6 @@ class Connection:
con.RegisterEventHandler(self._event_dispatcher) con.RegisterEventHandler(self._event_dispatcher)
try: try:
#FIXME: blocking
auth = con.auth(name, self.password, resource, 1) auth = con.auth(name, self.password, resource, 1)
except IOError: #probably a timeout except IOError: #probably a timeout
self.connected = 0 self.connected = 0