Debian Codegraph @

django/http/cookie.py

raw
1 from http import cookies
2
3 # For backwards compatibility in Django 2.1.
4 SimpleCookie = cookies.SimpleCookie
5
6
7 def parse_cookie(cookie):
8 """
9 Return a dictionary parsed from a `Cookie:` header string.
10 """
11 cookiedict = {}
12 for chunk in cookie.split(";"):
13 if "=" in chunk:
14 key, val = chunk.split("=", 1)
15 else:
16 # Assume an empty name per
17 # https://bugzilla.mozilla.org/show_bug.cgi?id=169091
18 key, val = "", chunk
19 key, val = key.strip(), val.strip()
20 if key or val:
21 # unquote using Python's algorithm.
22 cookiedict[key] = cookies._unquote(val)
23 return cookiedict