Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
api.cpython-313.pyc179 linesDownload Raw Back to __pycache__
1�

2��j� ��*�SrSSKJr SSKJr SSKJr SSKJr SSKJ	r	 SSKJ3r4 SS	KJr S5SKJ
r
 S6SKJr \R"S
5r\R"S5rSSjrSSjrSSjrSSjrSSjrg)z*Public API functions for the event system.�)�annotations)�Any)�Callable�)�_registrars)�_ET)�	_EventKey)�_ListenerFnType�)�exc)�util�CANCEL�	NO_RETVALc��[UH%nURX5nUcM[XX$5s $ [R"SU<SU<S35e)NzNo such event 'z' for target '�')r�_accept_withr	r�InvalidRequestError)�target�7identifier�fn�evt_cls�tgts     �ZD:\code\apps\devtools\python\user_packages\Python313\site-packages\sqlalchemy/event/api.py�8_event_keyrsR���z�*���"�"�6�6���?��V��9�9�+�9�%�%�4>��G�10�	11�c�<�[XU5R"U0UD6 g)ahRegister a listener function for the given target.12 13The :func:`.listen` function is part of the primary interface for the14SQLAlchemy event system, documented at :ref:`event_toplevel`.15 16e.g.::17 18    from sqlalchemy import event19    from sqlalchemy.schema import UniqueConstraint20 21 22    def unique_constraint_name(const, table):23        const.name = "uq_%s_%s" % (table.name, list(const.columns)[0].name)24 25 26    event.listen(27        UniqueConstraint, "after_parent_attach", unique_constraint_name28    )29 30:param bool insert: The default behavior for event handlers is to append31  the decorated user defined function to an internal list of registered32  event listeners upon discovery. If a user registers a function with33  ``insert=True``, SQLAlchemy will insert (prepend) the function to the34  internal list upon discovery. This feature is not typically used or35  recommended by the SQLAlchemy maintainers, but is provided to ensure36  certain user defined functions can run before others, such as when37  :ref:`Changing the sql_mode in MySQL <mysql_sql_mode>`.38 39:param bool named: When using named argument passing, the names listed in40  the function argument specification will be used as keys in the41  dictionary.42  See :ref:`event_named_argument_styles`.43 44:param bool once: Private/Internal API usage. Deprecated.  This parameter45  would provide that an event function would run only once per given46  target. It does not however imply automatic de-registration of the47  listener function; associating an arbitrarily high number of listeners48  without explicitly removing them will cause memory to grow unbounded even49  if ``once=True`` is specified.50 51:param bool propagate: The ``propagate`` kwarg is available when working52  with ORM instrumentation and mapping events.53  See :class:`_ormevent.MapperEvents` and54  :meth:`_ormevent.MapperEvents.before_mapper_configured` for examples.55 56:param bool retval: This flag applies only to specific event listeners,57  each of which includes documentation explaining when it should be used.58  By default, no listener ever requires a return value.59  However, some listeners do support special behaviors for return values,60  and include in their documentation that the ``retval=True`` flag is61  necessary for a return value to be processed.62 63  Event listener suites that make use of :paramref:`_event.listen.retval`64  include :class:`_events.ConnectionEvents` and65  :class:`_ormevent.AttributeEvents`.66 67.. note::68 69    The :func:`.listen` function cannot be called at the same time70    that the target event is being run.   This has implications71    for thread safety, and also means an event cannot be added72    from inside the listener function for itself.  The list of73    events to be run are present inside of a mutable collection74    that can't be changed during iteration.75 76    Event registration and removal is not intended to be a "high77    velocity" operation; it is a configurational operation.  For78    systems that need to quickly associate and deassociate with79    events at high scale, use a mutable structure that is handled80    from inside of a single listener.81 82.. seealso::83 84    :func:`.listens_for`85 86    :func:`.remove`87 88N)r�listen)rrr�args�kws     rrr's��d�v�2�&�-�-�t�:�r�:rc�$^^^^�SUUUU4SjjnU$)a�Decorate a function as a listener for the given target + identifier.89 90The :func:`.listens_for` decorator is part of the primary interface for the91SQLAlchemy event system, documented at :ref:`event_toplevel`.92 93This function generally shares the same kwargs as :func:`.listen`.94 95e.g.::96 97    from sqlalchemy import event98    from sqlalchemy.schema import UniqueConstraint99 100 101    @event.listens_for(UniqueConstraint, "after_parent_attach")102    def unique_constraint_name(const, table):103        const.name = "uq_%s_%s" % (table.name, list(const.columns)[0].name)104 105A given function can also be invoked for only the first invocation106of the event using the ``once`` argument::107 108    @event.listens_for(Mapper, "before_configure", once=True)109    def on_config():110        do_config()111 112.. warning:: The ``once`` argument does not imply automatic de-registration113   of the listener function after it has been invoked a first time; a114   listener entry will remain associated with the target object.115   Associating an arbitrarily high number of listeners without explicitly116   removing them will cause memory to grow unbounded even if ``once=True``117   is specified.118 119.. seealso::120 121    :func:`.listen` - general description of event listening122 123c�*>�[TTU/TQ70TD6 U$)N)r)rrrrrs ����r�decorate�listens_for.<locals>.decorate�s����v�z�2�3��3��3��	r)r�Callable[..., Any]�returnr$�)rrrrr"s```` r�listens_forr'|s���P���Orc�8�[XU5R5 g)a�Remove an event listener.124 125The arguments here should match exactly those which were sent to126:func:`.listen`; all the event registration which proceeded as a result127of this call will be reverted by calling :func:`.remove` with the same128arguments.129 130e.g.::131 132    # if a function was registered like this...133    @event.listens_for(SomeMappedClass, "before_insert", propagate=True)134    def my_listener_function(*arg):135        pass136 137 138    # ... it's removed like this139    event.remove(SomeMappedClass, "before_insert", my_listener_function)140 141Above, the listener function associated with ``SomeMappedClass`` was also142propagated to subclasses of ``SomeMappedClass``; the :func:`.remove`143function will revert all of these operations.144 145.. note::146 147    The :func:`.remove` function cannot be called at the same time148    that the target event is being run.   This has implications149    for thread safety, and also means an event cannot be removed150    from inside the listener function for itself.  The list of151    events to be run are present inside of a mutable collection152    that can't be changed during iteration.153 154    Event registration and removal is not intended to be a "high155    velocity" operation; it is a configurational operation.  For156    systems that need to quickly associate and deassociate with157    events at high scale, use a mutable structure that is handled158    from inside of a single listener.159 160.. seealso::161 162    :func:`.listen`163 164N)r�remove�rrrs   rr)r)�s��V�v�2�&�-�-�/rc�6�[XU5R5$)z=Return True if the given target/ident/fn is set up to listen.)r�containsr*s   rr,r,�s���f�"�-�6�6�8�8rN)rrr�strrr165r%z_EventKey[_ET])rrrr-rr$rrrrr%�None)166rrrr-rrrrr%z2Callable[[Callable[..., Any]], Callable[..., Any]])rrrr-rr$r%r.)rrrr-rr$r%�bool)�__doc__�167__future__r�typingrr�baser�registryrr	r168�rr
�symbolrrrrr'r)r,r&rr�<module>r7s���1�"������%���169���X�	���K�K��$�	�170171��172173� �174175�&5�176177��178179�R;��R;� �R;�&8�R;�AD�R;�LO�R;�	�R;�j,��,� �,�),�,�47�,�7�,�^+0�\9r
codekingpro/portable-devtools · Team Ai