HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/zmq/__pycache__/decorators.cpython-310.pyc
o

�N�g��@s^dZdZddlmZddlZGdd�d�ZGdd�de�ZGd	d
�d
e�Zdd�Zd
d�Z	dS)aiDecorators 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):
        ...
)�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����.}�r�|vr||�<n�r*�|vr*td��j����||f}�|i|��Wd�S1s@wYdS)Nz*{}() got multiple values for argument '{}')�
get_target�	TypeError�format�__name__)�args�kwargsr�obj)�dec_args�
dec_kwargs�func�kw_namer
rr
�wrapper<s

�
$�z7_Decorator.__call__.<locals>.decorator.<locals>.wrapperr)rr�rrrr
)rr
�	decorator;sz&_Decorator.__call__.<locals>.decorator)�process_decorator_args)r
rrrrrr
�__call__%s��z_Decorator.__call__cOs|jS)zWReturn the target function

        Allows modifying args/kwargs to be passed.
        r)r
rrrrr
rRsz_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�r
rrrrrr
rYs
z!_Decorator.process_decorator_argsr)r�
__module__�__qualname__�__doc__rrrrrrrr
rs
-rcs eZdZdZ�fdd�Z�ZS)�_ContextDecoratorzDecorator subclass for Contextscst��tj�dSr)�superr�zmq�Context)r
��	__class__rr
rmsz_ContextDecorator.__init__)rr'r(r)r�
__classcell__rrr.r
r*jsr*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$r2r&r.rr
rws
z'_SocketDecorator.process_decorator_argscOs|j|i|��}|jS)z$Get context, based on call-time args)�_get_contextr)r
rrrrrr
r}sz_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
        )r2r!r,r-�instance)r
rr�ctx�argrrr
r3�s

�
z_SocketDecorator._get_context)rr'r(r)rrr3r0rrr.r
r1qs
r1cO�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r
r�s
rcOr7)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
    )r1r8rrr
r�sr)
r)�__all__�	functoolsrr,rr*r1rrrrrr
�<module>sK,