From 863e2f468f1ba63627bd87fe9edb4d3ba5e2f5d5 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 13 Feb 2016 08:55:55 -0500 Subject: [PATCH] moved more logic around --- sphinx/builders/linkcheck.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index ac28b7ed8..ecec3c9c9 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -137,8 +137,20 @@ class CheckExternalLinksBuilder(Builder): if self.app.config.linkcheck_timeout: kwargs['timeout'] = self.app.config.linkcheck_timeout - def check_uri(): + # split off anchor + if '#' in uri: + req_url, hash = uri.split('#', 1) + else: + req_url = uri + hash = None + + # handle non-ASCII URIs + try: + req_url.encode('ascii') + except UnicodeError: + req_url = encode_uri(req_url) + try: if hash and self.app.config.linkcheck_anchors: # Read the whole document and see if #hash exists @@ -203,19 +215,6 @@ class CheckExternalLinksBuilder(Builder): if rex.match(uri): return 'ignored', '', 0 - # split off anchor - if '#' in uri: - req_url, hash = uri.split('#', 1) - else: - req_url = uri - hash = None - - # handle non-ASCII URIs - try: - req_url.encode('ascii') - except UnicodeError: - req_url = encode_uri(req_url) - # need to actually check the URI for _ in range(self.app.config.linkcheck_retries): status, info, code = check_uri()