Fix: In python3 environment, make linkcheck cause "Can't convert 'bytes'

object to str implicitly" error when link target url has a hash part.
Thanks to Jorge_C. Closes #1457
This commit is contained in:
Takayuki Shimizukawa 2014-05-04 00:43:50 +09:00
parent 3ae8906447
commit 82a53382d5
2 changed files with 8 additions and 1 deletions

View File

@ -10,6 +10,9 @@ Bugs fixed
* #1363: Fix i18n: missing python domain's cross-references with currentmodule
directive or currentclass directive.
* #1444: autosummary does not create the description from attributes docstring.
* #1457: In python3 environment, make linkcheck cause "Can't convert 'bytes'
object to str implicitly" error when link target url has a hash part.
Thanks to Jorge_C.
Release 1.2.2 (released Mar 2, 2014)
====================================

View File

@ -24,6 +24,7 @@ from docutils import nodes
from sphinx.builders import Builder
from sphinx.util.console import purple, red, darkgreen, darkgray, \
darkred, turquoise
from sphinx.util.pycompat import TextIOWrapper
class RedirectHandler(HTTPRedirectHandler):
@ -142,7 +143,10 @@ class CheckExternalLinksBuilder(Builder):
# Read the whole document and see if #hash exists
req = Request(req_url)
f = opener.open(req, **kwargs)
found = check_anchor(f, unquote(hash))
encoding = 'utf-8'
if hasattr(f.headers, 'get_content_charset'):
encoding = f.headers.get_content_charset() or encoding
found = check_anchor(TextIOWrapper(f, encoding), unquote(hash))
f.close()
if not found: