Created
February 8, 2013 12:18
-
-
Save anonymous/4738646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/doc/config.rst b/doc/config.rst | |
--- a/doc/config.rst | |
+++ b/doc/config.rst | |
@@ -1336,6 +1336,13 @@ | |
.. versionadded:: 1.1 | |
+.. confval:: linkcheck_retries | |
+ | |
+ The number of checking attempts before a link will be considered broken. | |
+ Default is 1 attempt. | |
+ | |
+ .. versionadded:: 1.2 | |
+ | |
.. confval:: linkcheck_workers | |
The number of worker threads to use when checking links. Default is 5 | |
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py | |
--- a/sphinx/builders/linkcheck.py | |
+++ b/sphinx/builders/linkcheck.py | |
@@ -124,22 +124,30 @@ | |
hash = None | |
# need to actually check the URI | |
- try: | |
- if hash and self.app.config.linkcheck_anchors: | |
- # Read the whole document and see if #hash exists | |
- f = opener.open(Request(req_url), **kwargs) | |
- found = check_anchor(f, unquote(hash)) | |
- f.close() | |
+ attempt_nr = 1 | |
+ while True: | |
+ try: | |
+ if hash and self.app.config.linkcheck_anchors: | |
+ # Read the whole document and see if #hash exists | |
+ f = opener.open(Request(req_url), **kwargs) | |
+ found = check_anchor(f, unquote(hash)) | |
+ f.close() | |
- if not found: | |
- raise Exception("Anchor '%s' not found" % hash) | |
- else: | |
- f = opener.open(HeadRequest(req_url), **kwargs) | |
- f.close() | |
+ if not found: | |
+ raise Exception("Anchor '%s' not found" % hash) | |
+ else: | |
+ f = opener.open(HeadRequest(req_url), **kwargs) | |
+ f.close() | |
+ # Link is not broken | |
+ break | |
+ except Exception, err: | |
+ if attempt_nr < self.app.config.linkcheck_retries: | |
+ attempt_nr += 1 | |
+ pass | |
+ else: | |
+ self.broken[uri] = str(err) | |
+ return 'broken', str(err) | |
- except Exception, err: | |
- self.broken[uri] = str(err) | |
- return 'broken', str(err) | |
if f.url.rstrip('/') == req_url.rstrip('/'): | |
self.good.add(uri) | |
return 'working', 'new' | |
diff --git a/sphinx/config.py b/sphinx/config.py | |
--- a/sphinx/config.py | |
+++ b/sphinx/config.py | |
@@ -195,6 +195,7 @@ | |
# linkcheck options | |
linkcheck_ignore = ([], None), | |
linkcheck_timeout = (None, None), | |
+ linkcheck_retries = (1, None), | |
linkcheck_workers = (5, None), | |
linkcheck_anchors = (True, None), | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment