Skip to content

Commit

Permalink
Pylint: remove bare excepts
Browse files Browse the repository at this point in the history
Bare excepts should not be used, because they may hide system exceptions such as KeyboardInterupts or SystemExits.
  • Loading branch information
MartinBasti committed Aug 31, 2016
1 parent 1e2b542 commit 61fbd89
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions dns/entropy.py
Expand Up @@ -70,14 +70,14 @@ def _maybe_seed(self):
if not self.seeded or self.seed_pid != os.getpid():
try:
seed = os.urandom(16)
except:
except Exception:
try:
r = open('/dev/urandom', 'rb', 0)
try:
seed = r.read(16)
finally:
r.close()
except:
except Exception:
seed = str(time.time())
self.seeded = True
self.seed_pid = os.getpid()
Expand Down Expand Up @@ -125,7 +125,7 @@ def random_between(self, first, last):

try:
system_random = random.SystemRandom()
except:
except Exception:
system_random = None

def random_16():
Expand Down
6 changes: 3 additions & 3 deletions dns/inet.py
Expand Up @@ -85,7 +85,7 @@ def af_for_address(text):
try:
dns.ipv4.inet_aton(text)
return AF_INET
except:
except Exception:
try:
dns.ipv6.inet_aton(text)
return AF_INET6
Expand All @@ -103,9 +103,9 @@ def is_multicast(text):
try:
first = ord(dns.ipv4.inet_aton(text)[0])
return first >= 224 and first <= 239
except:
except Exception:
try:
first = ord(dns.ipv6.inet_aton(text)[0])
return first == 255
except:
except Exception:
raise ValueError
6 changes: 3 additions & 3 deletions dns/message.py
Expand Up @@ -898,7 +898,7 @@ def _question_line(self, section):
raise dns.exception.SyntaxError
except dns.exception.SyntaxError:
raise dns.exception.SyntaxError
except:
except Exception:
rdclass = dns.rdataclass.IN
# Type
rdtype = dns.rdatatype.from_text(token.value)
Expand Down Expand Up @@ -931,7 +931,7 @@ def _rr_line(self, section):
raise dns.exception.SyntaxError
except dns.exception.SyntaxError:
raise dns.exception.SyntaxError
except:
except Exception:
ttl = 0
# Class
try:
Expand All @@ -944,7 +944,7 @@ def _rr_line(self, section):
rdclass = self.zone_rdclass
except dns.exception.SyntaxError:
raise dns.exception.SyntaxError
except:
except Exception:
rdclass = dns.rdataclass.IN
# Type
rdtype = dns.rdatatype.from_text(token.value)
Expand Down
2 changes: 1 addition & 1 deletion dns/name.py
Expand Up @@ -34,7 +34,7 @@

try:
maxint = sys.maxint
except:
except AttributeError:
maxint = (1 << (8 * struct.calcsize("P"))) // 2 - 1

NAMERELN_NONE = 0
Expand Down
2 changes: 1 addition & 1 deletion dns/query.py
Expand Up @@ -176,7 +176,7 @@ def _destination_and_source(af, where, port, source, source_port):
if af is None:
try:
af = dns.inet.af_for_address(where)
except:
except Exception:
af = dns.inet.AF_INET
if af == dns.inet.AF_INET:
destination = (where, port)
Expand Down
12 changes: 6 additions & 6 deletions dns/resolver.py
Expand Up @@ -1212,13 +1212,13 @@ def _getaddrinfo(host=None, service=None, family=socket.AF_UNSPEC, socktype=0,
addr = dns.ipv6.inet_aton(ahost)
v6addrs.append(host)
canonical_name = host
except:
except Exception:
try:
# Is it a V4 address literal?
addr = dns.ipv4.inet_aton(host)
v4addrs.append(host)
canonical_name = host
except:
except Exception:
if flags & socket.AI_NUMERICHOST == 0:
try:
if family == socket.AF_INET6 or family == socket.AF_UNSPEC:
Expand Down Expand Up @@ -1250,11 +1250,11 @@ def _getaddrinfo(host=None, service=None, family=socket.AF_UNSPEC, socktype=0,
port = 0
else:
port = int(service)
except:
except Exception:
if flags & socket.AI_NUMERICSERV == 0:
try:
port = socket.getservbyname(service)
except:
except Exception:
pass
if port is None:
raise socket.gaierror(socket.EAI_NONAME)
Expand Down Expand Up @@ -1329,7 +1329,7 @@ def _getfqdn(name=None):
name = socket.gethostname()
try:
return _getnameinfo(_getaddrinfo(name, 80)[0][4])[0]
except:
except Exception:
return name


Expand All @@ -1354,7 +1354,7 @@ def _gethostbyaddr(ip):
dns.ipv6.inet_aton(ip)
sockaddr = (ip, 80, 0, 0)
family = socket.AF_INET6
except:
except Exception:
sockaddr = (ip, 80)
family = socket.AF_INET
(name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
Expand Down
2 changes: 1 addition & 1 deletion dns/reversename.py
Expand Up @@ -51,7 +51,7 @@ def from_address(text):
else:
parts = [x for x in str(binascii.hexlify(v6).decode())]
origin = ipv6_reverse_domain
except:
except Exception:
parts = ['%d' %
byte for byte in bytearray(dns.ipv4.inet_aton(text))]
origin = ipv4_reverse_domain
Expand Down
6 changes: 3 additions & 3 deletions dns/zone.py
Expand Up @@ -658,7 +658,7 @@ def _rr_line(self):
raise dns.exception.SyntaxError
except dns.exception.SyntaxError:
raise dns.exception.SyntaxError
except:
except Exception:
rdclass = self.zone.rdclass
if rdclass != self.zone.rdclass:
raise dns.exception.SyntaxError("RR class is not zone's class")
Expand Down Expand Up @@ -777,7 +777,7 @@ def _generate_line(self):
raise dns.exception.SyntaxError
except dns.exception.SyntaxError:
raise dns.exception.SyntaxError
except:
except Exception:
rdclass = self.zone.rdclass
if rdclass != self.zone.rdclass:
raise dns.exception.SyntaxError("RR class is not zone's class")
Expand All @@ -787,7 +787,7 @@ def _generate_line(self):
token = self.tok.get()
if not token.is_identifier():
raise dns.exception.SyntaxError
except:
except Exception:
raise dns.exception.SyntaxError("unknown rdatatype '%s'" %
token.value)

Expand Down
4 changes: 2 additions & 2 deletions examples/zonediff.py
Expand Up @@ -199,15 +199,15 @@ def _open(what, err):
if proc.returncode == 0:
return proc.stdout
sys.stderr.write(err + "\n")
except:
except Exception:
sys.stderr.write(err + "\n")
if opts.tracebacks:
traceback.print_exc()
else:
# Open as normal file
try:
return open(what, 'rb')
except:
except IOError:
sys.stderr.write(err + "\n")
if opts.tracebacks:
traceback.print_exc()
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Expand Up @@ -19,7 +19,7 @@ disable=
assigning-non-slot,
bad-builtin,
bad-continuation,
bare-except,
broad-except,
deprecated-method,
fixme,
getslice-method,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_name.py
Expand Up @@ -86,13 +86,13 @@ def testTortureFromText(self):
for t in good:
try:
n = dns.name.from_text(t)
except:
except Exception:
self.fail("good test '%s' raised an exception" % t)
for t in bad:
caught = False
try:
n = dns.name.from_text(t)
except:
except Exception:
caught = True
if not caught:
self.fail("bad test '%s' did not raise an exception" % t)
Expand Down

0 comments on commit 61fbd89

Please sign in to comment.