jw-python/src/python/jw/util/auth/Auth.py

210 lines
5.4 KiB
Python
Raw Normal View History

from __future__ import annotations
import abc
from enum import Enum, Flag, auto
from typing import TYPE_CHECKING, Any, Self, Sequence, TypeAlias, cast
from ..Config import Config
from ..enum_helper import kebab_to_pascal
from ..log import ERR, WARNING, log
from ..misc import load_object
from ..stree.StringTree import StringTree
if TYPE_CHECKING:
from typing import Mapping
class Access(Enum): # export
Read = auto()
Modify = auto()
Create = auto()
Delete = auto()
class ProjectFlags(Flag): # export
NoFlags = auto()
Contributing = auto()
Active = auto()
class Kind(Flag):
Group = auto()
User = auto()
Both = Group | User
class Entity(abc.ABC): # export
@abc.abstractmethod
def _kind(self) -> Kind:
...
@property
def kind(self) -> Kind:
return self._kind()
@abc.abstractmethod
def _name(self) -> str:
...
@property
def name(self) -> str:
return self._name()
def _display_name(self) -> str:
return self._name()
@property
def display_name(self) -> str:
return self._display_name()
def _email(self) -> str:
return 'no-email@example.com'
@property
def email(self) -> str:
return self._email()
@abc.abstractmethod
def _groups(self) -> Sequence[Group]:
...
@property
def groups(self) -> Sequence[Group]:
return self._groups()
@abc.abstractmethod
def _projects(self, flags: ProjectFlags) -> Sequence[str]:
...
def projects(self, flags: ProjectFlags) -> Sequence[str]:
return self._projects(flags)
User: TypeAlias = Entity
Group: TypeAlias = Entity
class Auth(abc.ABC): # export
@classmethod
def load(
cls,
conf: Config | dict[str, Any] | StringTree,
base_type: type | None = None,
tp: str | None = None,
class_name_filter: str | None = None,
mypy: Fix disallow_incomplete_defs fallout Add parameter and return type annotations to untyped functions all over the package: - ldap.py: Add return types to Config properties (ldap_uri, bind_dn, bind_pw, base_dn), Connection.__init__, add, delete, walk, find, __oc_recurse_to_top, object_class_path, and inner callbacks - cast.py: Add Any import, add return type annotations to cast_str_to_bool, guess_type, from_str, from_env, cast_str, and parameter type annotations where missing - Table.py: - __init__ (schema: Schema) - __eq__ (rhs: Any) - _column_data_type (name: str) - _column_default (name: str) - column_default (name: str) - foreign_keys_to_parent_table (parent_table: Any) - misc.py: - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - multi_regex_edit (spec: Any) - dump_dict (*args: Any, **kwargs: Any) - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - dump (*args: Any, **kwargs: Any) - MapAttr2Shape.py, ShuntingYard.py, Queries.py: - Add parameter and return type annotations to fix disallow_incomplete_defs: - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - Queries.py: _run, _register, name property, __getitem__, keys, load, add, _add - Add parameter and return type annotations: - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - auth/Auth.py: load, conf, _entity, projects - auth/ldap/Auth.py: __init__, _create_entity - Fix parameter type annotations: - rows_check_not_null: keys: str | list[str], stat_key: str | None, caller: Any - rows_dumps: lead: str | list[str] | None, tablefmt: str | None - rows_dump: heading: str | None, lead: str | list[str] | None, tablefmt: str | None - Table.py: column_default, add_row_location, add_child_row_location - CompositeForeignKey.py: __table, parent_column, child_column - TableIoHandler.py: _load, _store, load - Query.py: _register, register, parent property - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - MapAttr2Shape.py, auth/ldap/Auth.py, Query.py: - MapAttr2Shape.py: Add None check for id, add None check for graph - auth/ldap/Auth.py: Add Any import, fix __init__ and _create_entity - Query.py: Fix _add, run, parent signatures - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - Config.py: dump - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - ShellCmd.py: __init__ - auth/Auth.py: load, __init__ - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - auth/ldap/Auth.py: Entity.__init__, Auth.__init__, _create_entity - cast.py: guess_type - DataBase.py: _create_session, _delete_session - TableIoHandler.py: load - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ - ldap.py: Config.__get__, Config properties, Connection methods, inner callbacks - misc.py: get_derived_classes, load_classes, load_class_names, load_object, multi_regex_edit, dump_dict, dump - multi_key_dict.py: items - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 22:34:10 +02:00
module_path: list[str] = ['jwutils.auth.{type}.Auth'],
module_extra_path: list[str] = [],
*args: Any,
**kwargs: Any,
) -> Self:
# == Prepare arguments
# -- conf
if isinstance(conf, dict):
conf = StringTree.from_dict(conf)
if isinstance(conf, StringTree):
conf = Config(tree = conf)
# -- tp
if tp is None:
val = conf.get('type')
if val is None:
msg = 'No type specified in auth configuration'
conf.dump(ERR, msg)
raise Exception(msg)
tp = val
# -- class_name_filter
if class_name_filter is None:
class_name_filter = 'Auth'
# -- base_type
if base_type is None:
base_type = cls
# -- Strings path and class_name_filter
Type = kebab_to_pascal(tp)
macros = {'type': tp, 'Type': Type}
path = [p.format(**macros) for p in module_path + module_extra_path]
class_name_filter = class_name_filter.format(**macros)
# == Do it
return cast(
'Self',
load_object(path, base_type, class_name_filter, conf, *args, **kwargs)
)
mypy: Fix disallow_incomplete_defs fallout Add parameter and return type annotations to untyped functions all over the package: - ldap.py: Add return types to Config properties (ldap_uri, bind_dn, bind_pw, base_dn), Connection.__init__, add, delete, walk, find, __oc_recurse_to_top, object_class_path, and inner callbacks - cast.py: Add Any import, add return type annotations to cast_str_to_bool, guess_type, from_str, from_env, cast_str, and parameter type annotations where missing - Table.py: - __init__ (schema: Schema) - __eq__ (rhs: Any) - _column_data_type (name: str) - _column_default (name: str) - column_default (name: str) - foreign_keys_to_parent_table (parent_table: Any) - misc.py: - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - multi_regex_edit (spec: Any) - dump_dict (*args: Any, **kwargs: Any) - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - dump (*args: Any, **kwargs: Any) - MapAttr2Shape.py, ShuntingYard.py, Queries.py: - Add parameter and return type annotations to fix disallow_incomplete_defs: - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - Queries.py: _run, _register, name property, __getitem__, keys, load, add, _add - Add parameter and return type annotations: - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - auth/Auth.py: load, conf, _entity, projects - auth/ldap/Auth.py: __init__, _create_entity - Fix parameter type annotations: - rows_check_not_null: keys: str | list[str], stat_key: str | None, caller: Any - rows_dumps: lead: str | list[str] | None, tablefmt: str | None - rows_dump: heading: str | None, lead: str | list[str] | None, tablefmt: str | None - Table.py: column_default, add_row_location, add_child_row_location - CompositeForeignKey.py: __table, parent_column, child_column - TableIoHandler.py: _load, _store, load - Query.py: _register, register, parent property - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - MapAttr2Shape.py, auth/ldap/Auth.py, Query.py: - MapAttr2Shape.py: Add None check for id, add None check for graph - auth/ldap/Auth.py: Add Any import, fix __init__ and _create_entity - Query.py: Fix _add, run, parent signatures - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - Config.py: dump - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - ShellCmd.py: __init__ - auth/Auth.py: load, __init__ - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - auth/ldap/Auth.py: Entity.__init__, Auth.__init__, _create_entity - cast.py: guess_type - DataBase.py: _create_session, _delete_session - TableIoHandler.py: load - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ - ldap.py: Config.__get__, Config properties, Connection methods, inner callbacks - misc.py: get_derived_classes, load_classes, load_class_names, load_object, multi_regex_edit, dump_dict, dump - multi_key_dict.py: items - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 22:34:10 +02:00
def __init__(self, conf: Config, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.__conf = conf
self.__base_entity_by_email: dict[str, Entity] | None = None
@property
mypy: Fix disallow_incomplete_defs fallout Add parameter and return type annotations to untyped functions all over the package: - ldap.py: Add return types to Config properties (ldap_uri, bind_dn, bind_pw, base_dn), Connection.__init__, add, delete, walk, find, __oc_recurse_to_top, object_class_path, and inner callbacks - cast.py: Add Any import, add return type annotations to cast_str_to_bool, guess_type, from_str, from_env, cast_str, and parameter type annotations where missing - Table.py: - __init__ (schema: Schema) - __eq__ (rhs: Any) - _column_data_type (name: str) - _column_default (name: str) - column_default (name: str) - foreign_keys_to_parent_table (parent_table: Any) - misc.py: - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - multi_regex_edit (spec: Any) - dump_dict (*args: Any, **kwargs: Any) - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - dump (*args: Any, **kwargs: Any) - MapAttr2Shape.py, ShuntingYard.py, Queries.py: - Add parameter and return type annotations to fix disallow_incomplete_defs: - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - Queries.py: _run, _register, name property, __getitem__, keys, load, add, _add - Add parameter and return type annotations: - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - auth/Auth.py: load, conf, _entity, projects - auth/ldap/Auth.py: __init__, _create_entity - Fix parameter type annotations: - rows_check_not_null: keys: str | list[str], stat_key: str | None, caller: Any - rows_dumps: lead: str | list[str] | None, tablefmt: str | None - rows_dump: heading: str | None, lead: str | list[str] | None, tablefmt: str | None - Table.py: column_default, add_row_location, add_child_row_location - CompositeForeignKey.py: __table, parent_column, child_column - TableIoHandler.py: _load, _store, load - Query.py: _register, register, parent property - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - MapAttr2Shape.py, auth/ldap/Auth.py, Query.py: - MapAttr2Shape.py: Add None check for id, add None check for graph - auth/ldap/Auth.py: Add Any import, fix __init__ and _create_entity - Query.py: Fix _add, run, parent signatures - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - Config.py: dump - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - ShellCmd.py: __init__ - auth/Auth.py: load, __init__ - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - auth/ldap/Auth.py: Entity.__init__, Auth.__init__, _create_entity - cast.py: guess_type - DataBase.py: _create_session, _delete_session - TableIoHandler.py: load - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ - ldap.py: Config.__get__, Config properties, Connection methods, inner callbacks - misc.py: get_derived_classes, load_classes, load_class_names, load_object, multi_regex_edit, dump_dict, dump - multi_key_dict.py: items - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 22:34:10 +02:00
def conf(self) -> Config:
return self.__conf
@abc.abstractmethod
def _access(
self, what: str, access_type: Access | None, who: Entity | Group | None
) -> bool:
...
def access(
self,
what: str,
access_type: Access | None = None,
who: Entity | Group | None = None
) -> bool:
return self._access(what, access_type, who)
@abc.abstractmethod
def _current_entity(self) -> Entity:
...
@property
def current_entity(self) -> Entity:
return self._current_entity()
@abc.abstractmethod
mypy: Fix disallow_incomplete_defs fallout Add parameter and return type annotations to untyped functions all over the package: - ldap.py: Add return types to Config properties (ldap_uri, bind_dn, bind_pw, base_dn), Connection.__init__, add, delete, walk, find, __oc_recurse_to_top, object_class_path, and inner callbacks - cast.py: Add Any import, add return type annotations to cast_str_to_bool, guess_type, from_str, from_env, cast_str, and parameter type annotations where missing - Table.py: - __init__ (schema: Schema) - __eq__ (rhs: Any) - _column_data_type (name: str) - _column_default (name: str) - column_default (name: str) - foreign_keys_to_parent_table (parent_table: Any) - misc.py: - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - multi_regex_edit (spec: Any) - dump_dict (*args: Any, **kwargs: Any) - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - dump (*args: Any, **kwargs: Any) - MapAttr2Shape.py, ShuntingYard.py, Queries.py: - Add parameter and return type annotations to fix disallow_incomplete_defs: - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - Queries.py: _run, _register, name property, __getitem__, keys, load, add, _add - Add parameter and return type annotations: - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - auth/Auth.py: load, conf, _entity, projects - auth/ldap/Auth.py: __init__, _create_entity - Fix parameter type annotations: - rows_check_not_null: keys: str | list[str], stat_key: str | None, caller: Any - rows_dumps: lead: str | list[str] | None, tablefmt: str | None - rows_dump: heading: str | None, lead: str | list[str] | None, tablefmt: str | None - Table.py: column_default, add_row_location, add_child_row_location - CompositeForeignKey.py: __table, parent_column, child_column - TableIoHandler.py: _load, _store, load - Query.py: _register, register, parent property - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - MapAttr2Shape.py, auth/ldap/Auth.py, Query.py: - MapAttr2Shape.py: Add None check for id, add None check for graph - auth/ldap/Auth.py: Add Any import, fix __init__ and _create_entity - Query.py: Fix _add, run, parent signatures - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - Config.py: dump - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - ShellCmd.py: __init__ - auth/Auth.py: load, __init__ - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - auth/ldap/Auth.py: Entity.__init__, Auth.__init__, _create_entity - cast.py: guess_type - DataBase.py: _create_session, _delete_session - TableIoHandler.py: load - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ - ldap.py: Config.__get__, Config properties, Connection methods, inner callbacks - misc.py: get_derived_classes, load_classes, load_class_names, load_object, multi_regex_edit, dump_dict, dump - multi_key_dict.py: items - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 22:34:10 +02:00
def _entity(self, name: str, kind: Kind) -> Entity:
...
def entity(self, name: str, kind: Kind) -> Entity:
return self._entity(name, kind)
@abc.abstractmethod
def _entities(self, kind: Kind) -> Mapping[str, Entity]:
...
def entities(self, kind: Kind) -> Mapping[str, Entity]:
return self._entities(kind)
def _entity_by_email(self, email: str, kind: Kind) -> Entity:
if self.__base_entity_by_email is None:
ret: dict[str, Entity] = dict()
entities = self._entities(kind)
for entity in entities.values():
ret[entity.email] = entity
self.__base_entity_by_email = ret
return self.__base_entity_by_email[email]
def entity_by_email(self, email: str, kind: Kind) -> Entity:
return self._entity_by_email(email, kind)
def user_by_email(self, email: str) -> Entity:
return self._entity_by_email(email, Kind.User)
# -- Convenience / legacy wrappers
mypy: Fix disallow_incomplete_defs fallout Add parameter and return type annotations to untyped functions all over the package: - ldap.py: Add return types to Config properties (ldap_uri, bind_dn, bind_pw, base_dn), Connection.__init__, add, delete, walk, find, __oc_recurse_to_top, object_class_path, and inner callbacks - cast.py: Add Any import, add return type annotations to cast_str_to_bool, guess_type, from_str, from_env, cast_str, and parameter type annotations where missing - Table.py: - __init__ (schema: Schema) - __eq__ (rhs: Any) - _column_data_type (name: str) - _column_default (name: str) - column_default (name: str) - foreign_keys_to_parent_table (parent_table: Any) - misc.py: - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - multi_regex_edit (spec: Any) - dump_dict (*args: Any, **kwargs: Any) - get_derived_classes (mod: Any, flt: Any) - load_classes (flt: Any) - load_class_names (remove_flt: bool) - load_object (*args: Any, **kwargs: Any) - dump (*args: Any, **kwargs: Any) - MapAttr2Shape.py, ShuntingYard.py, Queries.py: - Add parameter and return type annotations to fix disallow_incomplete_defs: - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - Queries.py: _run, _register, name property, __getitem__, keys, load, add, _add - Add parameter and return type annotations: - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - auth/Auth.py: load, conf, _entity, projects - auth/ldap/Auth.py: __init__, _create_entity - Fix parameter type annotations: - rows_check_not_null: keys: str | list[str], stat_key: str | None, caller: Any - rows_dumps: lead: str | list[str] | None, tablefmt: str | None - rows_dump: heading: str | None, lead: str | list[str] | None, tablefmt: str | None - Table.py: column_default, add_row_location, add_child_row_location - CompositeForeignKey.py: __table, parent_column, child_column - TableIoHandler.py: _load, _store, load - Query.py: _register, register, parent property - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - MapAttr2Shape.py, auth/ldap/Auth.py, Query.py: - MapAttr2Shape.py: Add None check for id, add None check for graph - auth/ldap/Auth.py: Add Any import, fix __init__ and _create_entity - Query.py: Fix _add, run, parent signatures - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument - Config.py: dump - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval - ShellCmd.py: __init__ - auth/Auth.py: load, __init__ - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - auth/ldap/Auth.py: Entity.__init__, Auth.__init__, _create_entity - cast.py: guess_type - DataBase.py: _create_session, _delete_session - TableIoHandler.py: load - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ - ldap.py: Config.__get__, Config properties, Connection methods, inner callbacks - misc.py: get_derived_classes, load_classes, load_class_names, load_object, multi_regex_edit, dump_dict, dump - multi_key_dict.py: items - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add - auth/dummy/Auth.py: Entity.__init__, Auth.__init__ - Query.py: _run, _register, register, _add, run, parent/db properties - QueryResult.py: pages, _cast - Column.py: __eq__, foreign_key - Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name - Table.py: __init__, __eq__, _column_data_type, _column_default, column_default, __relationship_by_foreign_table, add_row_location, add_child_row_location - utils.py: check_schema - EventRouter.py: iter_peers - Group.py: __init__ - SimpleEntity.py: __init__ - Ldap.py: Entity.__init__, Ldap.__init__, _create_entity - Event.py: __init__ - Fuse.py: __init__ - Object.py: __init__ - SimpleObject.py: __init__, create - EvRequest.py: __init__ - Msg.py: __init__ Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 22:34:10 +02:00
def projects(self, name: str, flags: ProjectFlags) -> Sequence[str]:
log(
WARNING,
'Using Auth.projects() is deprecated. Use Entity.projects() instead!'
)
entity = self.entity(name, Kind.User)
return entity.projects(flags)
@property
def users(self) -> Mapping[str, Entity]:
return self.entities(Kind.User)
def user(self, name: str) -> Entity:
return self.entity(name, Kind.User)