Skip to content

Commit d1e4a57

Browse files
Address review comments
1 parent f67449d commit d1e4a57

5 files changed

Lines changed: 25 additions & 12 deletions

File tree

Doc/deprecations/pending-removal-in-3.19.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ Pending removal in Python 3.19
2222
supported depending on the backend implementation of hash functions.
2323
Prefer passing the initial data as a positional argument for maximum
2424
backwards compatibility.
25+
26+
* :mod:`http.cookies`:
27+
28+
* :meth:`http.cookies.BaseCookie.js_output` is deprecated and will be
29+
removed in Python 3.19.
30+
31+
This method generates a JavaScript snippet to set cookies in the browser,
32+
which is no longer considered a standard or recommended approach.
33+
Use :meth:`~http.cookies.BaseCookie.output` instead to generate HTTP
34+
headers.

Doc/library/http.cookies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Cookie Objects
110110
The meaning for *attrs* is the same as in :meth:`output`.
111111

112112
.. deprecated:: 3.15
113-
:meth:`!js_output` is deprecated and will be removed in Python 3.17.
113+
:meth:`!js_output` is deprecated and will be removed in Python 3.19.
114114
Use :meth:`output` instead.
115115

116116

Doc/whatsnew/3.15.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,8 +1741,10 @@ New deprecations
17411741
(Contributed by Bénédikt Tran in :gh:`134978`.)
17421742

17431743

1744+
* :mod:`http.cookies`
1745+
17441746
* :meth:`http.cookies.BaseCookie.js_output` is deprecated and will be
1745-
removed in Python 3.17. Use
1747+
removed in Python 3.19. Use
17461748
:meth:`~http.cookies.BaseCookie.output` instead.
17471749
(Contributed by kishorhange111 in :gh:`148849`.)
17481750

Lib/http/cookies.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,12 @@ def __repr__(self):
540540
l.append('%s=%s' % (key, repr(value.value)))
541541
return '<%s: %s>' % (self.__class__.__name__, _spacejoin(l))
542542

543-
@warnings.deprecated(
544-
"http.cookies.BaseCookie.js_output() is deprecated and will "
545-
"be removed in Python 3.17; use output() instead"
546-
)
547543
def js_output(self, attrs=None):
544+
warnings._deprecated(
545+
"http.cookies.BaseCookie.js_output",
546+
"3.19",
547+
"Use output() instead"
548+
)
548549
"""Return a string suitable for JavaScript."""
549550
result = []
550551
items = sorted(self.items())

Lib/test/test_http_cookies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_load(self):
176176
self.assertEqual(C.output(['path']),
177177
'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
178178
cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme; Version=1').decode('ascii')
179-
with self.assertWarnsRegex(DeprecationWarning, "BaseCookie.js_output"):
179+
with self.assertWarnsRegex(DeprecationWarning, r"BaseCookie\.js_output"):
180180
self.assertEqual(C.js_output(), fr"""
181181
<script type="text/javascript">
182182
<!-- begin hiding
@@ -185,7 +185,7 @@ def test_load(self):
185185
</script>
186186
""")
187187
cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme').decode('ascii')
188-
with self.assertWarnsRegex(DeprecationWarning, "BaseCookie.js_output"):
188+
with self.assertWarnsRegex(DeprecationWarning, r"BaseCookie\.js_output"):
189189
self.assertEqual(C.js_output(['path']), fr"""
190190
<script type="text/javascript">
191191
<!-- begin hiding
@@ -295,7 +295,7 @@ def test_quoted_meta(self):
295295
self.assertEqual(C.output(['path']),
296296
'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
297297
expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1').decode('ascii')
298-
with self.assertWarnsRegex(DeprecationWarning, "BaseCookie.js_output"):
298+
with self.assertWarnsRegex(DeprecationWarning, r"BaseCookie\.js_output"):
299299
self.assertEqual(C.js_output(), fr"""
300300
<script type="text/javascript">
301301
<!-- begin hiding
@@ -304,7 +304,7 @@ def test_quoted_meta(self):
304304
</script>
305305
""")
306306
expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme').decode('ascii')
307-
with self.assertWarnsRegex(DeprecationWarning, "BaseCookie.js_output"):
307+
with self.assertWarnsRegex(DeprecationWarning, r"BaseCookie\.js_output"):
308308
self.assertEqual(C.js_output(['path']), fr"""
309309
<script type="text/javascript">
310310
<!-- begin hiding
@@ -676,7 +676,7 @@ def test_control_characters_output(self):
676676
morsel._key = c0 # Override private variable.
677677
cookie = cookies.SimpleCookie()
678678
cookie["cookie"] = morsel
679-
with self.assertWarnsRegex(DeprecationWarning, "BaseCookie.js_output"):
679+
with self.assertWarnsRegex(DeprecationWarning, r"BaseCookie\.js_output"):
680680
with self.assertRaises(cookies.CookieError):
681681
cookie.js_output()
682682

@@ -685,7 +685,7 @@ def test_control_characters_output(self):
685685
morsel._coded_value = c0 # Override private variable.
686686
cookie = cookies.SimpleCookie()
687687
cookie["cookie"] = morsel
688-
with self.assertWarnsRegex(DeprecationWarning, "BaseCookie.js_output"):
688+
with self.assertWarnsRegex(DeprecationWarning, r"BaseCookie\.js_output"):
689689
with self.assertRaises(cookies.CookieError):
690690
cookie.js_output()
691691

0 commit comments

Comments
 (0)