Fix logging-not-lazy pylint errors

This commit is contained in:
Philipp Hörist 2018-09-17 18:57:00 +02:00 committed by Philipp Hörist
parent 7674450cc6
commit 6305fc69b9
21 changed files with 156 additions and 153 deletions

View File

@ -1094,7 +1094,7 @@ class Connection(CommonConnection, ConnectionHandlers):
conn=self, title=pritxt, msg=sectxt)) conn=self, title=pritxt, msg=sectxt))
def on_proxy_failure(self, reason): def on_proxy_failure(self, reason):
log.error('Connection to proxy failed: %s' % reason) log.error('Connection to proxy failed: %s', reason)
self.time_to_reconnect = None self.time_to_reconnect = None
self.on_connect_failure = None self.on_connect_failure = None
self.disconnect(on_purpose = True) self.disconnect(on_purpose = True)
@ -1108,8 +1108,8 @@ class Connection(CommonConnection, ConnectionHandlers):
log.info('Connect successfull') log.info('Connect successfull')
_con_type = con_type _con_type = con_type
if _con_type != self._current_type: if _con_type != self._current_type:
log.info('Connecting to next host beacuse desired type is %s and returned is %s' log.info('Connecting to next host beacuse desired type '
% (self._current_type, _con_type)) 'is %s and returned is %s', self._current_type, _con_type)
self._connect_to_next_host() self._connect_to_next_host()
return return
con.RegisterDisconnectHandler(self._on_disconnected) con.RegisterDisconnectHandler(self._on_disconnected)
@ -1149,8 +1149,9 @@ class Connection(CommonConnection, ConnectionHandlers):
self.on_connect_failure = None self.on_connect_failure = None
con.UnregisterDisconnectHandler(self._on_disconnected) con.UnregisterDisconnectHandler(self._on_disconnected)
con.RegisterDisconnectHandler(self.disconnectedReconnCB) con.RegisterDisconnectHandler(self.disconnectedReconnCB)
log.debug('Connected to server %s:%s with %s' % ( log.debug('Connected to server %s:%s with %s',
self._current_host['host'], self._current_host['port'], con_type)) self._current_host['host'], self._current_host['port'],
con_type)
self.connection = con self.connection = con
@ -1222,7 +1223,7 @@ class Connection(CommonConnection, ConnectionHandlers):
file = urlopen( file = urlopen(
url, cafile=cafile, timeout=2) url, cafile=cafile, timeout=2)
except (URLError, ssl.CertificateError) as exc: except (URLError, ssl.CertificateError) as exc:
log.info('Error while requesting POSH: %s' % exc) log.info('Error while requesting POSH: %s', exc)
return return
if file.getcode() != 200: if file.getcode() != 200:
@ -1274,7 +1275,7 @@ class Connection(CommonConnection, ConnectionHandlers):
'accounts', self.name, 'authentication_mechanisms').split() 'accounts', self.name, 'authentication_mechanisms').split()
for mech in auth_mechs: for mech in auth_mechs:
if mech not in nbxmpp.auth_nb.SASL_AUTHENTICATION_MECHANISMS | set(['XEP-0078']): if mech not in nbxmpp.auth_nb.SASL_AUTHENTICATION_MECHANISMS | set(['XEP-0078']):
log.warning("Unknown authentication mechanisms %s" % mech) log.warning('Unknown authentication mechanisms %s', mech)
if not auth_mechs: if not auth_mechs:
auth_mechs = None auth_mechs = None
else: else:
@ -1332,7 +1333,7 @@ class Connection(CommonConnection, ConnectionHandlers):
if not app.config.get_per('accounts', self.name, 'savepass'): if not app.config.get_per('accounts', self.name, 'savepass'):
# Forget password, it's wrong # Forget password, it's wrong
self.password = None self.password = None
log.debug("Couldn't authenticate to %s" % self._hostname) log.debug("Couldn't authenticate to %s", self._hostname)
self.disconnect(on_purpose = True) self.disconnect(on_purpose = True)
app.nec.push_incoming_event(OurShowEvent(None, conn=self, app.nec.push_incoming_event(OurShowEvent(None, conn=self,
show='offline')) show='offline'))

View File

@ -505,8 +505,8 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
if obj.conn.name != self.name: if obj.conn.name != self.name:
return return
for jid in obj.jid_list: for jid in obj.jid_list:
log.debug('Removing contact %s due to unregistered transport %s' % \ log.debug('Removing contact %s due to unregistered transport %s',
(jid, obj.agent)) jid, obj.agent)
self.get_module('Presence').unsubscribe(jid) self.get_module('Presence').unsubscribe(jid)
# Transport contacts can't have 2 resources # Transport contacts can't have 2 resources
if jid in app.to_be_removed[self.name]: if jid in app.to_be_removed[self.name]:

View File

@ -96,7 +96,7 @@ class HelperEvent:
tim = helpers.datetime_tuple(tag) tim = helpers.datetime_tuple(tag)
self.timestamp = timegm(tim) self.timestamp = timegm(tim)
except Exception: except Exception:
log.error('wrong timestamp, ignoring it: ' + tag) log.error('wrong timestamp, ignoring it: %s', tag)
self.timestamp = time_time() self.timestamp = time_time()
def get_chatstate(self): def get_chatstate(self):
@ -253,7 +253,7 @@ PresenceHelperEvent):
try: try:
self.get_jid_resource() self.get_jid_resource()
except Exception: except Exception:
log.warning('Invalid JID: %s, ignoring it' % self.stanza.getFrom()) log.warning('Invalid JID: %s, ignoring it', self.stanza.getFrom())
return return
jid_list = app.contacts.get_jid_list(self.conn.name) jid_list = app.contacts.get_jid_list(self.conn.name)
self.timestamp = None self.timestamp = None

View File

