%PDF- %PDF-
Direktori : /snap/core18/current/usr/lib/python3/dist-packages/blinker/__pycache__/ |
Current File : //snap/core18/current/usr/lib/python3/dist-packages/blinker/__pycache__/base.cpython-36.pyc |
3 RѰU�? � @ s� d Z ddlmZ ddlmZ ddlmZmZmZm Z m Z mZmZ ed�Z de _ dZG dd� de�Zed �ZG d d� de�ZG dd � d e�ZG dd� de�Ze� jZdS )a+ Signals and events. A small implementation of signals, inspired by a snippet of Django signal API client code seen in a blog post. Signals are first-class objects and each manages its own receivers and message emission. The :func:`signal` function provides singleton behavior for named signals. � )�warn)�WeakValueDictionary)� WeakTypes�contextmanager�defaultdict�hashable_identity� lazy_property� reference�symbol�ANYzToken for "any sender".c @ s� e Zd ZdZeZedd� �Zedd� �Zd%dd�Zed fd d�Z d&d d�Z eefdd��Zefdd�Z dd� Zdd� Zdd� Zefdd�Zdd� Zdd� Zdd � Zd!d"� Zd#d$� ZdS )'�SignalzA notification emitter.c C s t dd�S )z�Emitted after each :meth:`connect`. The signal sender is the signal instance, and the :meth:`connect` arguments are passed through: *receiver*, *sender*, and *weak*. .. versionadded:: 1.2 z"Emitted after a receiver connects.)�doc)r )�self� r �./usr/lib/python3/dist-packages/blinker/base.py�receiver_connected% s zSignal.receiver_connectedc C s t dd�S )a Emitted after :meth:`disconnect`. The sender is the signal instance, and the :meth:`disconnect` arguments are passed through: *receiver* and *sender*. Note, this signal is emitted **only** when :meth:`disconnect` is called explicitly. The disconnect signal can not be emitted by an automatic disconnect (due to a weakly referenced receiver or sender going out of scope), as the receiver and/or sender instances are no longer available for use at the time this signal would be emitted. An alternative approach is available by subscribing to :attr:`receiver_connected` and setting up a custom weakref cleanup callback on weak receivers and senders. .. versionadded:: 1.2 z%Emitted after a receiver disconnects.)r )r )r r r r �receiver_disconnected1 s zSignal.receiver_disconnectedNc C s. |r || _ i | _tt�| _tt�| _i | _dS )zt :param doc: optional. If provided, will be assigned to the signal's __doc__ attribute. N)�__doc__� receiversr �set�_by_receiver� _by_sender� _weak_senders)r r r r r �__init__I s zSignal.__init__Tc C sF t |�}|r t|| j�}||_n|}|tkr2t}nt |�}| jj||� | j| j |� | j | j |� ~|tk r�|| jkr�yt|| j�}||_ W n tk r� Y nX | jj||� ~d| jkr�| jjr�y| jj| |||d� W n | j||� � Y nX tj�rB| tk �rBytj| |||d� W n | j||� � Y nX |S )aa Connect *receiver* to signal events sent by *sender*. :param receiver: A callable. Will be invoked by :meth:`send` with `sender=` as a single positional argument and any \*\*kwargs that were provided to a call to :meth:`send`. :param sender: Any object or :obj:`ANY`, defaults to ``ANY``. Restricts notifications delivered to *receiver* to only those :meth:`send` emissions sent by *sender*. If ``ANY``, the receiver will always be notified. A *receiver* may be connected to multiple *sender* values on the same Signal through multiple calls to :meth:`connect`. :param weak: If true, the Signal will hold a weakref to *receiver* and automatically disconnect when *receiver* goes out of scope or is garbage collected. Defaults to True. r )�receiver�sender�weak)Zreceiver_argZ sender_argZweak_arg)r r �_cleanup_receiver�receiver_idr �ANY_IDr � setdefaultr �addr r �_cleanup_sender� sender_id� TypeError�__dict__r �send� disconnect)r r r r r �receiver_refr# � sender_refr r r �connect\ sP zSignal.connectFc s � ��fdd�}|S )aK Connect the decorated function as a receiver for *sender*. :param sender: Any object or :obj:`ANY`. The decorated function will only receive :meth:`send` emissions sent by *sender*. If ``ANY``, the receiver will always be notified. A function may be decorated multiple times with differing *sender* values. :param weak: If true, the Signal will hold a weakref to the decorated function and automatically disconnect when *receiver* goes out of scope or is garbage collected. Unlike :meth:`connect`, this defaults to False. The decorated function will be invoked by :meth:`send` with `sender=` as a single positional argument and any \*\*kwargs that were provided to the call to :meth:`send`. .. versionadded:: 1.1 c s � j | ��� | S )N)r* )�fn)r r r r r � decorator� s z%Signal.connect_via.<locals>.decoratorr )r r r r, r )r r r r �connect_via� s zSignal.connect_viac c sB | j ||dd� y dV W n | j|� � Y nX | j|� dS )a Execute a block with the signal temporarily connected to *receiver*. :param receiver: a receiver callable :param sender: optional, a sender to filter on This is a context manager for use in the ``with`` statement. It can be useful in unit tests. *receiver* is connected to the signal for the duration of the ``with`` block, and will be disconnected automatically when exiting the block: .. testsetup:: from __future__ import with_statement from blinker import Signal on_ready = Signal() receiver = lambda sender: None .. testcode:: with on_ready.connected_to(receiver): # do stuff on_ready.send(123) .. versionadded:: 1.1 F)r r N)r* r'