Refs #28965 -- Deprecated unused django.utils.http.cookie_date().
This commit is contained in:
parent
0afffae4ec
commit
ab7f4c3306
|
@ -3,6 +3,7 @@ import calendar
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
import warnings
|
||||||
from binascii import Error as BinasciiError
|
from binascii import Error as BinasciiError
|
||||||
from email.utils import formatdate
|
from email.utils import formatdate
|
||||||
from urllib.parse import (
|
from urllib.parse import (
|
||||||
|
@ -13,6 +14,7 @@ from urllib.parse import (
|
||||||
|
|
||||||
from django.core.exceptions import TooManyFieldsSent
|
from django.core.exceptions import TooManyFieldsSent
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
|
from django.utils.deprecation import RemovedInDjango30Warning
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.functional import keep_lazy_text
|
from django.utils.functional import keep_lazy_text
|
||||||
|
|
||||||
|
@ -118,6 +120,11 @@ def cookie_date(epoch_seconds=None):
|
||||||
|
|
||||||
Output a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
|
Output a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
|
||||||
"""
|
"""
|
||||||
|
warnings.warn(
|
||||||
|
'cookie_date() is deprecated in favor of http_date(), which follows '
|
||||||
|
'the format of the latest RFC.',
|
||||||
|
RemovedInDjango30Warning, stacklevel=2,
|
||||||
|
)
|
||||||
rfcdate = formatdate(epoch_seconds)
|
rfcdate = formatdate(epoch_seconds)
|
||||||
return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25])
|
return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25])
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ details on these changes.
|
||||||
|
|
||||||
* ``django.contrib.gis.db.models.functions.ForceRHR`` will be removed.
|
* ``django.contrib.gis.db.models.functions.ForceRHR`` will be removed.
|
||||||
|
|
||||||
|
* ``django.utils.http.cookie_date()`` will be removed.
|
||||||
|
|
||||||
See the :ref:`Django 2.1 release notes <deprecated-features-2.1>` for more
|
See the :ref:`Django 2.1 release notes <deprecated-features-2.1>` for more
|
||||||
details on these changes.
|
details on these changes.
|
||||||
|
|
||||||
|
|
|
@ -682,6 +682,10 @@ escaping HTML.
|
||||||
|
|
||||||
.. function:: cookie_date(epoch_seconds=None)
|
.. function:: cookie_date(epoch_seconds=None)
|
||||||
|
|
||||||
|
.. deprecated:: 2.1
|
||||||
|
|
||||||
|
Use :func:`http_date` instead, which follows the latest RFC.
|
||||||
|
|
||||||
Formats the time to ensure compatibility with Netscape's cookie standard.
|
Formats the time to ensure compatibility with Netscape's cookie standard.
|
||||||
|
|
||||||
Accepts a floating point number expressed in seconds since the epoch in
|
Accepts a floating point number expressed in seconds since the epoch in
|
||||||
|
|
|
@ -249,6 +249,10 @@ Miscellaneous
|
||||||
* The ``ForceRHR`` GIS function is deprecated in favor of the new
|
* The ``ForceRHR`` GIS function is deprecated in favor of the new
|
||||||
:class:`~django.contrib.gis.db.models.functions.ForcePolygonCW` function.
|
:class:`~django.contrib.gis.db.models.functions.ForcePolygonCW` function.
|
||||||
|
|
||||||
|
* ``django.utils.http.cookie_date()`` is deprecated in favor of
|
||||||
|
:func:`~django.utils.http.http_date`, which follows the format of the latest
|
||||||
|
RFC.
|
||||||
|
|
||||||
.. _removed-features-2.1:
|
.. _removed-features-2.1:
|
||||||
|
|
||||||
Features removed in 2.1
|
Features removed in 2.1
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase, ignore_warnings
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
|
from django.utils.deprecation import RemovedInDjango30Warning
|
||||||
from django.utils.http import (
|
from django.utils.http import (
|
||||||
base36_to_int, cookie_date, http_date, int_to_base36, is_safe_url,
|
base36_to_int, cookie_date, http_date, int_to_base36, is_safe_url,
|
||||||
is_same_domain, parse_etags, parse_http_date, quote_etag, urlencode,
|
is_same_domain, parse_etags, parse_http_date, quote_etag, urlencode,
|
||||||
|
@ -254,6 +255,7 @@ class HttpDateProcessingTests(unittest.TestCase):
|
||||||
t = 1167616461.0
|
t = 1167616461.0
|
||||||
self.assertEqual(http_date(t), 'Mon, 01 Jan 2007 01:54:21 GMT')
|
self.assertEqual(http_date(t), 'Mon, 01 Jan 2007 01:54:21 GMT')
|
||||||
|
|
||||||
|
@ignore_warnings(category=RemovedInDjango30Warning)
|
||||||
def test_cookie_date(self):
|
def test_cookie_date(self):
|
||||||
t = 1167616461.0
|
t = 1167616461.0
|
||||||
self.assertEqual(cookie_date(t), 'Mon, 01-Jan-2007 01:54:21 GMT')
|
self.assertEqual(cookie_date(t), 'Mon, 01-Jan-2007 01:54:21 GMT')
|
||||||
|
|
Loading…
Reference in New Issue