Fix #2990: linkcheck raises "Can't convert 'bytes' object to str implicitly" error if linkcheck_anchors enabled

This commit is contained in:
Hiroaki Itoh 2016-10-06 18:59:24 +09:00 committed by Takeshi KOMIYA
parent 4c7bec6460
commit 42604a1ff6
4 changed files with 35 additions and 1 deletions

View File

@ -51,6 +51,7 @@ class AnchorCheckParser(HTMLParser):
for key, value in attrs:
if key in ('id', 'name') and value == self.search_anchor:
self.found = True
break
def check_anchor(response, anchor):
@ -61,7 +62,7 @@ def check_anchor(response, anchor):
try:
# Read file in chunks. If we find a matching anchor, we break
# the loop early in hopes not to have to download the whole thing.
for chunk in response.iter_content():
for chunk in response.iter_content(chunk_size=4096, decode_unicode=True):
parser.feed(chunk)
if parser.found:
break

View File

@ -0,0 +1,4 @@
master_doc = 'links'
source_suffix = '.txt'
exclude_patterns = ['_build']
linkcheck_anchors = True

View File

@ -0,0 +1,4 @@
This is from CPython documentation.
* Also, if there is a `default namespace <https://www.w3.org/TR/2006/REC-xml-names-20060816/#defaulting>`__, that full URI gets prepended to all of the non-prefixed tags.
* The `SSMEDIAN <https://help.gnome.org/users/gnumeric/stable/gnumeric.html#gnumeric-function-SSMEDIAN>`_ function in the Gnome Gnumeric spreadsheet.

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
test_build_linkcheck
~~~~~~~~~~~~~~~~~~~~
Test the build process with manpage builder with the test root.
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
from util import with_app
@with_app('linkcheck', testroot='linkcheck', freshenv=True)
def test_all(app, status, warning):
app.builder.build_all()
assert (app.outdir / 'output.txt').exists()
content = (app.outdir / 'output.txt').text()
# expect all ok
assert not content