
    Mh`                        d Z ddlZddlZddlmZ ej                            ej                            d                    Z	ej
        Zee	j        _        ee	j        _        ee	j        _        eege	j        _        e	j        Zd Zd Zd Zej                            ej                            d                    Zej        Zee_        eej        ej        eege_        ej        Zej        e_        ege_        ej        Zde_        eej        ge_        ej        Zee_        eeege_        ej        Zee_        ej        Zde_        eeege_        ej        Zde_        ege_        ej         Z de _        ege _        d	Z!e"                    ed
          Z#d Z$d Z%d Z& ej'        deee          Z( e(e&          Z)d Z*d Z+dS )zBInputhook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 Z    t          | t                    s|                     d          } | S )zensure utf8 bytesutf8)
isinstancebytesencode)ss    b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/terminal/pt_inputhooks/osx.py_utf8r      s*    a HHVH    c                 P    t                               t          |                     S )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr      s      t---r   c                 P    t                               t          |                     S )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   !   s    eI..///r   CoreFoundation   kCFRunLoopCommonModesc                      t           t           gt          j        _        t	          t          d          t          d                    S )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplicationvoid_pr   objc_msgSendargtypesmsgr   r    r   r   _NSAppr"   N   s3    "(&!1Dq!!1%8#9#9:::r   c                    t           t           t           t           t           t           t           t           t           t           t           gt          j        _        t	          t          d          t          d          ddddddddd          }t           t           t           t           gt          j        _        t	          | t          d          t          |          d           dS )zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:Tr   )NSAppevents     r   _waker(   T   s     	"D 	)	B	
 	
 								 E  #)&&&!ADq%&&ut<<<<<r   c                     t          |            t          |            t                      }t          t          t          gt          j        _        t          |t          d          |           t          |           dS )z.Callback to fire when there's input to be readzstop:N)
CFFileDescriptorInvalidate	CFReleaser"   r   r   r   r   r    r   r(   )fdrefflagsinfor&   s       r   _input_callbackr/   w   s`    u%%%eHHE"(&&!9Dqzz5!!!	%LLLLLr   c                     t          d| dt          d          }t          |t                     t	          d|d          }t                      }t          ||t                     t          |           dS )z;Register callback to stop eventloop when there's data on fdNFr   )	CFFileDescriptorCreate_c_input_callbackCFFileDescriptorEnableCallBackskCFFileDescriptorReadCallBack#CFFileDescriptorCreateRunLoopSourceCFRunLoopGetCurrentCFRunLoopAddSourcer   r+   )fdr,   sourceloops       r   _stop_on_readr;      sl    "4U4EtLLE#E+HIII0ua@@F  DtV%:;;;fr   c                     t                      }t          |                                            t          t          gt          j        _        t          |t          d                     dS )zInputhook for Cocoa (NSApp)runN)	r"   r;   filenor   r   r   r   r    r   )contextr&   s     r   	inputhookr@      sO    HHE'..""###"(&!1Dqxxr   ),__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr   r   restyper   r   r   r    r   r   r   r   r1   c_intc_bool#CFFileDescriptorGetNativeDescriptorr3   c_ulongr5   r6   r7   r+   r*   r4   in_dllr   r"   r(   r/   	CFUNCTYPE_c_callback_func_typer2   r;   r@   r!   r   r   <module>rR      s              {v{77??@@	#   &  "  $f-  
  . . .0 0 0 (()A)ABR)S)STT'> !'  #)6<PV"W  &4&X #.4l # +06x # ,"0"P *.  ',2FN+C  (&4&X #.4 # +06/G # ,$8 $  #6 !  %vv6  $		 X	 +F %)  "'-h  # !" n6MNN ; ; ; =  =  =F   )(vvvFF ))/::       r   