MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / get_cookie

Method get_cookie

21-async/mojifinder/bottle.py:1060–1069  ·  view source on GitHub ↗

Return the content of a cookie. To read a `Signed Cookie`, the `secret` must match the one used to create the cookie (see :meth:`BaseResponse.set_cookie`). If anything goes wrong (missing cookie or wrong signature), return a default value.

(self, key, default=None, secret=None)

Source from the content-addressed store, hash-verified

1058 return FormsDict((c.key, c.value) for c in cookies)
1059
1060 def get_cookie(self, key, default=None, secret=None):
1061 """ Return the content of a cookie. To read a `Signed Cookie`, the
1062 `secret` must match the one used to create the cookie (see
1063 :meth:`BaseResponse.set_cookie`). If anything goes wrong (missing
1064 cookie or wrong signature), return a default value. """
1065 value = self.cookies.get(key)
1066 if secret and value:
1067 dec = cookie_decode(value, secret) # (key, value) tuple or None
1068 return dec[1] if dec and dec[0] == key else default
1069 return value or default
1070
1071 @DictProperty('environ', 'bottle.request.query', read_only=True)
1072 def query(self):

Callers

nothing calls this directly

Calls 2

cookie_decodeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected