Qf:ndZddlZddlZdgZdZej ej zdzZGddZy)a A generic class to build line-oriented command interpreters. Interpreters constructed with this class obey the following conventions: 1. End of file on input is processed as the command 'EOF'. 2. A command is parsed out of each line by collecting the prefix composed of characters in the identchars member. 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method is passed a single argument consisting of the remainder of the line. 4. Typing an empty line repeats the last command. (Actually, it calls the method `emptyline', which may be overridden in a subclass.) 5. There is a predefined `help' method. Given an argument `topic', it calls the command `help_topic'. With no arguments, it lists all topics with defined help_ functions, broken into up to three topics; documented commands, miscellaneous help topics, and undocumented commands. 6. The command '?' is a synonym for `help'. The command '!' is a synonym for `shell', if a do_shell method exists. 7. If completion is enabled, completing commands will be done automatically, and completing of commands args is done by calling complete_foo() with arguments text, line, begidx, endidx. text is string we are matching against, all returned matches must begin with it. line is the current input line (lstripped), begidx and endidx are the beginning and end indexes of the text being matched, which could be used to provide different completion depending upon which position the argument is in. The `default' method may be overridden to intercept commands for which there is no do_ method. The `completedefault' method may be overridden to intercept completions for commands that have no complete_ method. The data member `self.ruler' sets the character used to draw separator lines in the help messages. If empty, no ruler line is drawn. It defaults to "=". If the value of `self.intro' is nonempty when the cmdloop method is called, it is printed out on interpreter startup. This value may be overridden via an optional argument to the cmdloop() method. The data members `self.doc_header', `self.misc_header', and `self.undoc_header' set the headers used for the help function's listings of documented functions, miscellaneous topics, and undocumented functions respectively. NCmdz(Cmd) _ceZdZdZeZeZdZdZ dZ dZ dZ dZ dZdZd Zdd Zdd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!ddZ"y)raA simple framework for writing line-oriented command interpreters. These are often useful for test harnesses, administrative tools, and prototypes that will later be wrapped in a more sophisticated interface. A Cmd instance or subclass instance is a line-oriented interpreter framework. There is no good reason to instantiate Cmd itself; rather, it's useful as a superclass of an interpreter class you define yourself in order to inherit Cmd's methods and encapsulate action methods. =Nz(Documented commands (type help ):zMiscellaneous help topics:zUndocumented commands:z*** No help on %sc|||_ntj|_|||_ntj|_g|_||_y)aInstantiate a line-oriented interpreter framework. The optional argument 'completekey' is the readline name of a completion key; it defaults to the Tab key. If completekey is not None and the readline module is available, command completion is done automatically. The optional arguments stdin and stdout specify alternate input and output file objects; if not specified, sys.stdin and sys.stdout are used. N)stdinsysstdoutcmdqueue completekey)selfrr r s */opt/alt/python312/lib64/python3.12/cmd.py__init__z Cmd.__init__LsC  DJDJ   DK**DK &c|j|jr_|jrS ddl}|j |_|j |j|j|jdz |||_ |jr1|jjt|jdzd}|s|jr|jjd}n|jr t!|j"}nx|jj|j"|jj'|j(j}t+|sd}n|j-d}|j/|}|j1|}|j3||}|s|j5|jr.|jr! ddl}|j |j yyy#t$rYwxYw#t$$rd}YwxYw#t$rYywxYw#|jr=|jr0 ddl}|j |j w#t$rYwwxYwwwxYw)zRepeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument. rNz : complete EOFz )preloop use_rawinputrreadline get_completer old_completer set_completercompleteparse_and_bind ImportErrorintror writestrr popinputpromptEOFErrorflushr lenrstripprecmdonecmdpostcmdpostloop)rrrstoplines rcmdloopz Cmd.cmdloopbs$    !1!1 %-%;%;%="&&t}}5''(8(8(EF!  " zz !!#djj/$"67D====,,Q/D(()#(#5D ))$++6 ))+#zz224"4y#(D#';;v#6D{{4({{4(||D$/'( MMO  T%5%5#**4+=+=>&6 =   ()#(D)&#   T%5%5#**4+=+=>" &6 sAH =A>H<<HB/H<H<*H- HH H*'H<)H**H<- H98H9<JI65J6 J?JJJc|S)zHook method executed just before the command line is interpreted, but after the input prompt is generated and issued. rr.s rr)z Cmd.precmds  rc|S)z?Hook method executed just after a command dispatch is finished.r1)rr-r.s rr+z Cmd.postcmds rcy)z>Hook method executed once when the cmdloop() method is called.Nr1rs rrz Cmd.preloops rcy)zYHook method executed once when the cmdloop() method is about to return. Nr1r5s rr,z Cmd.postloops rcN|j}|sdd|fS|ddk(r d|ddz}n"|ddk(rt|dr d|ddz}ndd|fSdt|}}||kr-|||jvr|dz}||kr|||jvr|d|||dj}}|||fS) zParse the line into a command name and a string containing the arguments. Returns a tuple containing (command, args, line). 'command' and 'args' may be None if the line couldn't be parsed. Nr?zhelp r!do_shellzshell )striphasattrr' identchars)rr.incmdargs r parselinez Cmd.parselines zz|t# # !W^T!"X%D !W^tZ($qr(*T4''#d)1!eQ4??2!Aa!eQ4??28T!"X^^-SC~rc8|j|\}}}|s|jS||j|S||_|dk(rd|_|dk(r|j|S t |d|z}||S#t $r|j|cYSwxYw)ahInterpret the argument as though it had been typed in response to the prompt. This may be overridden, but should not normally need to be; see the precmd() and postcmd() methods for useful execution hooks. The return value is a flag indicating whether interpretation of commands by the interpreter should stop. rrdo_)rB emptylinedefaultlastcmdgetattrAttributeError)rr.r@rAfuncs rr*z Cmd.onecmds-S$>># # ;<<% % 5=DL "9<<% % *tUS[19 " *||D)) *s%A<<BBcR|jr|j|jSy)zCalled when an empty line is entered in response to the prompt. If this method is not overridden, it repeats the last nonempty command entered. N)rGr*r5s rrEz Cmd.emptylines# <<;;t||, , rc@|jjd|zy)zCalled on an input line when the command prefix is not recognized. If this method is not overridden, it prints an error message and returns. z*** Unknown syntax: %s N)r r r2s rrFz Cmd.defaults 4T9:rcgS)zMethod called to complete an input line when no command-specific complete_*() method is available. By default, it returns an empty list. r1)rignoreds rcompletedefaultzCmd.completedefaults  rc|d|z}|jDcgc]}|j|s|ddc}Scc}w)NrD) get_names startswith)rtextrNdotextas r completenameszCmd.completenamess=t#~~/H/!1<<3G!"/HHHs99c|dk(rddl}|j}|j}t|t|z }|j |z }|j |z }|dkDr8|j |\} } } | dk(r |j} n t|d| z} n |j} | |||||_ |j|S#t$r|j} Y7wxYw#t$rYywxYw)zReturn the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_ to get list of completions. rNr complete_) rget_line_bufferlstripr' get_begidx get_endidxrBrOrHrIrWcompletion_matches IndexError) rrTstaterorigliner.strippedbegidxendidxr@argsfoocompfuncs rrz Cmd.completes A: //1H??$D8}s4y0H((*X5F((*X5Fax!%!5T3"9#33H8#*4s1B#C --&.tT66&JD # **51 1 *8#'#7#78  s$CC+C('C(+ C76C7c,t|jSN)dir __class__r5s rrRz Cmd.get_namess4>>""rct|j}tfd|jD}t||zS)Nc3VK|] }|jddzr|dd"yw)help_rN)rS).0rVres r z$Cmd.complete_help.. s49$4q WtAw%67qrU$4s&))setrWrRlist)rrecommandstopicss ` r complete_helpzCmd.complete_helpsH)t))4019DNN$499Hv%&&rc4|r t|d|z}|y|j}g}g}t}|D]}|dddk(s |j|dd!|jd} |D]x}|dddk(s || k(r|} |dd} | |vr#|j| |j| @t||jr|j| h|j| z|jj dt |jz|j|j|dd |j|j t#|dd |j|j$|dd y#t$r t|d|zj}|r)|jj dt |zYyn#t$rYnwxYw|jj dt |j |fzzYywxYw) zEList available commands with "help" or detailed help with "help cmd".rnrD%s NrorrQP)rHrI__doc__r r r!nohelprRrraddsortappendremove doc_leader print_topics doc_header misc_headersorted undoc_header) rrArJdocnamescmds_doc cmds_undocrunameprevnamer@s rdo_helpz Cmd.do_help$s  tWs]3 FNN$EHJUF8w&JJtABx( JJLH8u$x' #HQRCf} , c* t,44 ,"))#. KK  fS%99 :   dooR C   d..2 F   d//R CM" eck2::C ))&S/:& !!&T[[C6-A)B"BC s6F H AGH GHG8HHc J|r|jjdt|z|jr=|jjdt|jt |zz|j ||dz |jjdyy)Nrxrr)r r r!rulerr' columnize)rheadercmdscmdlenmaxcols rrzCmd.print_topicsRsy  KK  fS[0 1zz !!&TZZ#f+-E)F"FG NN4 * KK  d # rc ^|s|jjdytt|Dcgc]}t ||t s|}}|r+t ddjtt |zt|}|dk(r+|jjdt |dzytdt|D]}||zdz |z}g}d} t|D]]} d} t|D]+} | || zz}||k\rn||} t| t| } -|j| | | d zz } | |kDs]n| |ksnt|}d}dg}t|D]} g}t|D](} | || zz}||k\rd } n||} |j| *|r|d s |d =|r|d s tt|D]} || j|| || <|jjdt d j|zycc}w) zDisplay a list of strings as a compact set of columns. Each column is only as wide as necessary. Columns are separated by two spaces (one was not legible enough). z Nz list[i] not a string for i in %sz, rrxrrz ) r r ranger' isinstancer! TypeErrorjoinmapmaxrljust)rrs displaywidthr> nonstringssizenrowsncols colwidthstotwidthcolcolwidthrowxtextss rrz Cmd.columnizeZsA  KK  k * !&s4y!19!1A)$q'37!1 9 >"iiC(<=>? ?4y 19 KK  fSa\1 2 1c$i(E%Z\e+EIHU| rsA*X '   ! !FMM 1C 7 ]<]