mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Limit try block to code expected to raise an exception
In the off chance that the additional code in decoder()/encoder() raise a KeyError or AttributeError, a bug could be hidden.
This commit is contained in:
parent
a0a9b76ab5
commit
bd71374cd2
|
@ -401,15 +401,17 @@ def _getdecoder(mode, decoder_name, args, extra=()):
|
|||
|
||||
try:
|
||||
decoder = DECODERS[decoder_name]
|
||||
return decoder(mode, *args + extra)
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
return decoder(mode, *args + extra)
|
||||
|
||||
try:
|
||||
# get decoder
|
||||
decoder = getattr(core, decoder_name + "_decoder")
|
||||
return decoder(mode, *args + extra)
|
||||
except AttributeError:
|
||||
raise OSError("decoder %s not available" % decoder_name)
|
||||
return decoder(mode, *args + extra)
|
||||
|
||||
|
||||
def _getencoder(mode, encoder_name, args, extra=()):
|
||||
|
@ -422,15 +424,17 @@ def _getencoder(mode, encoder_name, args, extra=()):
|
|||
|
||||
try:
|
||||
encoder = ENCODERS[encoder_name]
|
||||
return encoder(mode, *args + extra)
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
return encoder(mode, *args + extra)
|
||||
|
||||
try:
|
||||
# get encoder
|
||||
encoder = getattr(core, encoder_name + "_encoder")
|
||||
return encoder(mode, *args + extra)
|
||||
except AttributeError:
|
||||
raise OSError("encoder %s not available" % encoder_name)
|
||||
return encoder(mode, *args + extra)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user