§
    ‹ŸjF%  ã                   óì   — d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ ddlZddlmZmZmZmZmZmZmZmZ  G d„ d¦  «        Z G d	„ d
e¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Zg d¢ZdS )z2Classes for running 0MQ Devices in the background.é    N)ÚProcess)ÚThread)ÚAnyÚCallableÚListÚOptionalÚTuple)ÚENOTSOCKÚETERMÚPUSHÚQUEUEÚContextÚZMQBindErrorÚZMQErrorÚproxyc            	       ó~  — e Zd ZU dZej        Zeg ej        f         e	d<   	 e
e	d<   ee	d<   ee	d<   ee	d<   ee         e	d<   ee         e	d<   eeeef                  e	d	<   ee         e	d
<   ee         e	d<   eeeef                  e	d<   ee         e	d<   eej                 e	d<   eddfdedee         dee         ddfd„Zdeddfd„Zdedefd„Zdeddfd„Zdededdfd„Zdeddfd„Zdedefd„Zdefd„Zdedefd„Zdedefd„Zdeej        ej        f         fd„Zd%d„Zd „ Zd%d!„Z d%d"„Z!d&d#ee"         ddfd$„Z#dS )'ÚDeviceaa  A 0MQ Device to be run in the background.

    You do not pass Socket instances to this, but rather Socket types::

        Device(device_type, in_socket_type, out_socket_type)

    For instance::

        dev = Device(zmq.QUEUE, zmq.DEALER, zmq.ROUTER)

    Similar to zmq.device, but socket types instead of sockets themselves are
    passed, and the sockets are created in the work thread, to avoid issues
    with thread safety. As a result, additional bind_{in|out} and
    connect_{in|out} methods and setsockopt_{in|out} allow users to specify
    connections for the sockets.

    Parameters
    ----------
    device_type : int
        The 0MQ Device type
    {in|out}_type : int
        zmq socket types, to be passed later to context.socket(). e.g.
        zmq.PUB, zmq.SUB, zmq.REQ. If out_type is < 0, then in_socket is used
        for both in_socket and out_socket.

    Methods
    -------
    bind_{in_out}(iface)
        passthrough for ``{in|out}_socket.bind(iface)``, to be called in the thread
    connect_{in_out}(iface)
        passthrough for ``{in|out}_socket.connect(iface)``, to be called in the
        thread
    setsockopt_{in_out}(opt,value)
        passthrough for ``{in|out}_socket.setsockopt(opt, value)``, to be called in
        the thread

    Attributes
    ----------
    daemon : bool
        sets whether the thread should be run as a daemon
        Default is true, because if it is false, the thread will not
        exit unless it is killed
    context_factory : callable
        This is a class attribute.
        Function for creating the Context. This will be Context.instance
        in ThreadDevices, and Context in ProcessDevices.  The only reason
        it is not instance() in ProcessDevices is that there may be a stale
        Context instance already initialized, and the forked environment
        should *never* try to use it.
    Úcontext_factoryÚdaemonÚdevice_typeÚin_typeÚout_typeÚ	_in_bindsÚ_in_connectsÚ_in_sockoptsÚ
_out_bindsÚ_out_connectsÚ_out_sockoptsÚ_random_addrsÚ_socketsNÚreturnc                 ó   — || _         |€t          d¦  «        ‚|€t          d¦  «        ‚|| _        || _        g | _        g | _        g | _        g | _        g | _        g | _	        g | _
        d| _        d| _        g | _        d S )Nzin_type must be specifiedzout_type must be specifiedTF)r   Ú	TypeErrorr   r   r   r   r   r   r   r   r   r   Údoner    )Úselfr   r   r   s       úc/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/zmq/devices/basedevice.pyÚ__init__zDevice.__init__V   s’   € ð 'ˆÔØˆ?ÝÐ7Ñ8Ô8Ð8ØÐÝÐ8Ñ9Ô9Ð9ØˆŒØ ˆŒØˆŒØˆÔØˆÔØˆŒØˆÔØˆÔØˆÔØˆŒØˆŒ	ØˆŒˆˆó    Úaddrc                 ó:   — | j                              |¦  «         dS )z`Enqueue ZMQ address for binding on in_socket.

        See zmq.Socket.bind for details.
        N)r   Úappend©r%   r)   s     r&   Úbind_inzDevice.bind_inn   s    € ð
 	Œ×Ò˜dÑ#Ô#Ð#Ð#Ð#r(   c                 ó\   —  | j         |g|¢R i |¤Ž}|                      |› d|› �¦  «         |S )z°Enqueue a random port on the given interface for binding on
        in_socket.

        See zmq.Socket.bind_to_random_port for details.

        .. versionadded:: 18.0
        ú:)Ú_reserve_random_portr-   ©r%   r)   ÚargsÚkwargsÚports        r&   Úbind_in_to_random_portzDevice.bind_in_to_random_portu   sK   € ð )ˆtÔ(¨Ð?°Ð?Ð?Ð?¸Ð?Ð?ˆà�Š˜Ð%Ð%˜tÐ%Ð%Ñ&Ô&Ð&àˆr(   c                 ó:   — | j                              |¦  «         dS )zfEnqueue ZMQ address for connecting on in_socket.

        See zmq.Socket.connect for details.
        N)r   r+   r,   s     r&   Ú