@ -77,12 +77,13 @@ class GlobalEventsDispatcher:
try: try:
self.handlers[event_name].remove((priority, handler)) self.handlers[event_name].remove((priority, handler))
except ValueError as error: except ValueError as error:
log.warning('''Function (%s) with priority "%s" never registered log.warning(
as handler of event "%s". Couldn\'t remove. Error: %s''' '''Function (%s) with priority "%s" never
%(handler, priority, event_name, error)) registered as handler of event "%s". Couldn\'t remove.
Error: %s''', handler, priority, event_name, error)
def raise_event(self, event_name, *args, **kwargs): def raise_event(self, event_name, *args, **kwargs):
log.debug('%s Args: %s'%(event_name, str(args))) log.debug('%s Args: %s', event_name, str(args))
if event_name in self.handlers: if event_name in self.handlers:
node_processed = False node_processed = False
for priority, handler in self.handlers[event_name]: for priority, handler in self.handlers[event_name]:

View File

@ -1355,7 +1355,7 @@ def _get_img_direct(attrs):
req.add_header('User-Agent', 'Gajim ' + app.version) req.add_header('User-Agent', 'Gajim ' + app.version)
f = urllib.request.urlopen(req) f = urllib.request.urlopen(req)
except Exception as ex: except Exception as ex:
log.debug('Error loading image %s ' % attrs['src'] + str(ex)) log.debug('Error loading image %s ', attrs['src'] + str(ex))
pixbuf = None pixbuf = None
alt = attrs.get('alt', 'Broken image') alt = attrs.get('alt', 'Broken image')
else: else:
@ -1368,7 +1368,7 @@ def _get_img_direct(attrs):
deadline = time.time() + (10 * (max_size / 1048576)) deadline = time.time() + (10 * (max_size / 1048576))
while True: while True:
if time.time() > deadline: if time.time() > deadline:
log.debug('Timeout loading image %s ' % attrs['src']) log.debug('Timeout loading image %s ', attrs['src'])
mem = '' mem = ''
alt = attrs.get('alt', '') alt = attrs.get('alt', '')
if alt: if alt:
@ -1378,7 +1378,7 @@ def _get_img_direct(attrs):
try: try:
temp = f.read(100) temp = f.read(100)
except socket.timeout as ex: except socket.timeout as ex:
log.debug('Timeout loading image %s ' % attrs['src'] + str(ex)) log.debug('Timeout loading image %s ', attrs['src'] + str(ex))
alt = attrs.get('alt', '') alt = attrs.get('alt', '')
if alt: if alt:
alt += '\n' alt += '\n'
@ -1445,7 +1445,7 @@ def _get_img_proxy(attrs, proxy):
else: else:
alt += _('Error loading image') alt += _('Error loading image')
except Exception as ex: except Exception as ex:
log.debug('Error loading image %s ' % attrs['src'] + str(ex)) log.debug('Error loading image %s ', attrs['src'] + str(ex))
pixbuf = None pixbuf = None
alt = attrs.get('alt', 'Broken image') alt = attrs.get('alt', 'Broken image')
return ('', alt) return ('', alt)

View File

@ -350,7 +350,7 @@ class JingleFileTransfer(JingleContent):
self.__send_candidate(args) self.__send_candidate(args)
def _on_connect_error(self, sid): def _on_connect_error(self, sid):
log.info('connect error, sid=' + sid) log.info('connect error, sid=%s', sid)
args = {'candError' : True, args = {'candError' : True,
'sendCand' : True} 'sendCand' : True}
self.__send_candidate(args) self.__send_candidate(args)

View File

@ -329,7 +329,7 @@ class JingleTransportSocks5(JingleTransport):
return content return content
def _on_proxy_auth_ok(self, proxy): def _on_proxy_auth_ok(self, proxy):
log.info('proxy auth ok for ' + str(proxy)) log.info('proxy auth ok for %s', str(proxy))
# send activate request to proxy, send activated confirmation to peer # send activate request to proxy, send activated confirmation to peer
if not self.connection: if not self.connection:
return return

View File

@ -34,7 +34,7 @@ class AbstractPEP:
def get_tag_as_PEP(cls, jid, account, event_tag): def get_tag_as_PEP(cls, jid, account, event_tag):
items = event_tag.getTag('items', {'node': cls.namespace}) items = event_tag.getTag('items', {'node': cls.namespace})
if items: if items:
log.debug("Received PEP 'user %s' from %s" % (cls.type_, jid)) log.debug('Received PEP "user %s" from %s', cls.type_, jid)
return cls(jid, account, items) return cls(jid, account, items)
else: else:
return None return None

View File

