BaseState

class gafaelfawr.middleware.state.BaseState

Bases: object

Base class for state information stored in a cookie.

Each application must implement this abstract base class and provide the class to the StateMiddleware constructor. This allows application-specific state while keeping the state middleware handling generic. The derived class must be a dataclass.

Methods Summary

from_cookie(cookie, request)

Reconstruct state from an encrypted cookie.

to_cookie()

Build an encrypted cookie representation of the state.

Methods Documentation

Reconstruct state from an encrypted cookie.

Parameters:
  • cookie (str) – The encrypted cookie value.

  • request (Request) – The request, used for logging.

Returns:

The state represented by the cookie.

Return type:

BaseState

Build an encrypted cookie representation of the state.

Returns:

The encrypted cookie value.

Return type:

str