From 3392c54dd0d775f5f0c2b79f6db3388a64011e38 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 3 Dec 2008 21:37:05 +0000 Subject: [PATCH] [thorstenp] fix empty exception clauses --- src/common/connection_handlers.py | 2 +- src/common/rst_xhtml_generator.py | 2 +- src/common/xmpp/auth.py | 6 ++++-- src/common/xmpp/features.py | 6 ++++-- src/common/xmpp/filetransfer.py | 14 +++++++++---- src/common/xmpp/protocol.py | 24 +++++++++++++++-------- src/common/xmpp/session.py | 6 ++++-- src/common/xmpp/simplexml.py | 27 ++++++++++++++++---------- src/common/xmpp/transports.py | 18 +++++++++++------ src/common/xmpp/transports_nb.py | 18 +++++++++++------ src/common/zeroconf/client_zeroconf.py | 6 +++--- src/config.py | 2 +- src/gtkgui_helpers.py | 2 +- src/htmltextview.py | 3 ++- 14 files changed, 88 insertions(+), 48 deletions(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 5c97ba87a..24d3e4072 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -2333,7 +2333,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, for jid in raw_roster: try: j = helpers.parse_jid(jid) - except: + except Exception: print >> sys.stderr, _('JID %s is not RFC compliant. It will not be added to your roster. Use roster management tools such as http://jru.jabberstudio.org/ to remove it') % jid else: infos = raw_roster[jid] diff --git a/src/common/rst_xhtml_generator.py b/src/common/rst_xhtml_generator.py index 315b011ad..c65387d15 100644 --- a/src/common/rst_xhtml_generator.py +++ b/src/common/rst_xhtml_generator.py @@ -27,7 +27,7 @@ try: from docutils.parsers.rst import roles from docutils import nodes,utils from docutils.parsers.rst.roles import set_classes -except: +except ImportError: print "Requires docutils 0.4 for set_classes to be available" def create_xhtml(text): return None diff --git a/src/common/xmpp/auth.py b/src/common/xmpp/auth.py index 1c7721cb8..733346123 100644 --- a/src/common/xmpp/auth.py +++ b/src/common/xmpp/auth.py @@ -161,8 +161,10 @@ class SASL(PlugIn): if challenge.getNamespace()!=NS_SASL: return if challenge.getName()=='failure': self.startsasl='failure' - try: reason=challenge.getChildren()[0] - except: reason=challenge + try: + reason=challenge.getChildren()[0] + except Exception: + reason=challenge self.DEBUG('Failed SASL authentification: %s'%reason,'error') raise NodeProcessed elif challenge.getName()=='success': diff --git a/src/common/xmpp/features.py b/src/common/xmpp/features.py index 277e7c8d3..4cee5d6f6 100644 --- a/src/common/xmpp/features.py +++ b/src/common/xmpp/features.py @@ -149,7 +149,8 @@ def getPrivacyLists(disp): if list_.getName()=='list': dict_['lists'].append(list_.getAttr('name')) else: dict_[list_.getName()]=list_.getAttr('name') return dict_ - except: pass + except Exception: + pass def getPrivacyList(disp,listname): """ Requests specific privacy list listname. Returns list of XML nodes (rules) @@ -157,7 +158,8 @@ def getPrivacyList(disp,listname): try: resp=disp.SendAndWaitForResponse(Iq('get',NS_PRIVACY,payload=[Node('list',{'name':listname})])) if isResultNode(resp): return resp.getQueryPayload()[0] - except: pass + except Exception: + pass def setActivePrivacyList(disp,listname=None,typ='active'): """ Switches privacy list 'listname' to specified type. diff --git a/src/common/xmpp/filetransfer.py b/src/common/xmpp/filetransfer.py index 6624a1143..6afefe3e3 100644 --- a/src/common/xmpp/filetransfer.py +++ b/src/common/xmpp/filetransfer.py @@ -69,8 +69,10 @@ class IBB(PlugIn): err=None sid,blocksize=stanza.getTagAttr('open','sid'),stanza.getTagAttr('open','block-size') self.DEBUG('StreamOpenHandler called sid->%s blocksize->%s'%(sid,blocksize),'info') - try: blocksize=int(blocksize) - except: err=ERR_BAD_REQUEST + try: + blocksize=int(blocksize) + except Exception: + err=ERR_BAD_REQUEST if not sid or not blocksize: err=ERR_BAD_REQUEST elif sid in self._streams.keys(): err=ERR_UNEXPECTED_REQUEST if err: rep=Error(stanza,err) @@ -137,8 +139,12 @@ class IBB(PlugIn): """ sid,seq,data=stanza.getTagAttr('data','sid'),stanza.getTagAttr('data','seq'),stanza.getTagData('data') self.DEBUG('ReceiveHandler called sid->%s seq->%s'%(sid,seq),'info') - try: seq=int(seq); data=base64.decodestring(data) - except: seq=''; data='' + try: + seq=int(seq) + data=base64.decodestring(data) + except Exception: + seq='' + data='' err=None if not sid in self._streams.keys(): err=ERR_ITEM_NOT_FOUND else: diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py index 5f553941b..eb9c3136f 100644 --- a/src/common/xmpp/protocol.py +++ b/src/common/xmpp/protocol.py @@ -326,22 +326,30 @@ class Protocol(Node): self.timestamp=None for d in self.getTags('delay',namespace=NS_DELAY2): try: - if d.getAttr('stamp') 0: errno = self.exc_args[0] strerror = self.exc_args[1] - except: pass + except Exception: + pass self.parent.__init__(self, errno, strerror) @@ -112,7 +113,8 @@ class SSLWrapper: if len(ppeer) == 2 and isinstance(ppeer[0], basestring) \ and isinstance(ppeer[1], int): self.peer = ppeer - except: pass + except Exception: + pass def __str__(self): s = str(self.__class__) @@ -356,8 +358,10 @@ class NonBlockingTcp(PlugIn, IdleObject): def pollend(self, retry=False): if not self.printed_error: self.printed_error = True - try: self._do_receive(errors_only=True) - except: log.error("pollend: Got exception from _do_receive:", exc_info=True) + try: + self._do_receive(errors_only=True) + except Exception: + log.error("pollend: Got exception from _do_receive:", exc_info=True) conn_failure_cb = self.on_connect_failure self.disconnect() if conn_failure_cb: @@ -381,8 +385,10 @@ class NonBlockingTcp(PlugIn, IdleObject): except socket.error, e: if e[0] != errno.ENOTCONN: log.error("Error shutting down socket for %s:", self.getName(), exc_info=True) - try: sock.close() - except: log.error("Error closing socket for %s:", self.getName(), exc_info=True) + try: + sock.close() + except Exception: + log.error("Error closing socket for %s:", self.getName(), exc_info=True) # socket descriptor cannot be (un)plugged anymore self.fd = -1 if self.on_disconnect: diff --git a/src/common/zeroconf/client_zeroconf.py b/src/common/zeroconf/client_zeroconf.py index 0b842e239..6952636c5 100644 --- a/src/common/zeroconf/client_zeroconf.py +++ b/src/common/zeroconf/client_zeroconf.py @@ -105,7 +105,7 @@ class ZeroconfListener(IdleObject): self.started = False try: self._serv.close() - except: + except socket.error: pass self.conn_holder.kill_all_connections() @@ -343,7 +343,7 @@ class P2PConnection(IdleObject, PlugIn): self._sock = socket.socket(*ai[:3]) self._sock.setblocking(False) self._server = ai[4] - except: + except socket.error: if sys.exc_value[0] != errno.EINPROGRESS: # for all errors, we try other addresses self.connect_to_next_ip() @@ -491,7 +491,7 @@ class P2PConnection(IdleObject, PlugIn): try: self._sock.shutdown(socket.SHUT_RDWR) self._sock.close() - except: + except socket.error: # socket is already closed pass self.fd = -1 diff --git a/src/config.py b/src/config.py index c072c7419..494b573d8 100644 --- a/src/config.py +++ b/src/config.py @@ -640,7 +640,7 @@ class PreferencesWindow: tv = gtk.TextView() try: gtkspell.Spell(tv, lang) - except: + except Exception: dialogs.ErrorDialog( _('Dictionary for lang %s not available') % lang, _('You have to install %s dictionary to use spellchecking, or ' diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 6fadb53b1..d86014bdc 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -795,7 +795,7 @@ default_name = ''): # Save image try: pixbuf.save(file_path, type_) - except: + except Exception: if os.path.exists(file_path): os.remove(file_path) new_file_path = '.'.join(file_path.split('.')[:-1]) + '.jpeg' diff --git a/src/htmltextview.py b/src/htmltextview.py index b6395b2ae..ce7f72db5 100644 --- a/src/htmltextview.py +++ b/src/htmltextview.py @@ -1046,7 +1046,8 @@ if __name__ == '__main__': change_cursor = tag elif tag == tag_table.lookup('focus-out-line'): over_line = True - except: pass + except Exception: + pass #if line_tooltip.timeout != 0: # Check if we should hide the line tooltip