diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 5c97ba87a54a8f8ed4e6f16591fe183e90332f40..24d3e4072cd24b3e61cc605b782b532f5c6f6354 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 315b011adb4ff003f636dcda70c46544b94b309e..c65387d152c2ea2aa7264e594169f18b86d95d39 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 1c7721cb88cd7605e27d0380028b6888c01b871f..733346123dc8f9f4e6cba9e2fe73ef4874222ca8 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 277e7c8d38f6537041f8c9ad6cdb738d9eb8c120..4cee5d6f6ed7964d8f1c0a38649b00a58698208c 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 6624a114376841ac6c4ba1f4b0693d827c9237a2..6afefe3e34f255f6b6ea6434b833e251fec8988b 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 5f553941b57af347f89b44721d91015bafc0521e..eb9c3136f2b015a972156ff422c3d86fa239ffa1 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')<self.getTimestamp2(): self.setTimestamp(d.getAttr('stamp')) - except: pass + if d.getAttr('stamp') < self.getTimestamp2(): + self.setTimestamp(d.getAttr('stamp')) + except Exception: + pass if not self.timestamp: for x in self.getTags('x',namespace=NS_DELAY): try: - if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp')) - except: pass + if x.getAttr('stamp') < self.getTimestamp(): + self.setTimestamp(x.getAttr('stamp')) + except Exception: + pass if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp='' def getTo(self): """ Return value of the 'to' attribute. """ - try: return self['to'] - except: return None + try: + return self['to'] + except KeyError: + return None def getFrom(self): """ Return value of the 'from' attribute. """ - try: return self['from'] - except: return None + try: + return self['from'] + except KeyError: + return None def getTimestamp(self): """ Return the timestamp in the 'yyyymmddThhmmss' format. """ if self.timestamp: return self.timestamp diff --git a/src/common/xmpp/session.py b/src/common/xmpp/session.py index 0e77020787cdb9802031467003248f66ffba8039..aa19d1d62a15953410aadaca49e5873550526a9d 100644 --- a/src/common/xmpp/session.py +++ b/src/common/xmpp/session.py @@ -127,8 +127,10 @@ class Session: """ Reads all pending incoming data. Raises IOError on disconnection. Blocks until at least one byte is read.""" - try: received = self._recv(10240) - except: received = '' + try: + received = self._recv(10240) + except socket.error: + received = '' if len(received): # length of 0 means disconnect self.DEBUG(repr(self.fileno())+' '+received,'got') diff --git a/src/common/xmpp/simplexml.py b/src/common/xmpp/simplexml.py index fc735ffab590d7566362c169a7ff9730891d3529..7e10185f67d75e19840dd5a029603a7ff5a022f0 100644 --- a/src/common/xmpp/simplexml.py +++ b/src/common/xmpp/simplexml.py @@ -168,8 +168,7 @@ class Node(object): return self.attrs def getAttr(self, key): """ Returns value of specified attribute. """ - try: return self.attrs[key] - except: return None + return self.attrs.get(key) def getChildren(self): """ Returns all node's child nodes as list. """ return self.kids @@ -203,12 +202,16 @@ class Node(object): return self.getTags(name, attrs, namespace, one=1) def getTagAttr(self,tag,attr): """ Returns attribute value of the child with specified name (or None if no such attribute).""" - try: return self.getTag(tag).attrs[attr] - except: return None + try: + return self.getTag(tag).attrs[attr] + except: + return None def getTagData(self,tag): """ Returns cocatenated CDATA of the child with specified name.""" - try: return self.getTag(tag).getData() - except: return None + try: + return self.getTag(tag).getData() + except Exception: + return None def getTags(self, name, attrs={}, namespace=None, one=0): """ Filters all child nodes using specified arguments as filter. Returns the list of nodes found. """ @@ -264,13 +267,17 @@ class Node(object): def setTagAttr(self,tag,attr,val): """ Creates new node (if not already present) with name "tag" and sets it's attribute "attr" to value "val". """ - try: self.getTag(tag).attrs[attr]=val - except: self.addChild(tag,attrs={attr:val}) + try: + self.getTag(tag).attrs[attr]=val + except Exception: + self.addChild(tag,attrs={attr:val}) def setTagData(self,tag,val,attrs={}): """ Creates new node (if not already present) with name "tag" and (optionally) attributes "attrs" and sets it's CDATA to string "val". """ - try: self.getTag(tag,attrs).setData(ustr(val)) - except: self.addChild(tag,attrs,payload=[ustr(val)]) + try: + self.getTag(tag,attrs).setData(ustr(val)) + except Exception: + self.addChild(tag,attrs,payload=[ustr(val)]) def has_attr(self,key): """ Checks if node have attribute "key".""" return key in self.attrs diff --git a/src/common/xmpp/transports.py b/src/common/xmpp/transports.py index ad7e68f0f66ae05329e7e1aec33ac0949b7cf354..9fd83884ad93db09c527949e02e8376c69c54cab 100644 --- a/src/common/xmpp/transports.py +++ b/src/common/xmpp/transports.py @@ -100,8 +100,10 @@ class TCPsocket(PlugIn): self._recv=self._sock.recv self.DEBUG("Successfully connected to remote host %s"%repr(server),'start') return 'ok' - except: continue - except: pass + except Exception: + continue + except Exception: + pass def plugout(self): """ Disconnect from the remote server and unregister self.disconnected method from @@ -112,12 +114,16 @@ class TCPsocket(PlugIn): def receive(self): """ Reads all pending incoming data. Calls owner's disconnected() method if appropriate.""" - try: received = self._recv(1024000) - except: received = '' + try: + received = self._recv(1024000) + except socket.error: + received = '' while temp_failure_retry(select.select,[self._sock],[],[],0)[0]: - try: add = self._recv(1024000) - except: add='' + try: + add = self._recv(1024000) + except socket.error: + add='' received +=add if not add: break diff --git a/src/common/xmpp/transports_nb.py b/src/common/xmpp/transports_nb.py index df456c11ece20313f9ee8b48dcb1cdc02e08c52c..5414fc956fcabb6b576d10344624d31139587b75 100644 --- a/src/common/xmpp/transports_nb.py +++ b/src/common/xmpp/transports_nb.py @@ -102,7 +102,8 @@ class SSLWrapper: if self.exc_args[0] > 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 0b842e239ef24c5a6f6720aecd3b1aa22258d674..6952636c50d150c4d1eb37a1cbdb31fc8c1e0bf4 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 c072c74198cbb592a19161df3a4574d6f60ed9fa..494b573d86aa6cf467f0241e7584297dbb1c3f20 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 6fadb53b1c569dc6f4b324e97a950b94cfaf81f5..d86014bdc5fca5fb99e1db1e9ba73f914ed085e0 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 b6395b2ae1d4079c2ace6b1aa3a8c7dc0ee9a676..ce7f72db58418b42472e6de79742258fa3369ad6 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