connect_inzDevice.connect_inƒ   s!   € ð
 	Ô× Ò  Ñ&Ô&Ð&Ð&Ð&r(   ÚoptÚvaluec                 ó>   — | j                              ||f¦  «         dS )zeEnqueue setsockopt(opt, value) for in_socket

        See zmq.Socket.setsockopt for details.
        N)r   r+   ©r%   r8   r9   s      r&   Úsetsockopt_inzDevice.setsockopt_inŠ   s%   € ð
 	Ô× Ò  # u Ñ.Ô.Ð.Ð.Ð.r(   c                 ó:   — | j                              |¦  «         dS )zaEnqueue ZMQ address for binding on out_socket.

        See zmq.Socket.bind for details.
        N)r   r+   r,   s     r&   Úbind_outzDevice.bind_out‘   s    € ð
 	Œ×Ò˜tÑ$Ô$Ð$Ð$Ð$r(   c                 ó\   —  | j         |g|¢R i |¤Ž}|                      |› d|› �¦  «         |S )z±Enqueue a random port on the given interface for binding on
        out_socket.

        See zmq.Socket.bind_to_random_port for details.

        .. versionadded:: 18.0
        r/   )r0   r>   r1   s        r&   Úbind_out_to_random_portzDevice.bind_out_to_random_port˜   sK   € ð )ˆtÔ(¨Ð?°Ð?Ð?Ð?¸Ð?Ð?ˆà�Š˜Ð&Ð& Ð&Ð&Ñ'Ô'Ð'àˆr(   c                 ó:   — | j                              |¦  «         dS )zgEnqueue ZMQ address for connecting on out_socket.

        See zmq.Socket.connect for details.
        N)r   r+   r,   s     r&   Úconnect_outzDevice.connect_out¦   s!   € ð
 	Ô×!Ò! $Ñ'Ô'Ð'Ð'Ð'r(   c                 ó>   — | j                              ||f¦  «         dS )zfEnqueue setsockopt(opt, value) for out_socket

        See zmq.Socket.setsockopt for details.
        N)r   r+   r;   s      r&   Úsetsockopt_outzDevice.setsockopt_out­   s%   € ð
 	Ô×!Ò! 3¨ ,Ñ/Ô/Ð/Ð/Ð/r(   c                 ór  — t          ¦   «         5 }|                     t          ¦  «        5 }t          d¦  «        D ]%} |j        |g|¢R i |¤Ž}|› d|› �}|| j        v rŒ$ nt          d¦  «        ‚| j                             |¦  «         d d d ¦  «         n# 1 swxY w Y   d d d ¦  «         n# 1 swxY w Y   |S )Né   r/   zCould not reserve random port.)r   Úsocketr   ÚrangeÚbind_to_random_portr   r   r+   )	r%   r)   r2   r3   ÚctxÚbinderÚir4   Únew_addrs	            r&   r0   zDevice._reserve_random_port´   sQ  € Ý‰YŒYð 	4˜#Ø—’�DÑ!Ô!ð 4 VÝ˜q™œð 
