You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cookie.py 818B

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