src/genro_asgi/session/avatar.py¶
Source from this local checkout, regenerated when the reader rebuilds.
Line links use #L<number>; a GitHub line range opens its first line.
1 # Copyright 2025 Softwell S.r.l.2 #3 # Licensed under the Apache License, Version 2.0 (the "License");4 # you may not use this file except in compliance with the License.5 # You may obtain a copy of the License at6 #7 # https://www.apache.org/licenses/LICENSE-2.08 #9 # Unless required by applicable law or agreed to in writing, software10 # distributed under the License is distributed on an "AS IS" BASIS,11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 # See the License for the specific language governing permissions and13 # limitations under the License.14 15 """Avatar — the ONE authenticated identity type across the package.16 17 An ``Avatar`` is a plain slotted value object: an identity string, its18 authorization tags, and an extensible ``Bag`` of per-user data. ``AuthCore``19 returns it and sessions carry it — "nobody" is ``None`` uniformly, never an20 anonymous Avatar. The constructor normalizes ``tags=None`` to an empty list21 (the identity boundary for e.g. a JWT null tags claim). No framework machinery.22 """23 24 from __future__ import annotations25 26 from genro_bag import Bag27 28 __all__ = ["Avatar"]29 30 31 class Avatar:32 """User identity with authorization tags and extensible Bag data."""33 34 __slots__ = ("_identity", "_tags", "_data")35 36 def __init__(self, identity: str, tags: list[str] | None = None) -> None:37 """Build the avatar; ``tags=None`` normalizes to an empty list."""38 self._identity = identity39 self._tags = list(tags) if tags else []40 self._data = Bag()41 42 @property43 def identity(self) -> str:44 """User identifier (username, email, ...)."""45 return self._identity46 47 @property48 def tags(self) -> list[str]:49 """Authorization tags (roles/permissions)."""50 return self._tags51 52 @property53 def data(self) -> Bag:54 """Extensible per-user data as a Bag."""55 return self._data