Skip to content

Commit f8924d8

Browse files
authored
fix RSt
1 parent 89a64bf commit f8924d8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Doc/library/http.cookies.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,22 @@ The following example demonstrates how to use the :mod:`http.cookies` module.
301301
Handling of Duplicate Cookies
302302
-----------------------------
303303

304-
As per `RFC 6265`_, the ``http.cookies`` module has been updated to handle duplicate cookies more in line with the standard practices recommended by the RFC. Previously, when multiple cookies with the same name were encountered, the last cookie value in the sequence was retained. The module now preserves the first cookie value encountered, aligning with the common behavior expected by user agents and web servers.
304+
As per `RFC 6265`_, the ``http.cookies`` module has been updated to better align with standard practices for handling duplicate cookies. Previously, if multiple cookies with the same name were encountered, the last value provided would be retained. With the update, the first value encountered for a given cookie name is preserved, reflecting the behavior commonly expected by web servers and user agents.
305305

306306
.. note::
307-
308-
This change ensures that when ``SimpleCookie`` parses a cookie string containing multiple cookies with the same name, it retains the first instance of such a cookie. This behavior is particularly relevant when cookies are set with different paths or domains, and the order of cookies in the HTTP header can imply precedence.
307+
This modification affects how ``SimpleCookie`` parses cookie strings containing multiple instances of the same cookie name. Now, the first instance is retained, which is particularly relevant when cookies are set with differing paths or domains, where the order in the HTTP header can imply precedence.
309308

310309
Example Usage:
311310

312-
.. doctest::
313-
:options: +NORMALIZE_WHITESPACE
311+
.. code-block:: python
312+
313+
from http.cookies import SimpleCookie
314+
315+
# Creating a SimpleCookie instance with duplicate cookies
316+
c = SimpleCookie('name=value1; name=value2')
314317
315-
>>> from http.cookies import SimpleCookie
316-
>>> c = SimpleCookie('name=value1; name=value2') # Creating a SimpleCookie instance with duplicate cookies
317-
>>> assert c['name'].value == 'value1' # The value of the first cookie is retained
318+
# The value of the first cookie is retained
319+
assert c['name'].value == 'value1'
318320
319321
.. _RFC 6265: https://datatracker.ietf.org/doc/html/rfc6265
320322

0 commit comments

Comments
 (0)