Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-19670: Added SimpleCookie.value_encode/value_decode docs #21017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Lib/http/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,19 @@ def __parse_string(self, str, patt=_CookiePattern):


class SimpleCookie(BaseCookie):
"""
SimpleCookie supports strings as cookie values. When setting
"""SimpleCookie supports strings as cookie values. When setting
the value using the dictionary assignment notation, SimpleCookie
calls the builtin str() to convert the value to a string. Values
received from HTTP are kept as strings.
"""
def value_decode(self, val):
"""Return an unquoted string, from the cookie header in a reversed fasion of value_encode.
"""
return _unquote(val), val

def value_encode(self, val):
"""Return an escaped quoted string, if needed, for the cookie header usage.
Will include non-compliant characters in the cookie value if exist.
"""
strval = str(val)
return strval, _quote(strval)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
added documentation to `SimpleCookie.value_decode` and `SimpleCookie.value_encode`
Loading