From ab7f4c330629f24f006a35729ee0d758711312fa Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 30 Dec 2017 14:19:43 -0500 Subject: [PATCH] Refs #28965 -- Deprecated unused django.utils.http.cookie_date(). --- django/utils/http.py | 7 +++++++ docs/internals/deprecation.txt | 2 ++ docs/ref/utils.txt | 4 ++++ docs/releases/2.1.txt | 4 ++++ tests/utils_tests/test_http.py | 4 +++- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/django/utils/http.py b/django/utils/http.py index c1c616a6fd..2148630fd3 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -3,6 +3,7 @@ import calendar import datetime import re import unicodedata +import warnings from binascii import Error as BinasciiError from email.utils import formatdate from urllib.parse import ( @@ -13,6 +14,7 @@ from urllib.parse import ( from django.core.exceptions import TooManyFieldsSent from django.utils.datastructures import MultiValueDict +from django.utils.deprecation import RemovedInDjango30Warning from django.utils.encoding import force_bytes 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'. """ + 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) return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25]) diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 248a0c642e..f601b035ca 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -31,6 +31,8 @@ details on these changes. * ``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 ` for more details on these changes. diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index 03c9af0c46..d6127e3fed 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -682,6 +682,10 @@ escaping HTML. .. 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. Accepts a floating point number expressed in seconds since the epoch in diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index e1947728d9..3c9fad8ca5 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -249,6 +249,10 @@ Miscellaneous * The ``ForceRHR`` GIS function is deprecated in favor of the new :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: Features removed in 2.1 diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index 41bda81967..be3034b88f 100644 --- a/tests/utils_tests/test_http.py +++ b/tests/utils_tests/test_http.py @@ -1,8 +1,9 @@ import unittest 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.deprecation import RemovedInDjango30Warning from django.utils.http import ( base36_to_int, cookie_date, http_date, int_to_base36, is_safe_url, is_same_domain, parse_etags, parse_http_date, quote_etag, urlencode, @@ -254,6 +255,7 @@ class HttpDateProcessingTests(unittest.TestCase): t = 1167616461.0 self.assertEqual(http_date(t), 'Mon, 01 Jan 2007 01:54:21 GMT') + @ignore_warnings(category=RemovedInDjango30Warning) def test_cookie_date(self): t = 1167616461.0 self.assertEqual(cookie_date(t), 'Mon, 01-Jan-2007 01:54:21 GMT')