<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import os <EOL> import threading <EOL> __all__ = ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> class InputHookContext ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , inputhook ) : <EOL> assert callable ( inputhook ) <EOL> self . inputhook = inputhook <EOL> self . _input_is_ready = None <EOL> self . _r , self . _w = os . pipe ( ) <EOL> def input_is_ready ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _input_is_ready ( wait = False ) <EOL> def fileno ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _r <EOL> def call_inputhook ( self , input_is_ready_func ) : <EOL> """<STR_LIT>""" <EOL> self . _input_is_ready = input_is_ready_func <EOL> def thread ( ) : <EOL> input_is_ready_func ( wait = True ) <EOL> os . write ( self . _w , b'<STR_LIT:x>' ) <EOL> threading . Thread ( target = thread ) . start ( ) <EOL> self . inputhook ( self ) <EOL> try : <EOL> os . read ( self . _r , <NUM_LIT> ) <EOL> except OSError : <EOL> pass <EOL> self . _input_is_ready = None <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _r : <EOL> os . close ( self . _r ) <EOL> os . close ( self . _w ) <EOL> self . _r = self . _w = None </s>
