mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# event/__init__.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# event/api.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
@@ -51,15 +51,14 @@ def listen(
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.schema import UniqueConstraint
|
||||
|
||||
|
||||
def unique_constraint_name(const, table):
|
||||
const.name = "uq_%s_%s" % (
|
||||
table.name,
|
||||
list(const.columns)[0].name
|
||||
)
|
||||
const.name = "uq_%s_%s" % (table.name, list(const.columns)[0].name)
|
||||
|
||||
|
||||
event.listen(
|
||||
UniqueConstraint,
|
||||
"after_parent_attach",
|
||||
unique_constraint_name)
|
||||
UniqueConstraint, "after_parent_attach", unique_constraint_name
|
||||
)
|
||||
|
||||
:param bool insert: The default behavior for event handlers is to append
|
||||
the decorated user defined function to an internal list of registered
|
||||
@@ -132,19 +131,17 @@ def listens_for(
|
||||
The :func:`.listens_for` decorator is part of the primary interface for the
|
||||
SQLAlchemy event system, documented at :ref:`event_toplevel`.
|
||||
|
||||
This function generally shares the same kwargs as :func:`.listens`.
|
||||
This function generally shares the same kwargs as :func:`.listen`.
|
||||
|
||||
e.g.::
|
||||
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.schema import UniqueConstraint
|
||||
|
||||
|
||||
@event.listens_for(UniqueConstraint, "after_parent_attach")
|
||||
def unique_constraint_name(const, table):
|
||||
const.name = "uq_%s_%s" % (
|
||||
table.name,
|
||||
list(const.columns)[0].name
|
||||
)
|
||||
const.name = "uq_%s_%s" % (table.name, list(const.columns)[0].name)
|
||||
|
||||
A given function can also be invoked for only the first invocation
|
||||
of the event using the ``once`` argument::
|
||||
@@ -153,7 +150,6 @@ def listens_for(
|
||||
def on_config():
|
||||
do_config()
|
||||
|
||||
|
||||
.. warning:: The ``once`` argument does not imply automatic de-registration
|
||||
of the listener function after it has been invoked a first time; a
|
||||
listener entry will remain associated with the target object.
|
||||
@@ -189,6 +185,7 @@ def remove(target: Any, identifier: str, fn: Callable[..., Any]) -> None:
|
||||
def my_listener_function(*arg):
|
||||
pass
|
||||
|
||||
|
||||
# ... it's removed like this
|
||||
event.remove(SomeMappedClass, "before_insert", my_listener_function)
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# event/attr.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# event/base.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
@@ -191,13 +191,8 @@ class _Dispatch(_DispatchCommon[_ET]):
|
||||
:class:`._Dispatch` objects.
|
||||
|
||||
"""
|
||||
if "_joined_dispatch_cls" not in self.__class__.__dict__:
|
||||
cls = type(
|
||||
"Joined%s" % self.__class__.__name__,
|
||||
(_JoinedDispatcher,),
|
||||
{"__slots__": self._event_names},
|
||||
)
|
||||
self.__class__._joined_dispatch_cls = cls
|
||||
assert "_joined_dispatch_cls" in self.__class__.__dict__
|
||||
|
||||
return self._joined_dispatch_cls(self, other)
|
||||
|
||||
def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
|
||||
@@ -328,6 +323,51 @@ class _HasEventsDispatch(Generic[_ET]):
|
||||
else:
|
||||
dispatch_target_cls.dispatch = dispatcher(cls)
|
||||
|
||||
klass = type(
|
||||
"Joined%s" % dispatch_cls.__name__,
|
||||
(_JoinedDispatcher,),
|
||||
{"__slots__": event_names},
|
||||
)
|
||||
dispatch_cls._joined_dispatch_cls = klass
|
||||
|
||||
# establish pickle capability by adding it to this module
|
||||
globals()[klass.__name__] = klass
|
||||
|
||||
|
||||
class _JoinedDispatcher(_DispatchCommon[_ET]):
|
||||
"""Represent a connection between two _Dispatch objects."""
|
||||
|
||||
__slots__ = "local", "parent", "_instance_cls"
|
||||
|
||||
local: _DispatchCommon[_ET]
|
||||
parent: _DispatchCommon[_ET]
|
||||
_instance_cls: Optional[Type[_ET]]
|
||||
|
||||
def __init__(
|
||||
self, local: _DispatchCommon[_ET], parent: _DispatchCommon[_ET]
|
||||
):
|
||||
self.local = local
|
||||
self.parent = parent
|
||||
self._instance_cls = self.local._instance_cls
|
||||
|
||||
def __reduce__(self) -> Any:
|
||||
return (self.__class__, (self.local, self.parent))
|
||||
|
||||
def __getattr__(self, name: str) -> _JoinedListener[_ET]:
|
||||
# Assign _JoinedListeners as attributes on demand
|
||||
# to reduce startup time for new dispatch objects.
|
||||
ls = getattr(self.local, name)
|
||||
jl = _JoinedListener(self.parent, ls.name, ls)
|
||||
setattr(self, ls.name, jl)
|
||||
return jl
|
||||
|
||||
def _listen(self, event_key: _EventKey[_ET], **kw: Any) -> None:
|
||||
return self.parent._listen(event_key, **kw)
|
||||
|
||||
@property
|
||||
def _events(self) -> Type[_HasEventsDispatch[_ET]]:
|
||||
return self.parent._events
|
||||
|
||||
|
||||
class Events(_HasEventsDispatch[_ET]):
|
||||
"""Define event listening functions for a particular target type."""
|
||||
@@ -340,9 +380,11 @@ class Events(_HasEventsDispatch[_ET]):
|
||||
return all(isinstance(target.dispatch, t) for t in types)
|
||||
|
||||
def dispatch_parent_is(t: Type[Any]) -> bool:
|
||||
return isinstance(
|
||||
cast("_JoinedDispatcher[_ET]", target.dispatch).parent, t
|
||||
)
|
||||
parent = cast("_JoinedDispatcher[_ET]", target.dispatch).parent
|
||||
while isinstance(parent, _JoinedDispatcher):
|
||||
parent = cast("_JoinedDispatcher[_ET]", parent).parent
|
||||
|
||||
return isinstance(parent, t)
|
||||
|
||||
# Mapper, ClassManager, Session override this to
|
||||
# also accept classes, scoped_sessions, sessionmakers, etc.
|
||||
@@ -382,38 +424,6 @@ class Events(_HasEventsDispatch[_ET]):
|
||||
cls.dispatch._clear()
|
||||
|
||||
|
||||
class _JoinedDispatcher(_DispatchCommon[_ET]):
|
||||
"""Represent a connection between two _Dispatch objects."""
|
||||
|
||||
__slots__ = "local", "parent", "_instance_cls"
|
||||
|
||||
local: _DispatchCommon[_ET]
|
||||
parent: _DispatchCommon[_ET]
|
||||
_instance_cls: Optional[Type[_ET]]
|
||||
|
||||
def __init__(
|
||||
self, local: _DispatchCommon[_ET], parent: _DispatchCommon[_ET]
|
||||
):
|
||||
self.local = local
|
||||
self.parent = parent
|
||||
self._instance_cls = self.local._instance_cls
|
||||
|
||||
def __getattr__(self, name: str) -> _JoinedListener[_ET]:
|
||||
# Assign _JoinedListeners as attributes on demand
|
||||
# to reduce startup time for new dispatch objects.
|
||||
ls = getattr(self.local, name)
|
||||
jl = _JoinedListener(self.parent, ls.name, ls)
|
||||
setattr(self, ls.name, jl)
|
||||
return jl
|
||||
|
||||
def _listen(self, event_key: _EventKey[_ET], **kw: Any) -> None:
|
||||
return self.parent._listen(event_key, **kw)
|
||||
|
||||
@property
|
||||
def _events(self) -> Type[_HasEventsDispatch[_ET]]:
|
||||
return self.parent._events
|
||||
|
||||
|
||||
class dispatcher(Generic[_ET]):
|
||||
"""Descriptor used by target classes to
|
||||
deliver the _Dispatch class at the class level
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# event/legacy.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# event/registry.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
@@ -154,7 +154,11 @@ def _removed_from_collection(
|
||||
|
||||
if owner_ref in _collection_to_key:
|
||||
listener_to_key = _collection_to_key[owner_ref]
|
||||
listener_to_key.pop(listen_ref)
|
||||
# see #12216 - this guards against a removal that already occurred
|
||||
# here. however, I cannot come up with a test that shows any negative
|
||||
# side effects occurring from this removal happening, even though an
|
||||
# event key may still be referenced from a clsleveldispatch here
|
||||
listener_to_key.pop(listen_ref, None)
|
||||
|
||||
|
||||
def _stored_in_collection_multi(
|
||||
|
Reference in New Issue
Block a user