In the code you linked to is another additional exception handler:
try:
yield safe_join(template_dir, template_name)
except UnicodeDecodeError:
# The template dir name was a bytestring that wasn't valid UTF-8.
raise
except ValueError:
# The joined path was located outside of template_dir.
pass
Since UnicodeDecodeError
is a subclass of ValueError
, the second exception handler would cause any UnicodeDecodeError
to be ignored. It looks like this would not be the intended effect and to avoid it the UnicodeDecodeError
is processed explicitly by the first handler. So with both handlers together a ValueError
is only ignored if it's not a UnicodeDecodeError
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…