관리-도구
편집 파일: api.cpython-37.pyc
B ��4]� � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z e � d �Ze � d �Zdd� Z d d� Zdd� Zdd� Zdd� ZdS )z,Public API functions for the event system. � )�absolute_import� )�_registrars)� _EventKey� )�exc)�util�CANCEL� NO_RETVALc C sH xBt | D ]$}|�| �}|d k r t| |||�S q W t�d|| f ��d S )Nz"No such event '%s' for target '%s')r Z_accept_withr r ZInvalidRequestError)�target� identifier�fnZevt_clsZtgt� r �G/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/event/api.py� _event_key s r c O s t | ||�j||� dS )a� Register a listener function for the given target. The :func:`.listen` function is part of the primary interface for the SQLAlchemy event system, documented at :ref:`event_toplevel`. e.g.:: 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 ) event.listen( UniqueConstraint, "after_parent_attach", unique_constraint_name) A given function can also be invoked for only the first invocation of the event using the ``once`` argument:: def on_config(): do_config() event.listen(Mapper, "before_configure", on_config, once=True) .. versionadded:: 0.9.4 Added ``once=True`` to :func:`.event.listen` and :func:`.event.listens_for`. .. note:: The :func:`.listen` function cannot be called at the same time that the target event is being run. This has implications for thread safety, and also means an event cannot be added from inside the listener function for itself. The list of events to be run are present inside of a mutable collection that can't be changed during iteration. Event registration and removal is not intended to be a "high velocity" operation; it is a configurational operation. For systems that need to quickly associate and deassociate with events at high scale, use a mutable structure that is handled from inside of a single listener. .. versionchanged:: 1.0.0 - a ``collections.deque()`` object is now used as the container for the list of events, which explicitly disallows collection mutation while the collection is being iterated. .. seealso:: :func:`.listens_for` :func:`.remove` N)r �listen)r r r �args�kwr r r r "