Fix #2003: decode error under python2 (only) when `make linkcheck` is run

This commit is contained in:
Takeshi KOMIYA
2015-12-21 22:34:04 +09:00
parent f85d1a0b99
commit 8b57bc7227
2 changed files with 15 additions and 0 deletions
+2
View File
@@ -15,6 +15,8 @@ Bugs fixed
* #2171: Fix cannot linkcheck url with unicode
* #2182: LaTeX: support image file names with more than 1 dots
* #2189: Fix previous sibling link for first file in subdirectory uses last file, not intended previous from root toctree
* #2003: Fix decode error under python2 (only) when ``make linkcheck`` is run
Release 1.3.3 (released Dec 2, 2015)
+13
View File
@@ -95,6 +95,17 @@ def check_anchor(f, hash):
return parser.found
def get_content_charset(f):
content_type = f.headers.get('content-type')
if content_type:
params = (p.strip() for p in content_type.split(';')[1:])
for param in params:
if param.startswith('charset='):
return param[8:]
return None
class CheckExternalLinksBuilder(Builder):
"""
Checks for broken external links.
@@ -165,6 +176,8 @@ class CheckExternalLinksBuilder(Builder):
encoding = 'utf-8'
if hasattr(f.headers, 'get_content_charset'):
encoding = f.headers.get_content_charset() or encoding
else:
encoding = get_content_charset(f) or encoding
found = check_anchor(TextIOWrapper(f, encoding), unquote(hash))
f.close()