diff options
Diffstat (limited to 'sphinx/builders/linkcheck.py')
-rw-r--r-- | sphinx/builders/linkcheck.py | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 9544d5b35..911c58c12 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -34,7 +34,6 @@ if False: from typing import Any, Dict, List, Set, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.util.requests.requests import Response # NOQA - from sphinx.util.typing import unicode # NOQA logger = logging.getLogger(__name__) @@ -44,7 +43,7 @@ class AnchorCheckParser(HTMLParser): """Specialized HTML parser that looks for a specific anchor.""" def __init__(self, search_anchor): - # type: (unicode) -> None + # type: (str) -> None super(AnchorCheckParser, self).__init__() self.search_anchor = search_anchor @@ -59,7 +58,7 @@ class AnchorCheckParser(HTMLParser): def check_anchor(response, anchor): - # type: (Response, unicode) -> bool + # type: (Response, str) -> bool """Reads HTML data from a response object `response` searching for `anchor`. Returns True if anchor was found, False otherwise. """ @@ -87,9 +86,9 @@ class CheckExternalLinksBuilder(Builder): self.to_ignore = [re.compile(x) for x in self.app.config.linkcheck_ignore] self.anchors_ignore = [re.compile(x) for x in self.app.config.linkcheck_anchors_ignore] - self.good = set() # type: Set[unicode] - self.broken = {} # type: Dict[unicode, unicode] - self.redirected = {} # type: Dict[unicode, Tuple[unicode, int]] + self.good = set() # type: Set[str] + self.broken = {} # type: Dict[str, str] + self.redirected = {} # type: Dict[str, Tuple[str, int]] # set a timeout for non-responding servers socket.setdefaulttimeout(5.0) # create output file @@ -117,7 +116,7 @@ class CheckExternalLinksBuilder(Builder): kwargs['timeout'] = self.app.config.linkcheck_timeout def check_uri(): - # type: () -> Tuple[unicode, unicode, int] + # type: () -> Tuple[str, str, int] # split off anchor if '#' in uri: req_url, anchor = uri.split('#', 1) @@ -181,7 +180,7 @@ class CheckExternalLinksBuilder(Builder): return 'redirected', new_url, 0 def check(): - # type: () -> Tuple[unicode, unicode, int] + # type: () -> Tuple[str, str, int] # check for various conditions without bothering the network if len(uri) == 0 or uri.startswith(('#', 'mailto:', 'ftp:')): return 'unchecked', '', 0 @@ -220,7 +219,7 @@ class CheckExternalLinksBuilder(Builder): self.rqueue.put((uri, docname, lineno, status, info, code)) def process_result(self, result): - # type: (Tuple[unicode, unicode, int, unicode, unicode, int]) -> None + # type: (Tuple[str, str, int, str, str, int]) -> None uri, docname, lineno, status, info, code = result if status == 'unchecked': return @@ -258,19 +257,19 @@ class CheckExternalLinksBuilder(Builder): logger.info(color('redirect ') + uri + color(' - ' + text + ' to ' + info)) def get_target_uri(self, docname, typ=None): - # type: (unicode, unicode) -> unicode + # type: (str, str) -> str return '' def get_outdated_docs(self): - # type: () -> Set[unicode] + # type: () -> Set[str] return self.env.found_docs def prepare_writing(self, docnames): - # type: (Set[unicode]) -> None + # type: (Set[str]) -> None return def write_doc(self, docname, doctree): - # type: (unicode, nodes.Node) -> None + # type: (str, nodes.Node) -> None logger.info('') n = 0 for node in doctree.traverse(nodes.reference): @@ -293,7 +292,7 @@ class CheckExternalLinksBuilder(Builder): self.app.statuscode = 1 def write_entry(self, what, docname, line, uri): - # type: (unicode, unicode, int, unicode) -> None + # type: (str, str, int, str) -> None with open(path.join(self.outdir, 'output.txt'), 'a', encoding='utf-8') as output: output.write("%s:%s: [%s] %s\n" % (self.env.doc2path(docname, None), line, what, uri)) @@ -305,7 +304,7 @@ class CheckExternalLinksBuilder(Builder): def setup(app): - # type: (Sphinx) -> Dict[unicode, Any] + # type: (Sphinx) -> Dict[str, Any] app.add_builder(CheckExternalLinksBuilder) app.add_config_value('linkcheck_ignore', [], None) |