§
    ‹Ÿjë  ã                  óŒ   — d Z ddlmZ dZddlmZ ddlZ G d„ d¦  «        Z G d„ d	e¦  «        Z G d
„ de¦  «        Z	d„ Z
d„ ZdS )ae  Decorators 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                  ó,   — e Zd ZdZdd„Zd„ Zd„ Zd„ ZdS )Ú
_DecoratorzThe mini decorator factoryNc                ó   — || _         d S ©N©Ú_target)ÚselfÚtargets     ú[/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/zmq/decorators.pyÚ__init__z_Decorator.__init__$   s   € ØˆŒˆˆó    c                ó@   ‡ ‡‡‡—  ‰ j         ‰i ‰¤Ž\  ŠŠŠˆˆˆˆ fd„}|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:
                ...

        c                óF   •‡ — t          ‰ ¦  «        ˆˆˆ ˆˆfd„¦   «         }|S )Nc                 óÖ   •—  ‰j         | i |¤Ž} |‰i ‰¤Ž5 }‰r
‰|vr||‰<   n&‰r‰|v rt          ‰j        › d‰› d�¦  «        ‚| |fz   }  ‰| i |¤Žcd d d ¦  «         S # 1 swxY w Y   d S )Nz%() got multiple values for argument 'ú')Ú
get_targetÚ	TypeErrorÚ__name__)	ÚargsÚkwargsr   ÚobjÚdec_argsÚ
dec_kwargsÚfuncÚkw_namer   s	       €€€€€r   Úwrapperz7_Decorator.__call__.<locals>.decorator.<locals>.wrapper>   s  ø€ à(˜œ¨$Ð9°&Ð9Ð9�à�V˜XÐ4¨Ð4Ð4ð 1¸àð - 7°&Ð#8Ð#8Ø*-˜˜w™˜Ø ð - W°Ð%6Ð%6Ý'Ø#œ}ð 5ð 5Ø*1ð5ð 5ð 5ñô ð ð
  $ s f™}˜à˜4 Ð0¨Ð0Ð0ð1ð 1ð 1ð 1ñ 1ô 1ð 1ð 1ð 1ð 1ð 1ð 1øøøð 1ð 1ð 1ð 1ð 1ð 1s   —:AÁA"Á%A"r   )r   r!   r   r   r    r   s   ` €€€€r   Ú	decoratorz&_Decorator.__call__.<locals>.decorator=   sH   øø€ Ý�4‰[Œ[ð1ð 1ð 1ð 1ð 1ð 1ð 1ð 1ñ Œ[ð1ð" ˆNr   )Úprocess_decorator_args)r   r   r   r"   r    s   ``` @r   Ú__call__z_Decorator.__call__'   s_   øøøø€ ð$ )D¨Ô(CØð)
Ø#ð)
ð )
Ñ%ˆ�˜:ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð* Ðr   c                ó   — | j         S )zWReturn the target function

        Allows modifying args/kwargs to be passed.
        r   )r   r   r   s      r   r   z_Decorator.get_targetT   s   € ð
 Œ|Ðr   c                ó  — d}t          |                     d¦  «        t          ¦  «        r|                     d¦  «        }n@t	          |¦  «        dk    r-t          |d         t          ¦  «        r|d         }|dd…         }|||fS )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   r   r   r    s       r   r#   z!_Decorator.process_decorator_args[   s~   € ð ˆå�f—j’j Ñ(Ô(­#Ñ.Ô.ð 	Ø—j’j Ñ(Ô(ˆGˆGÝ�‰YŒY˜!Š^ˆ^¥
¨4°¬7µCÑ 8Ô 8ˆ^Ø˜1”gˆGØ˜˜˜”8ˆDà˜˜fÐ$Ð$r   r   )r   Ú
__module__Ú__qualname__Ú__doc__r   r$   r   r#   © r   r   r	   r	   !   s\   € € € € € Ø$Ð$ðð ð ð ð+ð +ð +ðZð ð ð%ð %ð %ð %ð %r   r	   c                  ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )Ú_ContextDecoratorzDecorator subclass for Contextsc                ó^   •— t          ¦   «                              t          j        ¦  «         d S r   )Úsuperr   ÚzmqÚContext)r   Ú	__class__s    €r   r   z_ContextDecorator.__init__o   s#   ø€ Ý‰Œ×Ò�œÑ%Ô%Ð%Ð%Ð%r   )r   r.   r/   r0   r   Ú__classcell__©r8   s   @r   r3   r3   l   s>   ø€ € € € € Ø)Ð)ð&ð &ð &ð &ð &ð &ð &ð &ð &r   r3   c                  ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )Ú_SocketDecoratorzJDecorator subclass for sockets

    Gets the context from other args.
    c                ó~   •—  t          ¦   «         j        |i |¤Ž\  }}}|                     dd¦  «        | _        |||fS )z$Also grab context_name out of kwargsÚcontext_namer   )r5   r#   r,   r>   )r   r   r   r    r8   s       €r   r#   z'_SocketDecorator.process_decorator_argsy   sH   ø€ à >¥¡¤Ô >ÀÐ OÈÐ OÐ OÑˆ��vØ"ŸJšJ ~°yÑAÔAˆÔØ˜˜fÐ$Ð$r   c                ó*   —  | j         |i |¤Ž}|j        S )z$Get context, based on call-time args)Ú_get_contextr   )r   r   r   r   s       r   r   z_SocketDecorator.get_target   s!   € à#�$Ô# TÐ4¨VÐ4Ð4ˆØŒ~Ðr   c                óè   — | j         |v r)|| j                  }t          |t          j        ¦  «        r|S |D ] }t          |t          j        ¦  «        r|c S Œ!t          j                             ¦   «         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
        )r>   r)   r6   r7   Úinstance)r   r   r   ÚctxÚargs        r   r@   z_SocketDecorator._get_context„   s   € ð Ô Ð&Ð&Ø˜Ô*Ô+ˆCå˜#�sœ{Ñ+Ô+ð Ø�
àð 	ð 	ˆCÝ˜#�sœ{Ñ+Ô+ð Ø�
�
�
ðõ Œ{×#Ò#Ñ%Ô%Ð%r   )r   r.   r/   r0   r#   r   r@   r9   r:   s   @r   r<   r<   s   s`   ø€ € € € € ðð ð
%ð %ð %ð %ð %ðð ð ð
&ð &ð &ð &ð &ð &ð &r   r<   c                 ó*   —  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
    )r3   ©r   r   s     r   r   r   Ÿ   s    € ð ÕÑÔ Ð/¨Ð/Ð/Ð/r   c                 ó*   —  t          ¦   «         | i |¤ŽS )aS  Decorator 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
    )r<   rF   s     r   r   r   ¯   s    € ð ÕÑÔ˜tÐ. vÐ.Ð.Ð.r   )r0   Ú
__future__r   Ú__all__Ú	functoolsr   r6   r	   r3   r<   r   r   r1   r   r   ú<module>rK      sõ   ððð ð" #Ð "Ð "Ð "Ð "Ð "ð
€ð
 Ð Ð Ð Ð Ð à 
€
€
€
ðH%ð H%ð H%ð H%ð H%ñ H%ô H%ð H%ðV&ð &ð &ð &ð &˜
ñ &ô &ð &ð)&ð )&ð )&ð )&ð )&�zñ )&ô )&ð )&ðX0ð 0ð 0ð /ð /ð /ð /ð /r   