Be defensive and handle newly defined HTTP error code

This commit implements a change to the linkcheck builder to handle undefined
HTTP error code such as https://tools.ietf.org/html/rfc7538.
At the moment, Sphinx will fail with an internal error. With this change,
a non-registered HTTP error code will be treated in the same way as error
code 0 i.e. unknown code.
This commit is contained in:
Sebastien Besson
2019-09-23 12:05:09 +01:00
committed by Takeshi KOMIYA
parent 3dcd0e9b5b
commit a2bc070533

View File

@@ -237,13 +237,16 @@ class CheckExternalLinksBuilder(Builder):
else:
logger.info(red('broken ') + uri + red(' - ' + info))
elif status == 'redirected':
text, color = {
301: ('permanently', darkred),
302: ('with Found', purple),
303: ('with See Other', purple),
307: ('temporarily', turquoise),
0: ('with unknown code', purple),
}[code]
try:
text, color = {
301: ('permanently', darkred),
302: ('with Found', purple),
303: ('with See Other', purple),
307: ('temporarily', turquoise),
0: ('with unknown code', purple),
}[code]
except KeyError:
text, color = ('with unknown code', purple)
self.write_entry('redirected ' + text, docname, lineno,
uri + ' to ' + info)
logger.info(color('redirect ') + uri + color(' - ' + text + ' to ' + info))