<s> """<STR_LIT>""" <EOL> from __future__ import nested_scopes <EOL> from pyrepl import completing_reader as cr , reader , completer <EOL> from pyrepl . completing_reader import CompletingReader as CR <EOL> import cmd <EOL> class CmdReader ( CR ) : <EOL> def collect_keymap ( self ) : <EOL> return super ( CmdReader , self ) . collect_keymap ( ) + ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> CR_init = CR . __init__ <EOL> def __init__ ( self , completions ) : <EOL> self . CR_init ( self ) <EOL> self . completions = completions <EOL> def get_completions ( self , stem ) : <EOL> if len ( stem ) != self . pos : <EOL> return [ ] <EOL> return cr . uniqify ( [ s for s in self . completions <EOL> if s . startswith ( stem ) ] ) <EOL> def replize ( klass , history_across_invocations = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> completions = [ s [ <NUM_LIT:3> : ] <EOL> for s in completer . get_class_members ( klass ) <EOL> if s . startswith ( "<STR_LIT>" ) ] <EOL> if not issubclass ( klass , cmd . Cmd ) : <EOL> raise Exception <EOL> class CmdRepl ( klass ) : <EOL> k_init = klass . __init__ <EOL> if history_across_invocations : <EOL> _CmdRepl__history = [ ] <EOL> def __init__ ( self , * args , ** kw ) : <EOL> self . k_init ( * args , ** kw ) <EOL> self . __reader = CmdReader ( completions ) <EOL> self . __reader . history = CmdRepl . _CmdRepl__history <EOL> self . __reader . historyi = len ( CmdRepl . _CmdRepl__history ) <EOL> else : <EOL> def __init__ ( self , * args , ** kw ) : <EOL> self . k_init ( * args , ** kw ) <EOL> self . __reader = CmdReader ( completions ) <EOL> def cmdloop ( self , intro = None ) : <EOL> self . preloop ( ) <EOL> if intro is not None : <EOL> self . intro = intro <EOL> if self . intro : <EOL> print self . intro <EOL> stop = None <EOL> while not stop : <EOL> if self . cmdqueue : <EOL> line = self . cmdqueue [ <NUM_LIT:0> ] <EOL> del self . cmdqueue [ <NUM_LIT:0> ] <EOL> else : <EOL> try : <EOL> self . __reader . ps1 = self . prompt <EOL> line = self . __reader . readline ( ) <EOL> except EOFError : <EOL> line = "<STR_LIT>" <EOL> line = self . precmd ( line ) <EOL> stop = self . onecmd ( line ) <EOL> stop = self . postcmd ( stop , line ) <EOL> self . postloop ( ) <EOL> CmdRepl . __name__ = "<STR_LIT>" % ( klass . __module__ , klass . __name__ ) <EOL> return CmdRepl </s>
