mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Merge pull request #4385 from jdufresne/try-block
Limit try block to code expected to raise an exception
This commit is contained in:
commit
892aec306b
|
@ -401,15 +401,17 @@ def _getdecoder(mode, decoder_name, args, extra=()):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
decoder = DECODERS[decoder_name]
|
decoder = DECODERS[decoder_name]
|
||||||
return decoder(mode, *args + extra)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
return decoder(mode, *args + extra)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# get decoder
|
# get decoder
|
||||||
decoder = getattr(core, decoder_name + "_decoder")
|
decoder = getattr(core, decoder_name + "_decoder")
|
||||||
return decoder(mode, *args + extra)
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise OSError("decoder %s not available" % decoder_name)
|
raise OSError("decoder %s not available" % decoder_name)
|
||||||
|
return decoder(mode, *args + extra)
|
||||||
|
|
||||||
|
|
||||||
def _getencoder(mode, encoder_name, args, extra=()):
|
def _getencoder(mode, encoder_name, args, extra=()):
|
||||||
|
@ -422,15 +424,17 @@ def _getencoder(mode, encoder_name, args, extra=()):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
encoder = ENCODERS[encoder_name]
|
encoder = ENCODERS[encoder_name]
|
||||||
return encoder(mode, *args + extra)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
return encoder(mode, *args + extra)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# get encoder
|
# get encoder
|
||||||
encoder = getattr(core, encoder_name + "_encoder")
|
encoder = getattr(core, encoder_name + "_encoder")
|
||||||
return encoder(mode, *args + extra)
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise OSError("encoder %s not available" % encoder_name)
|
raise OSError("encoder %s not available" % encoder_name)
|
||||||
|
return encoder(mode, *args + extra)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user