Merge pull request #2424 from radarhere/get

Replaced KeyError catch with dictionary get method
This commit is contained in:
Hugo 2017-02-25 10:56:08 +02:00 committed by GitHub
commit 77773fde43
4 changed files with 6 additions and 24 deletions

View File

@ -415,10 +415,7 @@ def _save(im, fp, filename, save_all=False):
def get_interlace(im):
try:
interlace = im.encoderinfo["interlace"]
except KeyError:
interlace = 1
interlace = im.encoderinfo.get("interlace", 1)
# workaround for @PIL153
if min(im.size) < 16:
@ -484,10 +481,7 @@ def _get_local_header(fp, im, offset, flags):
o8(0))
include_color_table = im.encoderinfo.get('include_color_table')
if include_color_table:
try:
palette = im.encoderinfo["palette"]
except KeyError:
palette = None
palette = im.encoderinfo.get("palette", None)
palette_bytes = _get_palette_bytes(im, palette, im.encoderinfo)[0]
color_table_size = _get_color_table_size(palette_bytes)
if color_table_size:

View File

@ -325,10 +325,7 @@ def _save(im, fp, filename, check=0):
except KeyError:
raise ValueError("Cannot save %s images as IM" % im.mode)
try:
frames = im.encoderinfo["frames"]
except KeyError:
frames = 1
frames = im.encoderinfo.get("frames", 1)
if check:
return check

View File

@ -2194,10 +2194,7 @@ def fromarray(obj, mode=None):
arr = obj.__array_interface__
shape = arr['shape']
ndim = len(shape)
try:
strides = arr['strides']
except KeyError:
strides = None
strides = arr.get('strides', None)
if mode is None:
try:
typekey = (1, 1) + shape[2:], arr['typestr']

View File

@ -38,10 +38,7 @@ class UI(Label):
self.update()
try:
duration = im.info["duration"]
except KeyError:
duration = 100
duration = im.info.get("duration", 100)
self.after(duration, self.next)
def next(self):
@ -64,10 +61,7 @@ class UI(Label):
except EOFError:
return # end of file
try:
duration = im.info["duration"]
except KeyError:
duration = 100
duration = im.info.get("duration", 100)
self.after(duration, self.next)
self.update_idletasks()