Ið 
I�AØ5˜6Ô5°dÐL¸TÐLÐLÐLÀVÐLÐL�Dà"&Ð/Ð/¨Ð/Ð/�Hà 4Ô#5Ð5Ð5Ø à˜å&Ð'GÑHÔHÐHàÔ"×)Ò)¨(Ñ3Ô3Ð3ð4ð 4ð 4ñ 4ô 4ð 4ð 4ð 4ð 4ð 4ð 4øøøð 4ð 4ð 4ð 4ð	4ð 	4ð 	4ñ 	4ô 	4ð 	4ð 	4ð 	4ð 	4ð 	4ð 	4øøøð 	4ð 	4ð 	4ð 	4ð  ˆs5   �B,ªABÂ	B,ÂB	ÂB,ÂB	ÂB,Â,B0Â3B0c                 ó°  — |                       ¦   «         }|| _        |                     | j        ¦  «        }| j                             |¦  «         | j        dk     r|}n4|                     | j        ¦  «        }| j                             |¦  «         | j        D ]\  }}|                     ||¦  «         Œ| j	        D ]\  }}|                     ||¦  «         Œ| j
        D ]}|                     |¦  «         Œ| j        D ]}|                     |¦  «         Œ| j        D ]}|                     |¦  «         Œ| j        D ]}|                     |¦  «         Œ||fS )Nr   )r   Ú_contextrG   r   r    r+   r   r   Ú
setsockoptr   r   Úbindr   r   Úconnectr   )r%   rJ   ÚinsÚoutsr8   r9   Úifaces          r&   Ú_setup_socketszDevice._setup_socketsÇ   s~  € Ø'+×';Ò';Ñ'=Ô'=ˆØˆŒð �jŠj˜œÑ&Ô&ˆØŒ×Ò˜SÑ!Ô!Ð!ØŒ=˜1ÒÐØˆDˆDà—:’:˜dœmÑ,Ô,ˆDØŒM× Ò  Ñ&Ô&Ð&ð Ô+ð 	'ð 	'‰JˆC�Ø�NŠN˜3 Ñ&Ô&Ð&Ð&ØÔ,ð 	(ð 	(‰JˆC�Ø�OŠO˜C Ñ'Ô'Ð'Ð'à”^ð 	ð 	ˆEØ�HŠH�U‰OŒOˆOˆOØ”_ð 	ð 	ˆEØ�IŠI�eÑÔÐÐàÔ&ð 	ð 	ˆEØ�KŠK˜ÑÔÐÐØÔ'ð 	 ð 	 ˆEØ�LŠL˜ÑÔÐÐà�DˆyÐr(   c                 óT   — |                       ¦   «         \  }}t          ||¦  «         dS )zpThe runner method.

        Do not call me directly, instead call ``self.start()``, just like a Thread.
        N)rV   r   )r%   rS   rT   s      r&   Ú
run_devicezDevice.run_deviceæ   s/   € ð
 ×'Ò'Ñ)Ô)‰	ˆˆTÝˆc�4ÑÔÐÐÐr(   c                 óT   — | j         D ]}|r|j        s|                     ¦   «          Œ dS )zCleanup sockets we createdN)r    ÚclosedÚclose)r%   Úss     r&   Ú_close_socketszDevice._close_socketsî   s<   € à”ð 	ð 	ˆAØð ˜œð Ø—’‘	”	�	øð	ð 	r(   c                 ó  — 	 |                       ¦   «          n.# t          $ r!}|j        t          t          hv rn‚ Y d}~nd}~ww xY wd| _        |                      ¦   «          dS # d| _        |                      ¦   «          w xY w)z"wrap run_device in try/catch ETERMNT)rX   r   Úerrnor   r
   r$   r]   )r%   Úes     r&   Úrunz
Device.runô   s¡   € ð
	"Ø�OŠOÑÔÐÐøÝð 	ð 	ð 	ØŒw�5¥(Ð+Ð+Ð+ààð ����øøøøð	øøøð ˆDŒIØ×ÒÑ!Ô!Ð!Ð!Ð!øð ˆDŒIØ×ÒÑ!Ô!Ð!Ð!øøøs(   ‚ –A" —
