mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Prefer 'except Exception:' to bare 'except:'
This commit is contained in:
parent
e10b22aca2
commit
c353225851
|
@ -84,7 +84,7 @@ class PillowTestCase(unittest.TestCase):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
all(x == y for x, y in zip(a, b)),
|
all(x == y for x, y in zip(a, b)),
|
||||||
msg or "got %s, expected %s" % (a, b))
|
msg or "got %s, expected %s" % (a, b))
|
||||||
except:
|
except Exception:
|
||||||
self.assertEqual(a, b, msg)
|
self.assertEqual(a, b, msg)
|
||||||
|
|
||||||
def assert_image(self, im, mode, size, msg=None):
|
def assert_image(self, im, mode, size, msg=None):
|
||||||
|
@ -149,7 +149,7 @@ class PillowTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
url = test_image_results.upload(a, b)
|
url = test_image_results.upload(a, b)
|
||||||
logger.error("Url for test images: %s" % url)
|
logger.error("Url for test images: %s" % url)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ def _mp_compile(self, sources, output_dir=None, macros=None,
|
||||||
pool = Pool(MAX_PROCS)
|
pool = Pool(MAX_PROCS)
|
||||||
try:
|
try:
|
||||||
print("Building using %d processes" % pool._processes)
|
print("Building using %d processes" % pool._processes)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
arr = [(self, obj, build, cc_args, extra_postargs, pp_opts)
|
arr = [(self, obj, build, cc_args, extra_postargs, pp_opts)
|
||||||
for obj in objects]
|
for obj in objects]
|
||||||
|
|
|
@ -971,7 +971,7 @@ class Image(object):
|
||||||
if isinstance(t, tuple):
|
if isinstance(t, tuple):
|
||||||
try:
|
try:
|
||||||
t = trns_im.palette.getcolor(t)
|
t = trns_im.palette.getcolor(t)
|
||||||
except:
|
except Exception:
|
||||||
raise ValueError("Couldn't allocate a palette "
|
raise ValueError("Couldn't allocate a palette "
|
||||||
"color for transparency")
|
"color for transparency")
|
||||||
trns_im.putpixel((0, 0), t)
|
trns_im.putpixel((0, 0), t)
|
||||||
|
@ -1008,7 +1008,7 @@ class Image(object):
|
||||||
if trns is not None:
|
if trns is not None:
|
||||||
try:
|
try:
|
||||||
new.info['transparency'] = new.palette.getcolor(trns)
|
new.info['transparency'] = new.palette.getcolor(trns)
|
||||||
except:
|
except Exception:
|
||||||
# if we can't make a transparent color, don't leave the old
|
# if we can't make a transparent color, don't leave the old
|
||||||
# transparency hanging around to mess us up.
|
# transparency hanging around to mess us up.
|
||||||
del(new.info['transparency'])
|
del(new.info['transparency'])
|
||||||
|
@ -1038,7 +1038,7 @@ class Image(object):
|
||||||
if new_im.mode == 'P':
|
if new_im.mode == 'P':
|
||||||
try:
|
try:
|
||||||
new_im.info['transparency'] = new_im.palette.getcolor(trns)
|
new_im.info['transparency'] = new_im.palette.getcolor(trns)
|
||||||
except:
|
except Exception:
|
||||||
del(new_im.info['transparency'])
|
del(new_im.info['transparency'])
|
||||||
warnings.warn("Couldn't allocate palette entry " +
|
warnings.warn("Couldn't allocate palette entry " +
|
||||||
"for transparency")
|
"for transparency")
|
||||||
|
|
|
@ -72,7 +72,7 @@ class ImageFont(object):
|
||||||
try:
|
try:
|
||||||
fullname = os.path.splitext(filename)[0] + ext
|
fullname = os.path.splitext(filename)[0] + ext
|
||||||
image = Image.open(fullname)
|
image = Image.open(fullname)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if image and image.mode in ("1", "L"):
|
if image and image.mode in ("1", "L"):
|
||||||
|
|
|
@ -124,7 +124,7 @@ class PhotoImage(object):
|
||||||
self.__photo.name = None
|
self.__photo.name = None
|
||||||
try:
|
try:
|
||||||
self.__photo.tk.call("image", "delete", name)
|
self.__photo.tk.call("image", "delete", name)
|
||||||
except:
|
except Exception:
|
||||||
pass # ignore internal errors
|
pass # ignore internal errors
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -244,7 +244,7 @@ class BitmapImage(object):
|
||||||
self.__photo.name = None
|
self.__photo.name = None
|
||||||
try:
|
try:
|
||||||
self.__photo.tk.call("image", "delete", name)
|
self.__photo.tk.call("image", "delete", name)
|
||||||
except:
|
except Exception:
|
||||||
pass # ignore internal errors
|
pass # ignore internal errors
|
||||||
|
|
||||||
def width(self):
|
def width(self):
|
||||||
|
|
|
@ -181,14 +181,14 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
fd = self.fp.fileno()
|
fd = self.fp.fileno()
|
||||||
length = os.fstat(fd).st_size
|
length = os.fstat(fd).st_size
|
||||||
except:
|
except Exception:
|
||||||
fd = -1
|
fd = -1
|
||||||
try:
|
try:
|
||||||
pos = self.fp.tell()
|
pos = self.fp.tell()
|
||||||
self.fp.seek(0, 2)
|
self.fp.seek(0, 2)
|
||||||
length = self.fp.tell()
|
length = self.fp.tell()
|
||||||
self.fp.seek(pos, 0)
|
self.fp.seek(pos, 0)
|
||||||
except:
|
except Exception:
|
||||||
length = -1
|
length = -1
|
||||||
|
|
||||||
self.tile = [('jpeg2k', (0, 0) + self.size, 0,
|
self.tile = [('jpeg2k', (0, 0) + self.size, 0,
|
||||||
|
@ -250,7 +250,7 @@ def _save(im, fp, filename):
|
||||||
if hasattr(fp, "fileno"):
|
if hasattr(fp, "fileno"):
|
||||||
try:
|
try:
|
||||||
fd = fp.fileno()
|
fd = fp.fileno()
|
||||||
except:
|
except Exception:
|
||||||
fd = -1
|
fd = -1
|
||||||
|
|
||||||
im.encoderconfig = (
|
im.encoderconfig = (
|
||||||
|
|
|
@ -75,7 +75,7 @@ def APP(self, marker):
|
||||||
try:
|
try:
|
||||||
jfif_unit = i8(s[7])
|
jfif_unit = i8(s[7])
|
||||||
jfif_density = i16(s, 8), i16(s, 10)
|
jfif_density = i16(s, 8), i16(s, 10)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if jfif_unit == 1:
|
if jfif_unit == 1:
|
||||||
|
@ -107,7 +107,7 @@ def APP(self, marker):
|
||||||
# extract Adobe custom properties
|
# extract Adobe custom properties
|
||||||
try:
|
try:
|
||||||
adobe_transform = i8(s[1])
|
adobe_transform = i8(s[1])
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.info["adobe_transform"] = adobe_transform
|
self.info["adobe_transform"] = adobe_transform
|
||||||
|
@ -441,7 +441,7 @@ def _fixup_dict(src_dict):
|
||||||
try:
|
try:
|
||||||
if len(value) == 1 and not isinstance(value, dict):
|
if len(value) == 1 and not isinstance(value, dict):
|
||||||
return value[0]
|
return value[0]
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ def _getmp(self):
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v2(head)
|
info = TiffImagePlugin.ImageFileDirectory_v2(head)
|
||||||
info.load(file_contents)
|
info.load(file_contents)
|
||||||
mp = dict(info)
|
mp = dict(info)
|
||||||
except:
|
except Exception:
|
||||||
raise SyntaxError("malformed MP Index (unreadable directory)")
|
raise SyntaxError("malformed MP Index (unreadable directory)")
|
||||||
# it's an error not to have a number of images
|
# it's an error not to have a number of images
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -340,7 +340,7 @@ class PngStream(ChunkStream):
|
||||||
self.im_size = i32(s), i32(s[4:])
|
self.im_size = i32(s), i32(s[4:])
|
||||||
try:
|
try:
|
||||||
self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))]
|
self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))]
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if i8(s[12]):
|
if i8(s[12]):
|
||||||
self.im_info["interlace"] = 1
|
self.im_info["interlace"] = 1
|
||||||
|
|
|
@ -231,7 +231,7 @@ class _PyAccessI16_B(PyAccess):
|
||||||
pixel = self.pixels[y][x]
|
pixel = self.pixels[y][x]
|
||||||
try:
|
try:
|
||||||
color = min(color, 65535)
|
color = min(color, 65535)
|
||||||
except:
|
except Exception:
|
||||||
color = min(color[0], 65535)
|
color = min(color[0], 65535)
|
||||||
|
|
||||||
pixel.l = color >> 8
|
pixel.l = color >> 8
|
||||||
|
|
|
@ -210,7 +210,7 @@ def loadImageSeries(filelist=None):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
im = Image.open(img).convert2byte()
|
im = Image.open(img).convert2byte()
|
||||||
except:
|
except Exception:
|
||||||
if not isSpiderImage(img):
|
if not isSpiderImage(img):
|
||||||
print(img + " is not a Spider image file")
|
print(img + " is not a Spider image file")
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1413,7 +1413,7 @@ def _save(im, fp, filename):
|
||||||
ifd[key] = info.get(key)
|
ifd[key] = info.get(key)
|
||||||
try:
|
try:
|
||||||
ifd.tagtype[key] = info.tagtype[key]
|
ifd.tagtype[key] = info.tagtype[key]
|
||||||
except:
|
except Exception:
|
||||||
pass # might not be an IFD, Might not have populated type
|
pass # might not be an IFD, Might not have populated type
|
||||||
|
|
||||||
# additions written by Greg Couch, gregc@cgl.ucsf.edu
|
# additions written by Greg Couch, gregc@cgl.ucsf.edu
|
||||||
|
|
|
@ -119,7 +119,7 @@ endlocal
|
||||||
def clean():
|
def clean():
|
||||||
try:
|
try:
|
||||||
shutil.rmtree('../build')
|
shutil.rmtree('../build')
|
||||||
except:
|
except Exception:
|
||||||
# could already be removed
|
# could already be removed
|
||||||
pass
|
pass
|
||||||
run_script(('virtualenvs', setup_vms()))
|
run_script(('virtualenvs', setup_vms()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user