Home / Class/ SecureCookieSession Class — flask Architecture

SecureCookieSession Class — flask Architecture

Architecture documentation for the SecureCookieSession class in sessions.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  d7fb9d4d_3951_5244_a49f_6217614cd3a9["SecureCookieSession"]
  22ae6a8e_9381_0dda_c9eb_5c5c7c0d67b1["SessionMixin"]
  d7fb9d4d_3951_5244_a49f_6217614cd3a9 -->|extends| 22ae6a8e_9381_0dda_c9eb_5c5c7c0d67b1
  f793a407_79ea_667a_f29e_29bbf57c781f["sessions.py"]
  d7fb9d4d_3951_5244_a49f_6217614cd3a9 -->|defined in| f793a407_79ea_667a_f29e_29bbf57c781f
  48b67f88_0886_1122_e715_98b8542670d0["__init__()"]
  d7fb9d4d_3951_5244_a49f_6217614cd3a9 -->|method| 48b67f88_0886_1122_e715_98b8542670d0
  a0a0665a_9a6e_670c_2986_b9742d1dd4a2["__getitem__()"]
  d7fb9d4d_3951_5244_a49f_6217614cd3a9 -->|method| a0a0665a_9a6e_670c_2986_b9742d1dd4a2
  dd770ec8_c848_909d_cc1c_2082f8bc5b07["get()"]
  d7fb9d4d_3951_5244_a49f_6217614cd3a9 -->|method| dd770ec8_c848_909d_cc1c_2082f8bc5b07
  25bac11e_b768_4e46_78ef_bee02f544a58["setdefault()"]
  d7fb9d4d_3951_5244_a49f_6217614cd3a9 -->|method| 25bac11e_b768_4e46_78ef_bee02f544a58

Relationship Graph

Source Code

src/flask/sessions.py lines 52–94

class SecureCookieSession(CallbackDict[str, t.Any], SessionMixin):
    """Base class for sessions based on signed cookies.

    This session backend will set the :attr:`modified` and
    :attr:`accessed` attributes. It cannot reliably track whether a
    session is new (vs. empty), so :attr:`new` remains hard coded to
    ``False``.
    """

    #: When data is changed, this is set to ``True``. Only the session
    #: dictionary itself is tracked; if the session contains mutable
    #: data (for example a nested dict) then this must be set to
    #: ``True`` manually when modifying that data. The session cookie
    #: will only be written to the response if this is ``True``.
    modified = False

    #: When data is read or written, this is set to ``True``. Used by
    # :class:`.SecureCookieSessionInterface` to add a ``Vary: Cookie``
    #: header, which allows caching proxies to cache different pages for
    #: different users.
    accessed = False

    def __init__(
        self,
        initial: c.Mapping[str, t.Any] | c.Iterable[tuple[str, t.Any]] | None = None,
    ) -> None:
        def on_update(self: te.Self) -> None:
            self.modified = True
            self.accessed = True

        super().__init__(initial, on_update)

    def __getitem__(self, key: str) -> t.Any:
        self.accessed = True
        return super().__getitem__(key)

    def get(self, key: str, default: t.Any = None) -> t.Any:
        self.accessed = True
        return super().get(key, default)

    def setdefault(self, key: str, default: t.Any = None) -> t.Any:
        self.accessed = True
        return super().setdefault(key, default)

Extends

Frequently Asked Questions

What is the SecureCookieSession class?
SecureCookieSession is a class in the flask codebase, defined in src/flask/sessions.py.
Where is SecureCookieSession defined?
SecureCookieSession is defined in src/flask/sessions.py at line 52.
What does SecureCookieSession extend?
SecureCookieSession extends SessionMixin.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free