Add type annotations to 30 files across jw.util, resolving all 191 'no-untyped-def' mypy errors in strict mode. The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch, Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session, rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult, and all db/schema files (Column, Table, ColumnSet, DataType, Schema, SingleForeignKey, CompositeForeignKey), plus asyncio variants and ev/base/Object and auth/dummy/Auth. Additionally, unreachable code and type annotation conflicts were resolved in StopWatch.py, Options.py, rows.py, and Table.py. Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
146 lines
4.3 KiB
Python
146 lines
4.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any, TYPE_CHECKING, override
|
|
|
|
from ...Config import Config
|
|
from ...log import WARNING, slog
|
|
from ..Auth import Access
|
|
from ..Auth import Auth as AuthBase
|
|
from ..Auth import Entity as EntityBase
|
|
from ..Auth import Group as Group # Needed by jwutils utility layer
|
|
from ..Auth import User as User # Needed by jwutils utility layer
|
|
from ..Auth import Kind, ProjectFlags
|
|
|
|
if TYPE_CHECKING:
|
|
from typing import Mapping, Sequence
|
|
|
|
class Entity(EntityBase): # export
|
|
|
|
def __init__(
|
|
self,
|
|
*,
|
|
auth: AuthBase,
|
|
name: str,
|
|
conf: Config,
|
|
kind: Kind,
|
|
**kwargs: Any,
|
|
) -> None:
|
|
super().__init__(**kwargs)
|
|
self.__name = name
|
|
self.__conf = conf
|
|
self.__kind = kind
|
|
self.__auth = auth
|
|
self.__groups: list[Entity] | None = None
|
|
self.__email: str = conf['email']
|
|
|
|
@property
|
|
def conf(self) -> Config:
|
|
return self.__conf
|
|
|
|
@override
|
|
def _name(self) -> str:
|
|
return self.__name
|
|
|
|
@override
|
|
def _groups(self) -> Sequence[Entity]:
|
|
if self.__kind != Kind.User:
|
|
return []
|
|
if self.__groups is None:
|
|
name: str = ''
|
|
ret: list[Entity] = []
|
|
for name in self.conf['groups']:
|
|
ret.append(
|
|
Entity(
|
|
auth = self.__auth,
|
|
name = name,
|
|
kind = Kind.Group,
|
|
conf = Config(),
|
|
)
|
|
)
|
|
self.__groups = ret
|
|
return self.__groups
|
|
|
|
@override
|
|
def _email(self) -> str:
|
|
return self.__email
|
|
|
|
@override
|
|
def _kind(self) -> Kind:
|
|
return self.__kind
|
|
|
|
@override
|
|
def _projects(self, flags: ProjectFlags) -> Sequence[str]:
|
|
return []
|
|
|
|
class Auth(AuthBase): # export
|
|
|
|
def __init__(self, conf: Config, **kwargs: Any) -> None:
|
|
super().__init__(conf, **kwargs)
|
|
self.___users: dict[str, EntityBase] | None = None
|
|
self.__groups = None
|
|
self.__current_user: EntityBase | None = None
|
|
self.__user_by_email: dict[str, EntityBase] | None = None
|
|
|
|
@property
|
|
def __users(self) -> dict[str, EntityBase]:
|
|
if self.___users is None:
|
|
ret: dict[str, EntityBase] = {}
|
|
for name in self.conf.entries('user'):
|
|
conf = self.conf.branch('user.' + name)
|
|
assert conf is not None, 'Config is None'
|
|
ret[name] = Entity(
|
|
auth = self,
|
|
name = name,
|
|
conf = conf,
|
|
kind = Kind.User,
|
|
)
|
|
self.___users = ret
|
|
return self.___users
|
|
|
|
@override
|
|
def _access(
|
|
self, what: str, access_type: Access | None, who: EntityBase | None
|
|
) -> bool:
|
|
slog(
|
|
WARNING,
|
|
f'Returning False for {access_type} access to resource {what} by {who}'
|
|
)
|
|
return False
|
|
|
|
@override
|
|
def _entity(self, name: str, kind: Kind) -> EntityBase:
|
|
if kind != Kind.User:
|
|
raise NotImplementedError(
|
|
'Support for retrieving groups is not implemented'
|
|
)
|
|
return self.__users[name]
|
|
|
|
@override
|
|
def _entities(self, kind: Kind) -> Mapping[str, EntityBase]:
|
|
if kind != Kind.User:
|
|
raise NotImplementedError(
|
|
'Support for retrieving all groups is not implemented'
|
|
)
|
|
return self.__users
|
|
|
|
@override
|
|
def _current_entity(self) -> EntityBase:
|
|
if self.__current_user is None:
|
|
self.__current_user = self._entity(
|
|
self.conf['current_user'],
|
|
kind = Kind.User,
|
|
)
|
|
return self.__current_user
|
|
|
|
@override
|
|
def _entity_by_email(self, email: str, kind: Kind) -> EntityBase:
|
|
if kind != Kind.User:
|
|
raise NotImplementedError(
|
|
'Support for retrieving groups by email is not implemented'
|
|
)
|
|
if self.__user_by_email is None:
|
|
ret: dict[str, EntityBase] = dict()
|
|
for user in self.__users.values():
|
|
ret[user.email] = user
|
|
self.__user_by_email = ret
|
|
return self.__user_by_email[email]
|