mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Fix #2474: Add `intersphinx_timeout option to sphinx.ext.intersphinx`
This commit is contained in:
@@ -112,6 +112,7 @@ Features added
|
|||||||
* #1604: epub3 builder: Obey font-related CSS when viewing in iBooks.
|
* #1604: epub3 builder: Obey font-related CSS when viewing in iBooks.
|
||||||
* #646: ``option`` directive support '.' character as a part of options
|
* #646: ``option`` directive support '.' character as a part of options
|
||||||
* Add document about kindlegen and fix document structure for it.
|
* Add document about kindlegen and fix document structure for it.
|
||||||
|
* #2474: Add ``intersphinx_timeout`` option to ``sphinx.ext.intersphinx``
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|||||||
@@ -121,3 +121,14 @@ linking:
|
|||||||
The maximum number of days to cache remote inventories. The default is
|
The maximum number of days to cache remote inventories. The default is
|
||||||
``5``, meaning five days. Set this to a negative value to cache inventories
|
``5``, meaning five days. Set this to a negative value to cache inventories
|
||||||
for unlimited time.
|
for unlimited time.
|
||||||
|
|
||||||
|
.. confval:: intersphinx_timeout
|
||||||
|
|
||||||
|
The number of seconds for timeout. The default is ``None``, meaning do not
|
||||||
|
timeout.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
timeout is not a time limit on the entire response download; rather, an
|
||||||
|
exception is raised if the server has not issued a response for timeout
|
||||||
|
seconds.
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ def _strip_basic_auth(url):
|
|||||||
return urlunsplit(frags)
|
return urlunsplit(frags)
|
||||||
|
|
||||||
|
|
||||||
def _read_from_url(url):
|
def _read_from_url(url, timeout=None):
|
||||||
"""Reads data from *url* with an HTTP *GET*.
|
"""Reads data from *url* with an HTTP *GET*.
|
||||||
|
|
||||||
This function supports fetching from resources which use basic HTTP auth as
|
This function supports fetching from resources which use basic HTTP auth as
|
||||||
@@ -161,7 +161,7 @@ def _read_from_url(url):
|
|||||||
:return: data read from resource described by *url*
|
:return: data read from resource described by *url*
|
||||||
:rtype: ``file``-like object
|
:rtype: ``file``-like object
|
||||||
"""
|
"""
|
||||||
r = requests.get(url, stream=True, headers=dict(useragent_header))
|
r = requests.get(url, stream=True, timeout=timeout, headers=dict(useragent_header))
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
r.raw.url = r.url
|
r.raw.url = r.url
|
||||||
return r.raw
|
return r.raw
|
||||||
@@ -202,7 +202,7 @@ def fetch_inventory(app, uri, inv):
|
|||||||
uri = _strip_basic_auth(uri)
|
uri = _strip_basic_auth(uri)
|
||||||
try:
|
try:
|
||||||
if '://' in inv:
|
if '://' in inv:
|
||||||
f = _read_from_url(inv)
|
f = _read_from_url(inv, timeout=app.config.intersphinx_timeout)
|
||||||
else:
|
else:
|
||||||
f = open(path.join(app.srcdir, inv), 'rb')
|
f = open(path.join(app.srcdir, inv), 'rb')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@@ -360,6 +360,7 @@ def missing_reference(app, env, node, contnode):
|
|||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_config_value('intersphinx_mapping', {}, True)
|
app.add_config_value('intersphinx_mapping', {}, True)
|
||||||
app.add_config_value('intersphinx_cache_limit', 5, False)
|
app.add_config_value('intersphinx_cache_limit', 5, False)
|
||||||
|
app.add_config_value('intersphinx_timeout', None, False)
|
||||||
app.connect('missing-reference', missing_reference)
|
app.connect('missing-reference', missing_reference)
|
||||||
app.connect('builder-inited', load_mappings)
|
app.connect('builder-inited', load_mappings)
|
||||||
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
|
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
|
||||||
|
|||||||
Reference in New Issue
Block a user