@ -778,7 +778,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
Handles streams state change. Used internally. Handles streams state change. Used internally.
""" """
typ = stanza.getType() typ = stanza.getType()
log.debug('IBBIqHandler called typ->%s' % typ) log.debug('IBBIqHandler called typ->%s', typ)
if typ == 'set' and stanza.getTag('open'): if typ == 'set' and stanza.getTag('open'):
self.StreamOpenHandler(conn, stanza) self.StreamOpenHandler(conn, stanza)
elif typ == 'set' and stanza.getTag('close'): elif typ == 'set' and stanza.getTag('close'):
@ -808,8 +808,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
err = None err = None
sid = stanza.getTagAttr('open', 'sid') sid = stanza.getTagAttr('open', 'sid')
blocksize = stanza.getTagAttr('open', 'block-size') blocksize = stanza.getTagAttr('open', 'block-size')
log.debug('StreamOpenHandler called sid->%s blocksize->%s' % (sid, log.debug('StreamOpenHandler called sid->%s blocksize->%s',
blocksize)) sid, blocksize)
file_props = FilesProp.getFilePropByTransportSid(self.name, sid) file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
try: try:
blocksize = int(blocksize) blocksize = int(blocksize)
@ -822,7 +822,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
if err: if err:
rep = nbxmpp.Error(stanza, err) rep = nbxmpp.Error(stanza, err)
else: else:
log.debug("Opening stream: id %s, block-size %s" % (sid, blocksize)) log.debug("Opening stream: id %s, block-size %s",
sid, blocksize)
rep = nbxmpp.Protocol('iq', stanza.getFrom(), 'result', rep = nbxmpp.Protocol('iq', stanza.getFrom(), 'result',
stanza.getTo(), {'id': stanza.getID()}) stanza.getTo(), {'id': stanza.getID()})
file_props.block_size = blocksize file_props.block_size = blocksize
@ -934,7 +935,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
sid = stanza.getTagAttr('data', 'sid') sid = stanza.getTagAttr('data', 'sid')
seq = stanza.getTagAttr('data', 'seq') seq = stanza.getTagAttr('data', 'seq')
data = stanza.getTagData('data') data = stanza.getTagData('data')
log.debug('ReceiveHandler called sid->%s seq->%s' % (sid, seq)) log.debug('ReceiveHandler called sid->%s seq->%s', sid, seq)
try: try:
seq = int(seq) seq = int(seq)
data = base64.b64decode(data.encode('utf-8')) data = base64.b64decode(data.encode('utf-8'))
@ -951,8 +952,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
elif seq != file_props.seq: elif seq != file_props.seq:
err = nbxmpp.ERR_UNEXPECTED_REQUEST err = nbxmpp.ERR_UNEXPECTED_REQUEST
else: else:
log.debug('Successfully received sid->%s %s+%s bytes' % (sid, log.debug('Successfully received sid->%s %s+%s bytes',
file_props.fp.tell(), len(data))) sid, file_props.fp.tell(), len(data))
file_props.seq += 1 file_props.seq += 1
file_props.started = True file_props.started = True
file_props.fp.write(data) file_props.fp.write(data)
@ -964,7 +965,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
if file_props.received_len >= file_props.size: if file_props.received_len >= file_props.size:
file_props.completed = True file_props.completed = True
if err: if err:
log.debug('Error on receive: %s' % err) log.debug('Error on receive: %s', err)
conn.send(nbxmpp.Error(nbxmpp.Iq(to=stanza.getFrom(), conn.send(nbxmpp.Error(nbxmpp.Iq(to=stanza.getFrom(),
frm=stanza.getTo(), frm=stanza.getTo(),
payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close')]), err, reply=0)) payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close')]), err, reply=0))
@ -977,7 +978,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
Raise xmpppy event specifying successful data receive. Raise xmpppy event specifying successful data receive.
""" """
sid = stanza.getTagAttr('close', 'sid') sid = stanza.getTagAttr('close', 'sid')
log.debug('StreamCloseHandler called sid->%s' % sid) log.debug('StreamCloseHandler called sid->%s', sid)
# look in sending files # look in sending files
file_props = FilesProp.getFilePropByTransportSid(self.name, sid) file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
if file_props: if file_props:
@ -1002,7 +1003,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
is agreed upon. is agreed upon.
""" """
syn_id = stanza.getID() syn_id = stanza.getID()
log.debug('IBBAllIqHandler called syn_id->%s' % syn_id) log.debug('IBBAllIqHandler called syn_id->%s', syn_id)
for file_props in FilesProp.getAllFileProp(): for file_props in FilesProp.getAllFileProp():
if not file_props.direction or not file_props.connected: if not file_props.direction or not file_props.connected:
# It's socks5 bytestream # It's socks5 bytestream

View File

@ -122,22 +122,22 @@ class ProxyResolver:
self.state = S_FINISHED self.state = S_FINISHED
return return
self.state = S_INITIAL self.state = S_INITIAL
log.info('start resolving %s:%s' % (self.host, self.port)) log.info('start resolving %s:%s', self.host, self.port)
self.receiver_tester = ReceiverTester(self.host, self.port, self.jid, self.receiver_tester = ReceiverTester(self.host, self.port, self.jid,
self.sid, self.sender_jid, self._on_receiver_success, self.sid, self.sender_jid, self._on_receiver_success,
self._on_connect_failure) self._on_connect_failure)
self.receiver_tester.connect() self.receiver_tester.connect()
def _on_receiver_success(self): def _on_receiver_success(self):
log.debug('Receiver successfully connected %s:%s' % (self.host, log.debug('Receiver successfully connected %s:%s',
self.port)) self.host, self.port)
self.host_tester = HostTester(self.host, self.port, self.jid, self.host_tester = HostTester(self.host, self.port, self.jid,
self.sid, self.sender_jid, self._on_connect_success, self.sid, self.sender_jid, self._on_connect_success,
self._on_connect_failure) self._on_connect_failure)
self.host_tester.connect() self.host_tester.connect()
def _on_connect_success(self): def _on_connect_success(self):
log.debug('Host successfully connected %s:%s' % (self.host, self.port)) log.debug('Host successfully connected %s:%s', self.host, self.port)
iq = nbxmpp.Protocol(name='iq', to=self.jid, typ='set') iq = nbxmpp.Protocol(name='iq', to=self.jid, typ='set')
query = iq.setTag('query') query = iq.setTag('query')
query.setNamespace(nbxmpp.NS_BYTESTREAM) query.setNamespace(nbxmpp.NS_BYTESTREAM)
@ -147,7 +147,7 @@ class ProxyResolver:
activate.setData('test@gajim.org/test2') activate.setData('test@gajim.org/test2')
if self.active_connection: if self.active_connection:
log.debug('Activating bytestream on %s:%s' % (self.host, self.port)) log.debug('Activating bytestream on %s:%s', self.host, self.port)
self.active_connection.SendAndCallForResponse(iq, self.active_connection.SendAndCallForResponse(iq,
self._result_received) self._result_received)
self.state = S_ACTIVATED self.state = S_ACTIVATED
@ -162,11 +162,11 @@ class ProxyResolver:
self._on_connect_failure() self._on_connect_failure()
def keep_conf(self): def keep_conf(self):
log.debug('Bytestream activated %s:%s' % (self.host, self.port)) log.debug('Bytestream activated %s:%s', self.host, self.port)
self.state = S_FINISHED self.state = S_FINISHED
def _on_connect_failure(self): def _on_connect_failure(self):
log.debug('Connection failed with %s:%s' % (self.host, self.port)) log.debug('Connection failed with %s:%s', self.host, self.port)
self.state = S_FINISHED self.state = S_FINISHED
self.host = None self.host = None
self.port = 0 self.port = 0
@ -318,9 +318,9 @@ class HostTester(Socks5, IdleObject):
data = self._get_request_buff(self._get_sha1_auth()) data = self._get_request_buff(self._get_sha1_auth())
self.send_raw(data) self.send_raw(data)
self.state += 1 self.state += 1
log.debug('Host authenticating to %s:%s' % (self.host, self.port)) log.debug('Host authenticating to %s:%s', self.host, self.port)
elif self.state == 3: elif self.state == 3:
log.debug('Host authenticated to %s:%s' % (self.host, self.port)) log.debug('Host authenticated to %s:%s', self.host, self.port)
self.on_success() self.on_success()
self.disconnect() self.disconnect()
self.state += 1 self.state += 1
@ -331,7 +331,7 @@ class HostTester(Socks5, IdleObject):
try: try:
self._sock.connect((self.host, self.port)) self._sock.connect((self.host, self.port))
self._sock.setblocking(False) self._sock.setblocking(False)
log.debug('Host Connecting to %s:%s' % (self.host, self.port)) log.debug('Host Connecting to %s:%s', self.host, self.port)
self._send = self._sock.send self._send = self._sock.send
self._recv = self._sock.recv self._recv = self._sock.recv
except Exception as ee: except Exception as ee:
@ -351,7 +351,7 @@ class HostTester(Socks5, IdleObject):
self._recv = self._sock.recv self._recv = self._sock.recv
self.buff = b'' self.buff = b''
self.state = 1 # connected self.state = 1 # connected
log.debug('Host connected to %s:%s' % (self.host, self.port)) log.debug('Host connected to %s:%s', self.host, self.port)
self.idlequeue.plug_idle(self, True, False) self.idlequeue.plug_idle(self, True, False)
return return
@ -436,7 +436,7 @@ class ReceiverTester(Socks5, IdleObject):
if version != 0x05 or method == 0xff: if version != 0x05 or method == 0xff:
self.pollend() self.pollend()
return return
log.debug('Receiver authenticating to %s:%s' % (self.host, self.port)) log.debug('Receiver authenticating to %s:%s', self.host, self.port)
data = self._get_request_buff(self._get_sha1_auth()) data = self._get_request_buff(self._get_sha1_auth())
self.send_raw(data) self.send_raw(data)
self.state += 1 self.state += 1
@ -448,7 +448,7 @@ class ReceiverTester(Socks5, IdleObject):
if version != 0x05 or reply != 0x00: if version != 0x05 or reply != 0x00:
self.pollend() self.pollend()
return return
log.debug('Receiver authenticated to %s:%s' % (self.host, self.port)) log.debug('Receiver authenticated to %s:%s', self.host, self.port)
self.on_success() self.on_success()
self.disconnect() self.disconnect()
self.state += 1 self.state += 1
@ -459,7 +459,7 @@ class ReceiverTester(Socks5, IdleObject):
try: try:
self._sock.setblocking(False) self._sock.setblocking(False)
self._sock.connect((self.host, self.port)) self._sock.connect((self.host, self.port))
log.debug('Receiver Connecting to %s:%s' % (self.host, self.port)) log.debug('Receiver Connecting to %s:%s', self.host, self.port)
self._send = self._sock.send self._send = self._sock.send
self._recv = self._sock.recv self._recv = self._sock.recv
except Exception as ee: except Exception as ee:
@ -479,5 +479,5 @@ class ReceiverTester(Socks5, IdleObject):
self._recv = self._sock.recv self._recv = self._sock.recv
self.buff = '' self.buff = ''
self.state = 1 # connected self.state = 1 # connected
log.debug('Receiver connected to %s:%s' % (self.host, self.port)) log.debug('Receiver connected to %s:%s', self.host, self.port)
self.idlequeue.plug_idle(self, True, False) self.idlequeue.plug_idle(self, True, False)

View File

@ -132,22 +132,22 @@ class SocksQueue:
fp = fingerprint fp = fingerprint
if receiving: if receiving:
if 'candidate_id' in streamhost: if 'candidate_id' in streamhost:
log.debug('Trying to connect as receiver to cid ' + \ log.debug('Trying to connect as receiver to cid %s',
streamhost['candidate_id']) streamhost['candidate_id'])
else: else:
log.debug('Trying to connect as receiver to jid ' + \ log.debug('Trying to connect as receiver to jid %s',
streamhost['jid']) streamhost['jid'])
file_props.type_ = 'r' file_props.type_ = 'r'
socks5obj = Socks5ReceiverClient(self.idlequeue, streamhost, socks5obj = Socks5ReceiverClient(self.idlequeue, streamhost,
transport_sid, file_props, fingerprint=fp) transport_sid, file_props, fingerprint=fp)
self.add_sockobj(account, socks5obj) self.add_sockobj(account, socks5obj)
else: else:
if 'candidate_id' in streamhost: if 'candidate_id' in streamhost:
log.debug('Trying to connect as sender to cid ' + \ log.debug('Trying to connect as sender to cid %s',
streamhost['candidate_id']) streamhost['candidate_id'])
else: else:
log.debug('Trying to connect as sender to jid ' + \ log.debug('Trying to connect as sender to jid %s',
streamhost['jid']) streamhost['jid'])
if file_props.sha_str: if file_props.sha_str:
idx = file_props.sha_str idx = file_props.sha_str
else: else:
@ -175,9 +175,9 @@ class SocksQueue:
streamhosts. Stop other attempts for connections streamhosts. Stop other attempts for connections
""" """
if 'candidate_id' in streamhost: if 'candidate_id' in streamhost:
log.debug('Connected to cid ' + streamhost['candidate_id']) log.debug('Connected to cid %s', streamhost['candidate_id'])
else: else:
log.debug('Connected to jid ' + streamhost['jid']) log.debug('Connected to jid %s', streamhost['jid'])
for host in file_props.streamhosts: for host in file_props.streamhosts:
if host != streamhost and 'idx' in host: if host != streamhost and 'idx' in host:
if host['state'] == 1: if host['state'] == 1:
@ -240,9 +240,10 @@ class SocksQueue:
Called when we loose connection during transfer Called when we loose connection during transfer
""" """
if 'candidate_id' in streamhost: if 'candidate_id' in streamhost:
log.debug('Connection refused to cid ' + streamhost['candidate_id']) log.debug('Connection refused to cid %s',
streamhost['candidate_id'])
else: else:
log.debug('Connection refused to jid ' + streamhost['jid']) log.debug('Connection refused to jid %s', streamhost['jid'])
if file_props is None: if file_props is None:
return return
streamhost['state'] = -1 streamhost['state'] = -1
@ -641,7 +642,7 @@ class Socks5:
add = self._recv(64) add = self._recv(64)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError, except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError) as e: OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request : ' + repr(e)) log.info('SSL rehandshake request: %s', repr(e))
raise e raise e
except Exception: except Exception:
add = b'' add = b''
@ -658,7 +659,7 @@ class Socks5:
self._send(raw_data) self._send(raw_data)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError, except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError) as e: OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request :' + repr(e)) log.info('SSL rehandshake request: %s', repr(e))
raise e raise e
except Exception: except Exception:
self.disconnect() self.disconnect()
@ -682,7 +683,7 @@ class Socks5:
lenn = self._send(buff) lenn = self._send(buff)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError, except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError) as e: OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request :' + repr(e)) log.info('SSL rehandshake request: %s', repr(e))
raise e raise e
except Exception as e: except Exception as e:
if e.errno not in (EINTR, ENOBUFS, EWOULDBLOCK): if e.errno not in (EINTR, ENOBUFS, EWOULDBLOCK):
@ -756,7 +757,7 @@ class Socks5:
buff = self._recv(MAX_BUFF_LEN) buff = self._recv(MAX_BUFF_LEN)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError, except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError) as e: OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request :' + repr(e)) log.info('SSL rehandshake request: %s', repr(e))
raise e raise e
except Exception: except Exception:
buff = b'' buff = b''
@ -896,7 +897,7 @@ class Socks5:
buff = self._recv().decode('utf-8') buff = self._recv().decode('utf-8')
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError, except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError) as e: OpenSSL.SSL.WantX509LookupError) as e:
log.info("SSL rehandshake request : " + repr(e)) log.info("SSL rehandshake request: %s", repr(e))
raise e raise e
try: try:
version, method = struct.unpack('!BB', buff) version, method = struct.unpack('!BB', buff)
@ -1269,8 +1270,9 @@ class Socks5Client(Socks5):
def send_file(self): def send_file(self):
if self.ssl_errnum > 0: if self.ssl_errnum > 0:
log.error('remote certificate does not match the announced one.' + \ log.error('remote certificate does not match the announced one.'
'\nSSL Error: %d\nCancelling file transfer' % self.ssl_errnum) '\nSSL Error: %d\nCancelling file transfer',
self.ssl_errnum)
self.file_props.error = -12 self.file_props.error = -12
return -1 return -1
return super(Socks5Client, self).send_file() return super(Socks5Client, self).send_file()
@ -1435,7 +1437,7 @@ class Socks5Listener(IdleObject):
self.ai = None self.ai = None
continue continue
if not self.ai: if not self.ai:
log.error('unable to bind to port ' + str(self.port)) log.error('unable to bind to port %s', str(self.port))
return None return None
self._serv.listen(socket.SOMAXCONN) self._serv.listen(socket.SOMAXCONN)
self._serv.setblocking(False) self._serv.setblocking(False)

