<s> from libqtile import sh , command <EOL> from ipykernel . kernelbase import Kernel <EOL> class QshKernel ( Kernel ) : <EOL> implementation = '<STR_LIT>' <EOL> implementation_version = '<STR_LIT>' <EOL> language = '<STR_LIT>' <EOL> language_version = '<STR_LIT:1.0>' <EOL> language_info = { '<STR_LIT>' : '<STR_LIT>' } <EOL> banner = "<STR_LIT>" <EOL> def __init__ ( self , ** kwargs ) : <EOL> Kernel . __init__ ( self , ** kwargs ) <EOL> self . client = command . Client ( ) <EOL> self . qsh = sh . QSh ( self . client ) <EOL> def do_execute ( self , code , silent , store_history = True , user_expressions = None , allow_stdin = False ) : <EOL> if not code . strip ( ) : <EOL> return { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . execution_count , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { } , <EOL> } <EOL> if code [ - <NUM_LIT:1> ] == '<STR_LIT:?>' : <EOL> return self . do_inspect ( code , len ( code ) - <NUM_LIT:1> ) <EOL> try : <EOL> output = self . qsh . process_command ( code ) <EOL> except KeyboardInterrupt : <EOL> return { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . execution_count , <EOL> } <EOL> if not silent and output : <EOL> stream_content = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:text>' : output } <EOL> self . send_response ( self . iopub_socket , '<STR_LIT>' , stream_content ) <EOL> return { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . execution_count , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { } , <EOL> } <EOL> def do_complete ( self , code , cursor_pos ) : <EOL> no_complete = { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : cursor_pos , <EOL> '<STR_LIT>' : dict ( ) , <EOL> } <EOL> if not code or code [ - <NUM_LIT:1> ] == '<STR_LIT:U+0020>' : <EOL> return no_complete <EOL> tokens = code . split ( ) <EOL> if not tokens : <EOL> return no_complete <EOL> token = tokens [ - <NUM_LIT:1> ] <EOL> start = cursor_pos - len ( token ) <EOL> matches = self . qsh . _complete ( code , token ) <EOL> return { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : sorted ( matches ) , <EOL> '<STR_LIT>' : start , <EOL> '<STR_LIT>' : cursor_pos , <EOL> '<STR_LIT>' : dict ( ) , <EOL> } <EOL> def main ( ) : <EOL> from ipykernel . kernelapp import IPKernelApp <EOL> IPKernelApp . launch_instance ( kernel_class = QshKernel ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
