Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkcheck: Use correct function to convert from UTC time to UNIX epoch #11649

Merged
merged 6 commits into from Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES
Expand Up @@ -6,6 +6,7 @@ Bugs fixed

* #11618: Fix a regression in the MoveModuleTargets transform,
introduced in #10478 (#9662).
* #11649: Use :py:func:`calendar.timegm` to convert from UTC time to UNIX epoch.
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved

Release 7.2.3 (released Aug 23, 2023)
=====================================
Expand All @@ -24,7 +25,7 @@ Bugs fixed
when ``autodoc_preserve_defaults`` is ``True``.
* Restore support string methods on path objects.
This is deprecated and will be removed in Sphinx 8.
Use :py:func`os.fspath` to convert :py:class:`~pathlib.Path` objects to strings,
Use :py:func:`os.fspath` to convert :py:class:`~pathlib.Path` objects to strings,
or :py:class:`~pathlib.Path`'s methods to work with path objects.

Release 7.2.2 (released Aug 17, 2023)
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/linkcheck.py
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import calendar
import contextlib
import json
import re
Expand Down Expand Up @@ -491,7 +492,7 @@ def limit_rate(self, response_url: str, retry_after: str) -> float | None:
parsed = parsedate_tz(retry_after)
assert parsed is not None
# the 10th element is the GMT offset in seconds
next_check = time.mktime(parsed[:9]) - (parsed[9] or 0)
next_check = float(calendar.timegm(parsed[:9])) - (parsed[9] or 0)
except (AssertionError, TypeError, ValueError):
# TypeError: Invalid date format.
# ValueError: Invalid date, e.g. Oct 52th.
Expand Down
20 changes: 16 additions & 4 deletions tests/test_build_linkcheck.py
Expand Up @@ -4,6 +4,7 @@

import http.server
import json
import os
import re
import textwrap
import time
Expand Down Expand Up @@ -772,11 +773,22 @@ def test_too_many_requests_retry_after_int_delay(app, capsys, status):
)


@pytest.mark.parametrize('tz', ['GMT', 'GMT+3', 'GMT-3'])
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
def test_too_many_requests_retry_after_HTTP_date(app, capsys):
retry_after = wsgiref.handlers.format_date_time(time.time())
with http_server(make_retry_after_handler([(429, retry_after), (200, None)])):
app.build()
def test_too_many_requests_retry_after_HTTP_date(app, capsys, tz):
old_tz = os.environ.get('TZ')
os.environ['TZ'] = tz
if hasattr(time, 'tzset'):
time.tzset()
try:
retry_after = wsgiref.handlers.format_date_time(time.time())
with http_server(make_retry_after_handler([(429, retry_after), (200, None)])):
app.build()
finally:
if old_tz is None:
del os.environ['TZ']
else:
os.environ['TZ'] = old_tz
content = (app.outdir / 'output.json').read_text(encoding='utf8')
assert json.loads(content) == {
"filename": "index.rst",
Expand Down