§
    ‹ŸjL  ã                  óH   — d Z ddlmZ ddlZddlmZmZ  G d„ d¦  «        ZdS )zWin32 compatibility utilities.é    )ÚannotationsN)ÚAnyÚCallablec                  ó.   — e Zd ZdZddd„Zd„ Zd	„ Zd
„ ZdS )Úallow_interruptaD  Utility for fixing CTRL-C events on Windows.

    On Windows, the Python interpreter intercepts CTRL-C events in order to
    translate them into ``KeyboardInterrupt`` exceptions.  It (presumably)
    does this by setting a flag in its "console control handler" and
    checking it later at a convenient location in the interpreter.

    However, when the Python interpreter is blocked waiting for the ZMQ
    poll operation to complete, it must wait for ZMQ's ``select()``
    operation to complete before translating the CTRL-C event into the
    ``KeyboardInterrupt`` exception.

    The only way to fix this seems to be to add our own "console control
    handler" and perform some application-defined operation that will
    unblock the ZMQ polling operation in order to force ZMQ to pass control
    back to the Python interpreter.

    This context manager performs all that Windows-y stuff, providing you
    with a hook that is called when a CTRL-C event is intercepted.  This
    hook allows you to unblock your ZMQ poll operation immediately, which
    will then result in the expected ``KeyboardInterrupt`` exception.

    Without this context manager, your ZMQ-based application will not
    respond normally to CTRL-C events on Windows.  If a CTRL-C event occurs
    while blocked on ZMQ socket polling, the translation to a
    ``KeyboardInterrupt`` exception will be delayed until the I/O completes
    and control returns to the Python interpreter (this may never happen if
    you use an infinite timeout).

    A no-op implementation is provided on non-Win32 systems to avoid the
    application from having to conditionally use it.

    Example usage:

    .. sourcecode:: python

       def stop_my_application():
           # ...

       with allow_interrupt(stop_my_application):
           # main polling loop.

    In a typical ZMQ application, you would use the "self pipe trick" to
    send message to a ``PAIR`` socket in order to interrupt your blocking
    socket polling operation.

    In a Tornado event loop, you can use the ``IOLoop.stop`` method to
    unblock your I/O loop.
    NÚactionúCallable[[], Any] | NoneÚreturnÚNonec                óT   — t           j        dk    rdS |                      |¦  «         dS )a  Translate ``action`` into a CTRL-C handler.

        ``action`` is a callable that takes no arguments and returns no
        value (returned value is ignored).  It must *NEVER* raise an
        exception.

        If unspecified, a no-op will be used.
        ÚntN)ÚosÚnameÚ_init_action)Úselfr   s     ú\/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/zmq/utils/win32.pyÚ__init__zallow_interrupt.__init__@   s.   € õ Œ7�dŠ?ˆ?ØˆFØ×Ò˜&Ñ!Ô!Ð!Ð!Ð!ó    c                óæ   ‡— ddl m}m} ddlm}m} |                     d¦  «        } |||¦  «        }|j        x}| _        ||f|_	        ||_
        ‰€d„ Š‰| _        |ˆfd„¦   «         }	|	| _        d S )Nr   )ÚWINFUNCTYPEÚwindll)ÚBOOLÚDWORDÚkernel32c                 ó   — d S ©N© r   r   r   r   z,allow_interrupt._init_action.<locals>.action]   s   € Ø�tr   c                ó(   •— | dk    r
 ‰¦   «          dS )Nr   r   )Úeventr   s    €r   Úhandlez,allow_interrupt._init_action.<locals>.handleb   s   ø€ à˜ŠzˆzØ�‘”�ð �1r   )Úctypesr   r   Úctypes.wintypesr   r   ÚLoadLibraryÚSetConsoleCtrlHandlerÚ_SetConsoleCtrlHandlerÚargtypesÚrestyper   r    )
r   r   r   r   r   r   r   ÚPHANDLER_ROUTINEr$   r    s
    `        r   r   zallow_interrupt._init_actionM   sÔ   ø€ Ø.Ð.Ð.Ð.Ð.Ð.Ð.Ð.Ø/Ð/Ð/Ð/Ð/Ð/Ð/Ð/à×%Ò% jÑ1Ô1ˆð '˜; t¨UÑ3Ô3ÐàÔ*ð	
Ð Ô ;ð +;¸DÐ)AÐÔ&Ø(,ÐÔ%àˆ>ðð ð ð ˆŒà	ð		ð 		ð 		ð 		ñ 
Ô	ð		ð ˆŒˆˆr   c                óˆ   — t           j        dk    rdS |                      | j        d¦  «        }|dk    rt	          ¦   «         ‚dS )z"Install the custom CTRL-C handler.r   Né   r   ©r   r   r%   r    ÚOSError)r   Úresults     r   Ú	__enter__zallow_interrupt.__enter__p   óD   € åŒ7�dŠ?ˆ?ØˆFØ×,Ò,¨T¬[¸!Ñ<Ô<ˆØ�QŠ;ˆ;õ ‘)”)ˆOð ˆ;r   c                óˆ   — t           j        dk    rdS |                      | j        d¦  «        }|dk    rt	          ¦   «         ‚dS )z!Remove the custom CTRL-C handler.r   Nr   r+   )r   Úargsr-   s      r   Ú__exit__zallow_interrupt.__exit__z   r/   r   r   )r   r	   r
   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r.   r2   r   r   r   r   r      sf   € € € € € ð0ð 0ðd"ð "ð "ð "ð "ð!ð !ð !ðFð ð ðð ð ð ð r   r   )r6   Ú
__future__r   r   Útypingr   r   r   r   r   r   ú<module>r9      s|   ðØ $Ð $ð #Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  ðuð uð uð uð uñ uô uð uð uð ur   