Issue #16261: Converted some bare except statements to except statements

with specified exception type.  Original patch by Ramchandra Apte.
This commit is contained in:
Serhiy Storchaka 2015-05-20 10:33:40 +03:00
parent 492f027793
commit ba9ac5b5c4
7 changed files with 13 additions and 13 deletions

View File

@ -23,7 +23,7 @@ from types import MappingProxyType
from weakref import WeakKeyDictionary from weakref import WeakKeyDictionary
try: try:
from _thread import RLock from _thread import RLock
except: except ImportError:
class RLock: class RLock:
'Dummy reentrant lock for builds without threads' 'Dummy reentrant lock for builds without threads'
def __enter__(self): pass def __enter__(self): pass

View File

@ -135,7 +135,7 @@ def v4_int_to_packed(address):
""" """
try: try:
return address.to_bytes(4, 'big') return address.to_bytes(4, 'big')
except: except OverflowError:
raise ValueError("Address negative or too large for IPv4") raise ValueError("Address negative or too large for IPv4")
@ -151,7 +151,7 @@ def v6_int_to_packed(address):
""" """
try: try:
return address.to_bytes(16, 'big') return address.to_bytes(16, 'big')
except: except OverflowError:
raise ValueError("Address negative or too large for IPv6") raise ValueError("Address negative or too large for IPv6")

View File

@ -465,7 +465,7 @@ try:
for libname in ['uuid', 'c']: for libname in ['uuid', 'c']:
try: try:
lib = ctypes.CDLL(ctypes.util.find_library(libname)) lib = ctypes.CDLL(ctypes.util.find_library(libname))
except: except Exception:
continue continue
if hasattr(lib, 'uuid_generate_random'): if hasattr(lib, 'uuid_generate_random'):
_uuid_generate_random = lib.uuid_generate_random _uuid_generate_random = lib.uuid_generate_random
@ -607,7 +607,7 @@ def uuid4():
try: try:
import os import os
return UUID(bytes=os.urandom(16), version=4) return UUID(bytes=os.urandom(16), version=4)
except: except Exception:
import random import random
return UUID(int=random.getrandbits(128), version=4) return UUID(int=random.getrandbits(128), version=4)

View File

@ -572,7 +572,7 @@ def getTclTkVersion(configfile, versionline):
""" """
try: try:
f = open(configfile, "r") f = open(configfile, "r")
except: except OSError:
fatal("Framework configuration file not found: %s" % configfile) fatal("Framework configuration file not found: %s" % configfile)
for l in f: for l in f:
@ -814,7 +814,7 @@ def downloadURL(url, fname):
except: except:
try: try:
os.unlink(fname) os.unlink(fname)
except: except OSError:
pass pass
def verifyThirdPartyFile(url, checksum, fname): def verifyThirdPartyFile(url, checksum, fname):

View File

@ -261,7 +261,7 @@ class SheetParser:
def end_int(self, text): def end_int(self, text):
try: try:
self.value = int(text) self.value = int(text)
except: except (TypeError, ValueError):
self.value = None self.value = None
end_long = end_int end_long = end_int
@ -269,13 +269,13 @@ class SheetParser:
def end_double(self, text): def end_double(self, text):
try: try:
self.value = float(text) self.value = float(text)
except: except (TypeError, ValueError):
self.value = None self.value = None
def end_complex(self, text): def end_complex(self, text):
try: try:
self.value = complex(text) self.value = complex(text)
except: except (TypeError, ValueError):
self.value = None self.value = None
def end_string(self, text): def end_string(self, text):
@ -763,7 +763,7 @@ class SheetGUI:
for cls in int, float, complex: for cls in int, float, complex:
try: try:
value = cls(text) value = cls(text)
except: except (TypeError, ValueError):
continue continue
else: else:
cell = NumericCell(value) cell = NumericCell(value)

View File

@ -25,7 +25,7 @@ def treat_file(filename, outfp):
"""Append tags found in file named 'filename' to the open file 'outfp'""" """Append tags found in file named 'filename' to the open file 'outfp'"""
try: try:
fp = open(filename, 'r') fp = open(filename, 'r')
except: except OSError:
sys.stderr.write('Cannot open %s\n'%filename) sys.stderr.write('Cannot open %s\n'%filename)
return return
charno = 0 charno = 0

View File

@ -127,7 +127,7 @@ def hexrepr(t, precision=4):
return 'None' return 'None'
try: try:
len(t) len(t)
except: except TypeError:
return '0x%0*X' % (precision, t) return '0x%0*X' % (precision, t)
try: try:
return '(' + ', '.join(['0x%0*X' % (precision, item) return '(' + ', '.join(['0x%0*X' % (precision, item)