HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/zmq/__pycache__/decorators.cpython-310.pyc
o

;j��@sjdZddlmZdZddlmZddlZGdd�d�ZGdd	�d	e�ZGd
d�de�Z	dd
�Z
dd�ZdS)aeDecorators for running functions with context/sockets.

.. versionadded:: 15.3

Like using Contexts and Sockets as context managers, but with decorator syntax.
Context and sockets are closed at the end of the function.

For example::

    from zmq.decorators import context, socket

    @context()
    @socket(zmq.PUSH)
    def work(ctx, push):
        ...
�)�annotations)�context�socket��wrapsNc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)�
_DecoratorzThe mini decorator factoryNcCs
||_dS�N��_target)�self�target�r
�B/opt/saltstack/salt/lib/python3.10/site-packages/zmq/decorators.py�__init__$s
z_Decorator.__init__cs,�j�i���\�������fdd�}|S)a�
        The main logic of decorator

        Here is how those arguments works::

            @out_decorator(*dec_args, *dec_kwargs)
            def func(*wrap_args, **wrap_kwargs):
                ...

        And in the ``wrapper``, we simply create ``self.target`` instance via
        ``with``::

            target = self.get_target(*args, **kwargs)
            with target(*dec_args, **dec_kwargs) as obj:
                ...

        cs t�������fdd��}|S)Ncs��j|i|��}|�i����0}�r�|vr||�<n�r,�|vr,t�j�d��d���||f}�|i|��Wd�S1sBwYdS)Nz%() got multiple values for argument '�')�
get_target�	TypeError�__name__)�args�kwargsr�obj)�dec_args�
dec_kwargs�func�kw_namerr
r�wrapper>s
��
$�z7_Decorator.__call__.<locals>.decorator.<locals>.wrapperr)rr�rrrr)rr�	decorator=sz&_Decorator.__call__.<locals>.decorator)�process_decorator_args)rrrrr
rr�__call__'s��z_Decorator.__call__cOs|jS)zWReturn the target function

        Allows modifying args/kwargs to be passed.
        r	)rrrr
r
rrTsz_Decorator.get_targetcOsXd}t|�d�t�r|�d�}nt|�dkr't|dt�r'|d}|dd�}|||fS)z�Process args passed to the decorator.

        args not consumed by the decorator will be passed to the target factory
        (Context/Socket constructor).
        N�name�r)�
isinstance�get�str�pop�len�rrrrr
r
rr[s
z!_Decorator.process_decorator_argsr)r�
__module__�__qualname__�__doc__rrrrr
r
r
rr!s
-rcs eZdZdZ�fdd�Z�ZS)�_ContextDecoratorzDecorator subclass for Contextscst��tj�dSr)�superr�zmq�Context)r��	__class__r
rrosz_ContextDecorator.__init__)rr(r)r*r�
__classcell__r
r
r/rr+lsr+cs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�_SocketDecoratorzJDecorator subclass for sockets

    Gets the context from other args.
    cs0t�j|i|��\}}}|�dd�|_|||fS)z$Also grab context_name out of kwargs�context_namer)r,rr%r3r'r/r
rrys
z'_SocketDecorator.process_decorator_argscOs|j|i|��}|jS)z$Get context, based on call-time args)�_get_contextr)rrrrr
r
rrsz_SocketDecorator.get_targetcOsL|j|vr||j}t|tj�r|S|D]}t|tj�r |Sqtj��S)a�
        Find the ``zmq.Context`` from ``args`` and ``kwargs`` at call time.

        First, if there is an keyword argument named ``context`` and it is a
        ``zmq.Context`` instance , we will take it.

        Second, we check all the ``args``, take the first ``zmq.Context``
        instance.

        Finally, we will provide default Context -- ``zmq.Context.instance``

        :return: a ``zmq.Context`` instance
        )r3r"r-r.�instance)rrr�ctx�argr
r
rr4�s

�
z_SocketDecorator._get_context)rr(r)r*rrr4r1r
r
r/rr2ss
r2cO�t�|i|��S)z�Decorator for adding a Context to a function.

    Usage::

        @context()
        def foo(ctx):
            ...

    .. versionadded:: 15.3

    :param str name: the keyword argument passed to decorated function
    )r+�rrr
r
rr�s
rcOr8)aSDecorator for adding a socket to a function.

    Usage::

        @socket(zmq.PUSH)
        def foo(push):
            ...

    .. versionadded:: 15.3

    :param str name: the keyword argument passed to decorated function
    :param str context_name: the keyword only argument to identify context
                             object
    )r2r9r
r
rr�sr)r*�
__future__r�__all__�	functoolsrr-rr+r2rrr
r
r
r�<module>sK,