bpo-11001: updated cookie docs (GH-13086) · python/cpython@91cc01f

Original file line numberDiff line numberDiff line change

@@ -55,8 +55,9 @@ in Cookie name (as :attr:`~Morsel.key`).

5555

.. class:: SimpleCookie([input])

5656
5757

This class derives from :class:`BaseCookie` and overrides :meth:`value_decode`

58-

and :meth:`value_encode` to be the identity and :func:`str` respectively.

59-
58+

and :meth:`value_encode`. SimpleCookie supports strings as cookie values.

59+

When setting the value, SimpleCookie calls the builtin :func:`str()` to convert

60+

the value to a string. Values received from HTTP are kept as strings.

6061
6162

.. seealso::

6263

@@ -76,15 +77,16 @@ Cookie Objects

7677
7778

.. method:: BaseCookie.value_decode(val)

7879
79-

Return a decoded value from a string representation. Return value can be any

80-

type. This method does nothing in :class:`BaseCookie` --- it exists so it can be

81-

overridden.

80+

Return a tuple ``(real_value, coded_value)`` from a string representation.

81+

``real_value`` can be any type. This method does no decoding in

82+

:class:`BaseCookie` --- it exists so it can be overridden.

8283
8384
8485

.. method:: BaseCookie.value_encode(val)

8586
86-

Return an encoded value. *val* can be any type, but return value must be a

87-

string. This method does nothing in :class:`BaseCookie` --- it exists so it can

87+

Return a tuple ``(real_value, coded_value)``. *val* can be any type, but

88+

``coded_value`` will always be converted to a string.

89+

This method does no encoding in :class:`BaseCookie` --- it exists so it can

8890

be overridden.

8991
9092

In general, it should be the case that :meth:`value_encode` and