+
    ^|i`                     F   R t ^ RIt^ RIt^ RIHt ]P
                  P                  ]P                  P                  R4      4      t	]P                  t]]	P                  n        ]]	P                  n        ]]	P                  n        ]].]	P                  n        ]	P                  tR tR tR t]P
                  P                  ]P                  P                  R4      4      t]P,                  t]]n        ]]P.                  ]P0                  ]].]n        ]P2                  t]P.                  ]n        ].]n        ]P4                  tR]n        ]]P6                  .]n        ]P8                  t]]n        ]]].]n        ]P:                  t]]n        ]P<                  tR]n        ]]].]n        ]P>                  tR]n        ].]n        ]P@                  t R] n        ].] n        ^t!]PE                  ]R4      t#R	 t$R
 t%R t&]PN                  ! R]]]4      t(](! ]&4      t)R t*R t+R# )zBInputhook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
N)Eventobjcc                T    \        V \        4      '       g   V P                  R4      p V # )zensure utf8 bytesutf8)
isinstancebytesencode)ss   &D/usr/lib/python3/dist-packages/IPython/terminal/pt_inputhooks/osx.py_utf8r      s"    aHHVH    c                >    \         P                  \        V 4      4      # )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names   &r
   nr      s      t--r   c                >    \         P                  \        V 4      4      # )zget an ObjC Class by name)r   objc_getClassr   )	classnames   &r
   Cr   !   s    eI.//r   CoreFoundationkCFRunLoopCommonModesc                 |    \         \         .\        P                  n        \	        \        R4      \        R4      4      # )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplicationvoid_pr   objc_msgSendargtypesmsgr   r    r   r
   _NSAppr    N   s-    "(&!1Dq!1%8#9::r   c                ~   \         \         \         \         \         \         \         \         \         \         \         .\        P                  n        \	        \        R4      \        R4      ^^ ^ ^ ^ R^ ^ ^ 4      p\         \         \         \         .\        P                  n        \	        V \        R4      \        V4      R4       R# )zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:NzpostEvent:atStart:Tr   )NSAppevents   & r
   _waker%   T   s     	"D 	)	B	
 								E  #)&&&!ADq%&ut<r   c                    \        V 4       \        V 4       \        4       p\        \        \        .\        P
                  n        \        V\        R4      V4       \        V4       R# )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   sE    u%eHE"(&&!9Dqz5!	%Lr   c                    \        RV R\        R4      p\        V\        4       \	        RV^ 4      p\        4       p\        W2\        4       \        V4       R# )z;Register callback to stop eventloop when there's data on fdNF)	CFFileDescriptorCreate_c_input_callbackCFFileDescriptorEnableCallBackskCFFileDescriptorReadCallBack#CFFileDescriptorCreateRunLoopSourceCFRunLoopGetCurrentCFRunLoopAddSourcer   r(   )fdr)   sourceloops   &   r
   _stop_on_readr8      sI    "4U4EtLE#E+HI0ua@F Dt%:;fr   c                    \        4       p\        V P                  4       4       \        \        .\        P
                  n        \        V\        R4      4       R# )zInputhook for Cocoa (NSApp)runN)	r    r8   filenor   r   r   r   r   r   )contextr#   s   & r
   	inputhookr=      s9    HE'.."#"(&!1Dqxr   ),__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr   r   restyper   r   r   r   r   r   r   r   r.   c_intc_bool#CFFileDescriptorGetNativeDescriptorr0   c_ulongr2   r3   r4   r(   r'   r1   in_dllr   r    r%   r,   	CFUNCTYPE_c_callback_func_typer/   r8   r=   r   r   r
   <module>rO      s/     {{v{{77?@	#    &   "   $f-   
.0 (()A)ABR)ST'>> !'  #)6<<PV"W  &4&X&X #.4ll # +06x # ,"0"P"P *.  ',2FNN+C  (&4&X&X #.4 # +06/G # ,$88 $  #66 !  %vv6  $$		 X	 +FF %)  "'-h  # !" n6MN ; =F ((vvvF )/: r   