A token for the accessing reflex BaseState instances. This token type implies subtree hierarchy population and other semantic checks.
| 122 | |
| 123 | |
| 124 | class BaseStateToken(StateToken["BaseState"]): |
| 125 | """A token for the accessing reflex BaseState instances. |
| 126 | |
| 127 | This token type implies subtree hierarchy population and other semantic checks. |
| 128 | """ |
| 129 | |
| 130 | @property |
| 131 | def cache_key(self) -> str: |
| 132 | """The key used for caching state instances in the StateManager. |
| 133 | |
| 134 | BaseState tokens use just the ident because the entire state hierarchy |
| 135 | lives under a single root state instance per session. |
| 136 | |
| 137 | Returns: |
| 138 | The token ident. |
| 139 | """ |
| 140 | return self.ident |
| 141 | |
| 142 | def with_cls(self, cls: type[BaseState]) -> Self: |
| 143 | """Return a new token with the cls field updated to the provided class. |
| 144 | |
| 145 | Args: |
| 146 | cls: The class to update the cls field to. |
| 147 | |
| 148 | Returns: |
| 149 | A new StateToken instance with the updated cls field. |
| 150 | """ |
| 151 | return super().with_cls(cls) |
| 152 | |
| 153 | def __str__(self) -> str: |
| 154 | """The key used in the underlying StateManager store. |
| 155 | |
| 156 | Returns: |
| 157 | A string representation of the token, which is a combination of the ident and cls name. |
| 158 | """ |
| 159 | # urlencode the redis token to escape the slash delimiter. |
| 160 | return f"{self.ident}_{self.cls.get_full_name()}" |
| 161 | |
| 162 | @classmethod |
| 163 | def serialize(cls, state: BaseState) -> bytes: |
| 164 | """Serialize the BaseState for redis/disk storage. |
| 165 | |
| 166 | Args: |
| 167 | state: The BaseState to serialize. |
| 168 | |
| 169 | Returns: |
| 170 | The serialized state. |
| 171 | """ |
| 172 | return state._serialize() |
| 173 | |
| 174 | @classmethod |
| 175 | def deserialize( |
| 176 | cls, data: bytes | None = None, fp: BinaryIO | None = None |
| 177 | ) -> BaseState: |
| 178 | """Deserialize the BaseState from redis/disk. |
| 179 | |
| 180 | data and fp are mutually exclusive, but one must be provided. |
| 181 |
no outgoing calls