Mercurial > hg
changeset 13930:0b7853aee5ae
zeroconf: clean up naked exceptions
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 13 Apr 2011 12:57:24 -0500 |
parents | cff56a0ed18e |
children | c3372529247f |
files | hgext/zeroconf/Zeroconf.py |
diffstat | 1 files changed, 18 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/zeroconf/Zeroconf.py Mon Apr 11 21:44:22 2011 +0300 +++ b/hgext/zeroconf/Zeroconf.py Wed Apr 13 12:57:24 2011 -0500 @@ -237,14 +237,14 @@ """Class accessor""" try: return _CLASSES[clazz] - except: + except KeyError: return "?(%s)" % (clazz) def getType(self, type): """Type accessor""" try: return _TYPES[type] - except: + except KeyError: return "?(%s)" % (type) def toString(self, hdr, other): @@ -360,7 +360,7 @@ """String representation""" try: return socket.inet_ntoa(self.address) - except: + except Exception: return self.address class DNSHinfo(DNSRecord): @@ -790,7 +790,7 @@ """Adds an entry""" try: list = self.cache[entry.key] - except: + except KeyError: list = self.cache[entry.key] = [] list.append(entry) @@ -799,7 +799,7 @@ try: list = self.cache[entry.key] list.remove(entry) - except: + except KeyError: pass def get(self, entry): @@ -808,7 +808,7 @@ try: list = self.cache[entry.key] return list[list.index(entry)] - except: + except KeyError: return None def getByDetails(self, name, type, clazz): @@ -821,7 +821,7 @@ """Returns a list of entries whose key matches the name.""" try: return self.cache[name] - except: + except KeyError: return [] def entries(self): @@ -829,7 +829,7 @@ def add(x, y): return x+y try: return reduce(add, self.cache.values()) - except: + except Exception: return [] @@ -869,10 +869,10 @@ for socket in rr: try: self.readers[socket].handle_read() - except: + except Exception: if not globals()['_GLOBAL_DONE']: traceback.print_exc() - except: + except Exception: pass def getReaders(self): @@ -988,7 +988,7 @@ callback = lambda x: self.listener.removeService(x, self.type, record.alias) self.list.append(callback) return - except: + except Exception: if not expired: self.services[record.alias.lower()] = record callback = lambda x: self.listener.addService(x, self.type, record.alias) @@ -1117,7 +1117,7 @@ result[key] = value self.properties = result - except: + except Exception: traceback.print_exc() self.properties = None @@ -1255,7 +1255,7 @@ try: self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - except: + except Exception: # SO_REUSEADDR should be equivalent to SO_REUSEPORT for # multicast UDP sockets (p 731, "TCP/IP Illustrated, # Volume 2"), but some BSD-derived systems require @@ -1270,7 +1270,7 @@ self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1) try: self.socket.bind(self.group) - except: + except Exception: # Some versions of linux raise an exception even though # the SO_REUSE* options have been set, so ignore it # @@ -1370,7 +1370,7 @@ self.servicetypes[info.type]-=1 else: del self.servicetypes[info.type] - except: + except KeyError: pass now = currentTimeMillis() nextTime = now @@ -1455,7 +1455,7 @@ try: self.listeners.remove(listener) self.notifyAll() - except: + except Exception: pass def updateRecord(self, now, rec): @@ -1528,7 +1528,7 @@ out.addAnswer(msg, DNSText(question.name, _TYPE_TXT, _CLASS_IN | _CLASS_UNIQUE, _DNS_TTL, service.text)) if question.type == _TYPE_SRV: out.addAdditionalAnswer(DNSAddress(service.server, _TYPE_A, _CLASS_IN | _CLASS_UNIQUE, _DNS_TTL, service.address)) - except: + except Exception: traceback.print_exc() if out is not None and out.answers: @@ -1541,7 +1541,7 @@ #temp = DNSIncoming(out.packet()) try: self.socket.sendto(out.packet(), 0, (addr, port)) - except: + except Exception: # Ignore this, it may be a temporary loss of network connection pass