View File

@ -114,7 +114,7 @@ class ZeroconfListener(IdleObject):
""" """
Free all resources, we are not listening anymore Free all resources, we are not listening anymore
""" """
log.info('Disconnecting ZeroconfListener: %s' % message) log.info('Disconnecting ZeroconfListener: %s', message)
app.idlequeue.remove_timeout(self.fd) app.idlequeue.remove_timeout(self.fd)
app.idlequeue.unplug_idle(self.fd) app.idlequeue.unplug_idle(self.fd)
self.fd = -1 self.fd = -1
@ -252,8 +252,8 @@ class P2PClient(IdleObject):
def _check_stream_start(self, ns, tag, attrs): def _check_stream_start(self, ns, tag, attrs):
if ns != NS_STREAMS or tag != 'stream': if ns != NS_STREAMS or tag != 'stream':
log.error('Incorrect stream start: (%s,%s).Terminating!' % (tag, log.error('Incorrect stream start: (%s,%s).Terminating!',
ns), 'error') tag, ns)
self.Connection.disconnect() self.Connection.disconnect()
if self.on_not_ok: if self.on_not_ok:
self.on_not_ok('Connection to host could not be established: ' self.on_not_ok('Connection to host could not be established: '
@ -386,8 +386,8 @@ class P2PConnection(IdleObject, PlugIn):
self.disconnect() self.disconnect()
return return
ai = self.ais.pop(0) ai = self.ais.pop(0)
log.info('Trying to connect to %s through %s:%s', str(self.host), log.info('Trying to connect to %s through %s:%s',
ai[4][0], ai[4][1], exc_info=True) str(self.host), ai[4][0], ai[4][1], exc_info=True)
try: try:
self._sock = socket.socket(*ai[:3]) self._sock = socket.socket(*ai[:3])
self._sock.setblocking(False) self._sock.setblocking(False)
@ -543,7 +543,7 @@ class P2PConnection(IdleObject, PlugIn):
self.on_receive(received) self.on_receive(received)
else: else:
# This should never happed, so we need the debug # This should never happed, so we need the debug
log.error('Unhandled data received: %s' % received) log.error('Unhandled data received: %s', received)
self.disconnect() self.disconnect()
return True return True
@ -608,7 +608,7 @@ class P2PConnection(IdleObject, PlugIn):
def _on_send(self): def _on_send(self):
if self.sent_data and self.sent_data.strip(): if self.sent_data and self.sent_data.strip():
log.debug('sent: %s' % self.sent_data) log.debug('sent: %s', self.sent_data)
if hasattr(self._owner, 'Dispatcher'): if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event( self._owner.Dispatcher.Event(
'', DATA_SENT, self.sent_data.decode('utf-8')) '', DATA_SENT, self.sent_data.decode('utf-8'))
@ -705,7 +705,7 @@ class ClientZeroconf:
self.roster = None self.roster = None
self.disconnecting = True self.disconnecting = True
for i in reversed(self.disconnect_handlers): for i in reversed(self.disconnect_handlers):
log.debug('Calling disconnect handler %s' % i) log.debug('Calling disconnect handler %s', i)
i() i()
self.disconnecting = False self.disconnecting = False

View File

@ -60,7 +60,7 @@ class Zeroconf:
pass pass
def error_callback1(self, err): def error_callback1(self, err):
log.debug('Error while resolving: ' + str(err)) log.debug('Error while resolving: %s', str(err))
def error_callback(self, err): def error_callback(self, err):
log.debug(str(err)) log.debug(str(err))
@ -71,8 +71,8 @@ class Zeroconf:
def new_service_callback(self, interface, protocol, name, stype, domain, def new_service_callback(self, interface, protocol, name, stype, domain,
flags): flags):
log.debug('Found service %s in domain %s on %i.%i.' % (name, domain, log.debug('Found service %s in domain %s on %i.%i.',
interface, protocol)) name, domain, interface, protocol)
if not self.connected: if not self.connected:
return return
@ -84,8 +84,8 @@ class Zeroconf:
def remove_service_callback(self, interface, protocol, name, stype, domain, def remove_service_callback(self, interface, protocol, name, stype, domain,
flags): flags):
log.debug('Service %s in domain %s on %i.%i disappeared.' % (name, log.debug('Service %s in domain %s on %i.%i disappeared.',
domain, interface, protocol)) name, domain, interface, protocol)
if not self.connected: if not self.connected:
return return
if name != self.name: if name != self.name:
@ -161,10 +161,10 @@ class Zeroconf:
def service_resolved_callback(self, interface, protocol, name, stype, domain, def service_resolved_callback(self, interface, protocol, name, stype, domain,
host, aprotocol, address, port, txt, flags): host, aprotocol, address, port, txt, flags):
log.debug('Service data for service %s in domain %s on %i.%i:' log.debug('Service data for service %s in domain %s on %i.%i:',
% (name, domain, interface, protocol)) name, domain, interface, protocol)
log.debug('Host %s (%s), port %i, TXT data: %s' % (host, address, log.debug('Host %s (%s), port %i, TXT data: %s',
port, self.txt_array_to_dict(txt))) host, address, port, self.txt_array_to_dict(txt))
if not self.connected: if not self.connected:
return return
bare_name = name bare_name = name
@ -186,11 +186,13 @@ class Zeroconf:
# IPv6 aprotocol responses via the same protocol, # IPv6 aprotocol responses via the same protocol,
# so this probably needs to be revised again. # so this probably needs to be revised again.
if old_resolved_info[i][0:2] == (interface, protocol): if old_resolved_info[i][0:2] == (interface, protocol):
log.debug('Deleting resolved info for interface %i, protocol %i, host %s, aprotocol %i, address %s, port %i' % old_resolved_info[i]) log.debug('Deleting resolved info for interface %s',
old_resolved_info[i])
del old_resolved_info[i] del old_resolved_info[i]
break break
resolved_info = resolved_info + old_resolved_info resolved_info = resolved_info + old_resolved_info
log.debug('Collected resolved info is now: %s' % (resolved_info,)) log.debug('Collected resolved info is now: %s',
resolved_info)
self.contacts[name] = (name, domain, resolved_info, bare_name, txt) self.contacts[name] = (name, domain, resolved_info, bare_name, txt)
self.new_serviceCB(name) self.new_serviceCB(name)
else: else:
@ -225,7 +227,7 @@ class Zeroconf:
log.debug('Service successfully updated') log.debug('Service successfully updated')
def service_add_fail_callback(self, err): def service_add_fail_callback(self, err):
log.debug('Error while adding service. %s' % str(err)) log.debug('Error while adding service. %s', str(err))
if 'Local name collision' in str(err): if 'Local name collision' in str(err):
alternative_name = self.server.GetAlternativeServiceName(self.username) alternative_name = self.server.GetAlternativeServiceName(self.username)
self.name_conflictCB(alternative_name) self.name_conflictCB(alternative_name)
@ -234,7 +236,7 @@ class Zeroconf:
self.disconnect() self.disconnect()
def server_state_changed_callback(self, state, error): def server_state_changed_callback(self, state, error):
log.debug('server state changed to %s' % state) log.debug('server state changed to %s', state)
if state == ServerState.RUNNING: if state == ServerState.RUNNING:
self.create_service() self.create_service()
elif state in (ServerState.COLLISION, elif state in (ServerState.COLLISION,
@ -292,8 +294,8 @@ class Zeroconf:
txt['status'] = 'avail' txt['status'] = 'avail'
self.txt = txt self.txt = txt
log.debug('Publishing service %s of type %s' % (self.name, log.debug('Publishing service %s of type %s',
self.stype)) self.name, self.stype)
self.entrygroup.AddService(Interface.UNSPEC, self.entrygroup.AddService(Interface.UNSPEC,
Protocol.UNSPEC, dbus.UInt32(0), self.name, self.stype, '', Protocol.UNSPEC, dbus.UInt32(0), self.name, self.stype, '',
'', dbus.UInt16(self.port), self.avahi_txt(), '', dbus.UInt16(self.port), self.avahi_txt(),
@ -360,7 +362,7 @@ class Zeroconf:
dbus.set_default_main_loop(main_loop) dbus.set_default_main_loop(main_loop)
except ImportError: except ImportError:
log.debug('Error: python-dbus needs to be installed. No ' log.debug('Error: python-dbus needs to be installed. No '
'zeroconf support.') 'zeroconf support.')
return False return False
if self.bus: if self.bus:
return True return True

View File

@ -94,7 +94,7 @@ class Zeroconf:
resolve_sdRef.close() resolve_sdRef.close()
def remove_service_callback(self, name): def remove_service_callback(self, name):
log.info('Service %s disappeared.' % name) log.info('Service %s disappeared.', name)
if not self.connected: if not self.connected:
return return
if name != self.name: if name != self.name:

View File

@ -1380,9 +1380,9 @@ class ConversationTextview(GObject.GObject):
xhtml = xhtml.replace('/me', '<i>* %s</i>' % (name,), 1) xhtml = xhtml.replace('/me', '<i>* %s</i>' % (name,), 1)
self.tv.display_html(xhtml, self.tv, self, iter_=iter_) self.tv.display_html(xhtml, self.tv, self, iter_=iter_)
return return
except Exception as e: except Exception as error:
log.debug('Error processing xhtml: ' + str(e)) log.debug('Error processing xhtml: %s', error)
log.debug('with |' + xhtml + '|') log.debug('with |%s|', xhtml)
# /me is replaced by name if name is given # /me is replaced by name if name is given
if name and (text.startswith('/me ') or text.startswith('/me\n')): if name and (text.startswith('/me ') or text.startswith('/me\n')):

View File

@ -351,12 +351,13 @@ class FileTransfersWindow:
if file_props is None: if file_props is None:
return False return False
if contact.supports(NS_JINGLE_FILE_TRANSFER_5): if contact.supports(NS_JINGLE_FILE_TRANSFER_5):
log.info("contact %s supports jingle file transfer"%(contact.get_full_jid())) log.info('contact %s supports jingle file transfer',
contact.get_full_jid())
app.connections[account].start_file_transfer(contact.get_full_jid(), app.connections[account].start_file_transfer(contact.get_full_jid(),
file_props) file_props)
self.add_transfer(account, contact, file_props) self.add_transfer(account, contact, file_props)
else: else:
log.info("contact does not support jingle file transfer") log.info('contact does not support jingle file transfer')
file_props.transport_sid = file_props.sid file_props.transport_sid = file_props.sid
app.connections[account].send_file_request(file_props) app.connections[account].send_file_request(file_props)
self.add_transfer(account, contact, file_props) self.add_transfer(account, contact, file_props)

View File

@ -1953,8 +1953,8 @@ class GroupchatControl(ChatControlBase):
gc_c = app.contacts.get_gc_contact(self.account, gc_c = app.contacts.get_gc_contact(self.account,
self.room_jid, obj.nick) self.room_jid, obj.nick)
if not gc_c: if not gc_c:
log.error('%s has an iter, but no gc_contact instance' % \ log.error('%s has an iter, but no gc_contact instance',
obj.nick) obj.nick)
return return
actual_affiliation = gc_c.affiliation actual_affiliation = gc_c.affiliation

View File

@ -68,20 +68,20 @@ def get_icon_pixmap(icon_name, size=16, color=None, quiet=False):
pixbuf, was_symbolic = iconinfo.load_symbolic(*color) pixbuf, was_symbolic = iconinfo.load_symbolic(*color)
return pixbuf return pixbuf
return iconinfo.load_icon() return iconinfo.load_icon()
except GLib.GError as e: except GLib.GError as error:
if not quiet: if not quiet:
log.error('Unable to load icon %s: %s' % (icon_name, str(e))) log.error('Unable to load icon %s: %s', icon_name, str(error))
def get_icon_path(icon_name, size=16): def get_icon_path(icon_name, size=16):
try: try:
icon_info = gtk_icon_theme.lookup_icon(icon_name, size, 0) icon_info = gtk_icon_theme.lookup_icon(icon_name, size, 0)
if icon_info == None: if icon_info == None:
log.error('Icon not found: %s' % icon_name) log.error('Icon not found: %s', icon_name)
return "" return ''
else: else:
return icon_info.get_filename() return icon_info.get_filename()
except GLib.GError as e: except GLib.GError as error:
log.error("Unable to find icon %s: %s" % (icon_name, str(e))) log.error('Unable to find icon %s: %s', icon_name, str(error))
HAS_PYWIN32 = True HAS_PYWIN32 = True
@ -484,8 +484,8 @@ def on_avatar_save_as_menuitem_activate(widget, avatar, default_name=''):
# Save image # Save image
try: try:
pixbuf.savev(file_path, image_format, [], []) pixbuf.savev(file_path, image_format, [], [])
except Exception as e: except Exception as error:
log.error('Error saving avatar: %s' % str(e)) log.error('Error saving avatar: %s', error)
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
new_file_path = '.'.join(file_path.split('.')[:-1]) + '.png' new_file_path = '.'.join(file_path.split('.')[:-1]) + '.png'

View File

@ -270,9 +270,12 @@ class GajimPluginConfig():
s.close() s.close()
self.save() self.save()
except Exception: except Exception:
log.warning('%s plugin config file not readable. Saving it as ' enc = locale.getpreferredencoding()
'%s and creating a new one' % (self.plugin.short_name, filename = self.FILE_PATH.decode(enc) + '.bak'
self.FILE_PATH.decode(locale.getpreferredencoding()) + '.bak')) log.warning(
'%s plugin config file not readable. Saving it as '
'%s and creating a new one',
self.plugin.short_name, filename)
if os.path.exists(self.FILE_PATH + '.bak'): if os.path.exists(self.FILE_PATH + '.bak'):
os.remove(self.FILE_PATH + '.bak') os.remove(self.FILE_PATH + '.bak')
os.rename(self.FILE_PATH, self.FILE_PATH + '.bak') os.rename(self.FILE_PATH, self.FILE_PATH + '.bak')

View File

@ -99,11 +99,9 @@ class log_calls:
@functools.wraps(f) @functools.wraps(f)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
log.debug('%(funcname)s() <entered>'%{ log.debug('%s() <entered>', self.full_func_name)
'funcname': self.full_func_name})
result = f(*args, **kwargs) result = f(*args, **kwargs)
log.debug('%(funcname)s() <left>'%{ log.debug('%s() <left>', self.full_func_name)
'funcname': self.full_func_name})
return result return result
else: else:
@functools.wraps(f) @functools.wraps(f)

View File

@ -144,9 +144,10 @@ class PluginManager(metaclass=Singleton):
self.plugins.append(plugin) self.plugins.append(plugin)
plugin.active = False plugin.active = False
else: else:
log.info('Not loading plugin %s v%s from module %s (identified by' log.info('Not loading plugin %s v%s from module %s '
' short name: %s). Plugin already loaded.' % (plugin.name, '(identified by short name: %s). Plugin already loaded.',
plugin.version, plugin.__module__, plugin.short_name)) plugin.name, plugin.version,
plugin.__module__, plugin.short_name)
@log_calls('PluginManager') @log_calls('PluginManager')
def remove_plugin(self, plugin): def remove_plugin(self, plugin):
@ -314,8 +315,8 @@ class PluginManager(metaclass=Singleton):
try: try:
handlers[0](*args) handlers[0](*args)
except Exception as e: except Exception as e:
log.warning('Error executing %s', handlers[0], log.warning('Error executing %s',
exc_info=True) handlers[0], exc_info=True)
def _register_events_handlers_in_ged(self, plugin): def _register_events_handlers_in_ged(self, plugin):
for event_name, handler in plugin.events_handlers.items(): for event_name, handler in plugin.events_handlers.items():
@ -426,9 +427,9 @@ class PluginManager(metaclass=Singleton):
if handler: if handler:
try: try:
handler(*gui_extension_point_args) handler(*gui_extension_point_args)
except Exception as e: except Exception:
log.warning('Error executing %s', handler, log.warning('Error executing %s',
exc_info=True) handler, exc_info=True)
self._remove_events_handler_from_ged(plugin) self._remove_events_handler_from_ged(plugin)
self._remove_network_events_from_nec(plugin) self._remove_network_events_from_nec(plugin)
@ -467,9 +468,9 @@ class PluginManager(metaclass=Singleton):
if handler: if handler:
try: try:
handler(*gui_extension_point_args) handler(*gui_extension_point_args)
except Exception as e: except Exception:
log.warning('Error executing %s', handler, log.warning('Error executing %s',
exc_info=True) handler, exc_info=True)
@log_calls('PluginManager') @log_calls('PluginManager')
@ -579,9 +580,8 @@ class PluginManager(metaclass=Singleton):
try: try:
conf.read_file(conf_file) conf.read_file(conf_file)
except configparser.Error: except configparser.Error:
log.warning(("Plugin {plugin} not loaded, error loading" log.warning('Plugin %s not loaded, error loading manifest',
" manifest").format(plugin=elem_name) elem_name, exc_info=True)
, exc_info=True)
continue continue
min_v = conf.get('info', 'min_gajim_version', fallback=None) min_v = conf.get('info', 'min_gajim_version', fallback=None)
@ -591,32 +591,24 @@ class PluginManager(metaclass=Singleton):
gajim_v_cmp = parse_version(gajim_v) gajim_v_cmp = parse_version(gajim_v)
if min_v and gajim_v_cmp < parse_version(min_v): if min_v and gajim_v_cmp < parse_version(min_v):
log.warning(('Plugin {plugin} not loaded, newer version of' log.warning('Plugin %s not loaded, newer version of'
'gajim required: {gajim_v} < {min_v}').format( 'gajim required: %s < %s',
plugin=elem_name, elem_name, gajim_v, min_v)
gajim_v=gajim_v,
min_v=min_v
))
continue continue
if max_v and gajim_v_cmp > parse_version(max_v): if max_v and gajim_v_cmp > parse_version(max_v):
log.warning(('Plugin {plugin} not loaded, plugin incompatible ' log.warning('Plugin %s not loaded, plugin incompatible '
'with current version of gajim: ' 'with current version of gajim: '
'{gajim_v} > {max_v}').format( '%s > %s', elem_name, gajim_v, max_v)
plugin=elem_name,
gajim_v=gajim_v,
max_v=max_v
))
continue continue
module = None module = None
try: try:
log.info('Loading %s', module_name) log.info('Loading %s', module_name)
module = __import__(module_name) module = __import__(module_name)
except Exception as error: except Exception:
log.warning( log.warning(
"While trying to load {plugin}, exception occurred".format(plugin=elem_name), 'While trying to load %s, exception occurred',
exc_info=sys.exc_info() elem_name, exc_info=True)
)
continue continue
if module is None: if module is None:
@ -626,7 +618,7 @@ class PluginManager(metaclass=Singleton):
for module_attr_name in [attr_name for attr_name in dir(module) for module_attr_name in [attr_name for attr_name in dir(module)
if not (attr_name.startswith('__') or attr_name.endswith('__'))]: if not (attr_name.startswith('__') or attr_name.endswith('__'))]:
module_attr = getattr(module, module_attr_name) module_attr = getattr(module, module_attr_name)
log.debug('%s : %s' % (module_attr_name, module_attr)) log.debug('%s: %s', module_attr_name, module_attr)
try: try:
if not issubclass(module_attr, GajimPlugin) or \ if not issubclass(module_attr, GajimPlugin) or \
@ -653,16 +645,18 @@ class PluginManager(metaclass=Singleton):
pass pass
except configparser.NoOptionError: except configparser.NoOptionError:
# all fields are required # all fields are required
log.debug('%s : %s' % (module_attr_name, log.debug(
'wrong manifest file. all fields are required!')) '%s: wrong manifest file. all fields are required!',
module_attr_name)
except configparser.NoSectionError: except configparser.NoSectionError:
# info section are required # info section are required
log.debug('%s : %s' % (module_attr_name, log.debug(
'wrong manifest file. info section are required!')) '%s: wrong manifest file. info section are required!',
module_attr_name)
except configparser.MissingSectionHeaderError: except configparser.MissingSectionHeaderError:
# info section are required # info section are required
log.debug('%s : %s' % (module_attr_name, log.debug('%s: wrong manifest file. section are required!',
'wrong manifest file. section are required!')) module_attr_name)
sys.path.remove(path) sys.path.remove(path)
return plugins_found return plugins_found