A¡=¸A" ½AÁA" Á"A?c                 ó*   — |                       ¦   «         S )z>Start the device. Override me in subclass for other launchers.)ra   ©r%   s    r&   ÚstartzDevice.start  s   € à�xŠx‰zŒzÐr(   Útimeoutc                 óÒ   — t          j        ¦   «         }|}| j        sF|�	||z
  |k    s?t          j        d¦  «         t          j        ¦   «         }| j        s|®0||z
  |k    ¯9dS dS dS dS )z\wait for me to finish, like Thread.join.

        Reimplemented appropriately by subclasses.Ngü©ñÒMbP?)ÚtimeÚ	monotonicr$   Úsleep)r%   re   ÚticÚtocs       r&   ÚjoinzDevice.join  s�   € õ ŒnÑÔˆØˆØ”)ð 	# WÐ%8¸SÀ3¹YÈÒ=PÐ=PÝŒJ�uÑÔÐÝ”.Ñ"Ô"ˆCð ”)ð 	# WÐ%8¸SÀ3¹YÈÒ=PÐ=PÐ=PÐ=Pð 	#ð 	#ð 	#ð 	#Ð=PÐ=Pr(   ©r!   N©N)$Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úinstancer   r   ÚzmqÚ__annotations__ÚboolÚintr   Ústrr	   r   ÚSocketr   r   r'   r-   r5   r7   r<   r>   r@   rB   rD   r0   rV   rX   r]   ra   rd   Úfloatrl   © r(   r&   r   r      s'  € € € € € € ð1ð 1ðf 29Ô1A€O�X˜b #¤+˜oÔ.ÐAÐAÑAðð €L€L�LØÐÐÑØ€L€L�LØ€M€M�Mà�CŒyÐÐÑØ�s”)ÐÐÑØ�u˜S #˜X”Ô'Ð'Ð'Ñ'Ø�S”	ÐÐÑØ˜”9ÐÐÑØ˜˜c 3˜hœÔ(Ð(Ð(Ñ(Ø˜”9ÐÐÑØ�3”:ÔÐÐÑð !Ø!%Ø"&ð	ð àðð ˜#”ðð ˜3”-ð	ð
 
ðð ð ð ð0$˜Cð $ Dð $ð $ð $ð $ð¨3ð ÀCð ð ð ð ð'˜sð ' tð 'ð 'ð 'ð 'ð/ ð /¨Sð /°Tð /ð /ð /ð /ð%˜Sð % Tð %ð %ð %ð %ð¨Cð ÀSð ð ð ð ð( ð (ð (ð (ð (ð0 #ð 0¨cð 0ð 0ð 0ð 0ð¨ð À#ð ð ð ð ð&  c¤j°#´*Ð&<Ô =ð ð ð ð ð>ð ð ð ðð ð ð"ð "ð "ð "ðð ð ð ð#ð #˜H UœOð #°tð #ð #ð #ð #ð #ð #r(   r   c                   óV   — e Zd ZU dZdZeed<   dZeed<   d	d„Zd
de	e
         ddfd„ZdS )ÚBackgroundDevicezEBase class for launching Devices in background processes and threads.NÚlauncherÚ_launch_classr!   c                 ó–   — |                       | j        ¬¦  «        | _        | j        | j        _        | j                             ¦   «         S )N)Útarget)r   ra   r~   r   rd   rc   s    r&   rd   zBackgroundDevice.start  s<   € Ø×*Ò*°$´(Ð*Ñ;Ô;ˆŒØ#œ{ˆŒÔØŒ}×"Ò"Ñ$Ô$Ð$r(   re   c                 ó8   — | j                              |¬¦  «        S )N)re   )r~   rl   )r%   re   s     r&   rl   zBackgroundDevice.join  s   € ØŒ}×!Ò!¨'Ð!Ñ2Ô2Ð2r(   rm   rn   )ro   rp   rq   rr   r~   r   ru   r   rd   r   rz   rl   r{   r(   r&   r}   r}     s{   € € € € € € ØOÐOà€HˆcÐÐÑØ€M�3ÐÐÑð%ð %ð %ð %ð
3ð 3˜H UœOð 3°tð 3ð 3ð 3ð 3ð 3ð 3r(   r}   c                   ó   — e Zd ZdZeZdS )ÚThreadDevicezSA Device that will be run in a background Thread.

    See Device for details.
    N)ro   rp   rq   rr   r   r   r{   r(   r&   r„   r„      s   € € € € € ðð ð
 €M€M€Mr(   r„   c                   ó   — e Zd ZdZeZeZdS )ÚProcessDevicezTA Device that will be run in a background Process.

    See Device for details.
    N)ro   rp   rq   rr   r   r   r   r   r{   r(   r&   r†   r†   )  s*   € € € € € ðð ð
 €MØ€Oðð r(   r†   )r   r„   r†   )rr   rg   Úmultiprocessingr   Ú	threadingr   Útypingr   r   r   r   r	   rt   r
   r   r   r   r   r   r   r   r   r}   r„   r†   Ú__all__r{   r(   r&   ú<module>r‹      sk  ðØ 8Ð 8ð
 €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7à 
€
€
€
Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tð#ð #ð #ð #ð #ñ #ô #ð #ðD3ð 3ð 3ð 3ð 3�vñ 3ô 3ð 3ðð ð ð ð Ð#ñ ô ð ð
ð 
ð 
ð 
ð 
Ð$ñ 
ô 
ð 
ð 6Ð
5Ð
5€€€r(   