MCPcopy Create free account
hub / github.com/EasyIME/PIME / parse_cookie

Function parse_cookie

python/python3/tornado/httputil.py:1111–1134  ·  view source on GitHub ↗

Parse a ``Cookie`` HTTP header into a dict of name/value pairs. This function attempts to mimic browser cookie parsing behavior; it specifically does not follow any of the cookie-related RFCs (because browsers don't either). The algorithm used is identical to that used by Django ve

(cookie: str)

Source from the content-addressed store, hash-verified

1109
1110
1111def parse_cookie(cookie: str) -> Dict[str, str]:
1112 """Parse a ``Cookie`` HTTP header into a dict of name/value pairs.
1113
1114 This function attempts to mimic browser cookie parsing behavior;
1115 it specifically does not follow any of the cookie-related RFCs
1116 (because browsers don't either).
1117
1118 The algorithm used is identical to that used by Django version 1.9.10.
1119
1120 .. versionadded:: 4.4.2
1121 """
1122 cookiedict = {}
1123 for chunk in cookie.split(str(";")):
1124 if str("=") in chunk:
1125 key, val = chunk.split(str("="), 1)
1126 else:
1127 # Assume an empty name per
1128 # https://bugzilla.mozilla.org/show_bug.cgi?id=169091
1129 key, val = str(""), chunk
1130 key, val = key.strip(), val.strip()
1131 if key or val:
1132 # unquote using Python's algorithm.
1133 cookiedict[key] = _unquote_cookie(val)
1134 return cookiedict

Callers 4

test_python_cookiesMethod · 0.90
test_cookie_edgecasesMethod · 0.90
test_invalid_cookiesMethod · 0.90
cookiesMethod · 0.85

Calls 2

_unquote_cookieFunction · 0.85
splitMethod · 0.80

Tested by 3

test_python_cookiesMethod · 0.72
test_cookie_edgecasesMethod · 0.72
test_invalid_cookiesMethod · 0.72