{hAdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZmZddlmZmZmZddlmZmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd l(m,Z,m-Z-m.Z.dd l/m0Z0m1Z1dd l2m3Z3m4Z4dd l)m5Z5m6Z6m7Z7m8Z8ddl9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEddlFmGZGmHZHmIZIddlJmKZKmLZLmMZMmNZNmOZOejPeQ5ddlRmSZSdddn #1swxYwYddlTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^ddl_m`Z`maZaddl+mbZbmcZcmdZdmeZemfZfe\eUjgkr)e jhie&jje]nddlTmkZkmlZlekjmZne\eUjokrekjpjqjrZsnUe\eUjtkrJddluZuddlTmvZveujwxevdZye$ezeuj$eyeuj{j|Z}GddZ~GddZedgdZer(egejfZee#de4fgejfZneZeZGd d!ZGd"dejZdS)#avVariant on standard library's cmd with extra features. To use, simply import cmd2.Cmd instead of cmd.Cmd; use precisely as though you were using the standard library's cmd, while enjoying the extra features. Searchable command history (commands: "history") Run commands from file, save to file, edit commands in file Multi-line commands Special-character shortcut commands (beyond cmd's "?" and "!") Settable environment parameters Parsing commands with `argparse` argument parsers (flags) Redirection to file or paste buffer (clipboard) with > or >> Easy transcript-based testing of applications (see examples/example.py) Bash-style ``select`` available Note that redirection with > and | will only work if `self.poutput()` is used in place of `print`. - Catherine Devlin, Jan 03 2008 - catherinedevlin.blogspot.com Git repository on GitHub at https://github.com/python-cmd2/cmd2 N)InteractiveConsole) OrderedDict namedtuple)CallableIterableMapping) FrameType ModuleType) IO TYPE_CHECKINGAnyClassVarOptionalTextIOTypeVarUnioncast)ansiargparse_completerargparse_custom constantspluginutils)ChoicesProviderFunc CompleterFuncCompletionItem)get_paste_bufferwrite_to_paste_buffer) CommandFunc CommandSet) CLASS_ATTR_DEFAULT_HELP_CATEGORYCOMMAND_FUNC_PREFIXCOMPLETER_FUNC_PREFIXHELP_FUNC_PREFIX) CommandParentas_subcommand_towith_argparser)Cmd2ShlexErrorCommandSetRegistrationErrorCompletionErrorEmbeddedConsoleExitEmptyStatementPassThroughExceptionRedirectionErrorSkipPostcommandHooks)History HistoryItemsingle_line_format)MacroMacroArg StatementStatementParser shlex_split start_ipython) RlTyperl_escape_promptrl_get_display_prompt rl_get_point rl_get_promptrl_in_search_mode rl_set_promptrl_type rl_warning vt100_support)Column SimpleTable)Settableget_defining_class get_typesstrip_doc_annotationssuggest_similar)readlinerl_force_redisplay) readline_librl_basic_quote_charactersceZdZdZddZdS)_SavedReadlineSettingszRreadline settings that are backed up when switching between readline environments.returnNc0d|_d|_d|_dS)N) completerdelims basic_quotesselfs Y/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/cmd2/cmd2.py__init__z_SavedReadlineSettings.__init__s -1rRN__name__ __module__ __qualname____doc__r[r\rZrQrQs.\\222222r\rQceZdZdZddZdS) _SavedCmd2EnvzWcmd2 environment settings that are backed up when entering an interactive Python shell.rRNcdt|_d|_g|_d|_d|_dSN)rQreadline_settingsreadline_modulehistory sys_stdout sys_stdinrXs rZr[z_SavedCmd2Env.__init__s1!7!9!959"$ ,0+/r\r]r^rcr\rZreres.aa000000r\reDisabledCommandcommand_function help_functioncompleter_functionCmdceZdZdZd dZededefdZdede fd Z dede e j fd Zdeddfd ZdS) _CommandParserszCreate and store all command method argument parsers for a given Cmd instance. Parser creation and retrieval are accomplished through the get() method. cmdrrrRNc"||_i|_dSrg)_cmd_parsers)rYrus rZr[z_CommandParsers.__init__s =? r\command_methodcH |jd|jS#t$rYdSwxYw)zQReturn the fully qualified name of a method or None if a method wasn't passed in..rT)r`raAttributeError)rys rZ_fully_qualified_namez%_CommandParsers._fully_qualified_namesC $/OO.2MOO O   22 s  !!cJ||}t|S)zReturn whether a given method's parser is in self. If the parser does not yet exist, it will be created if applicable. This is basically for checking if a method is argarse-based. )getbool)rYryparsers rZ __contains__z_CommandParsers.__contains__s! .))F||r\cL||}|sdS||jvr|jtsdS|jt td}t |tjd}|dS|j |p|j }|j |||}|j :t|dr*|jjrt!|jj|_ ||j|<|j|S)zReturn a given method's parser or None if the method is not argparse-based. If the parser does not yet exist, it will be created. N __wrapped__)r}rxr_ startswithr#lengetattrrCMD_ATTR_ARGPARSERrwfind_commandset_for_command _build_parser descriptionhasattrrrbrJr)rYryfull_method_namecommandparser_builderparentrs rZrz_CommandParsers.gets"  55nEE 4 4= 0 0!*556IJJ t$-c2E.F.F.H.HIG$^Y5QSWXXN%tY::7CCPtyFY,,V^WMMF!)gnm.T.T)YgYsY{)%:>;U;]%^%^".4DM* +}  !1222r\cV||}||jvr |j|=dSdS)z,Remove a given method's parser if it exists.N)r}rx)rYryrs rZremovez_CommandParsers.removes<55nEE t} , , ./// - ,r\)rurrrRN)r_r`rarbr[ staticmethodr strr}rrrargparseArgumentParserrrrcr\rZrtrts ????kc\;43+3(8;R2S3333:0[0T000000r\rtc*h)eZdZUdZejZdZejZ ej Z gZ e eeed< dddddddd dd ddddd d dd d ed eed eededededededededeeededeeedeeedeeeefdeeededededdf(fdZdd d!eed"edeefd#Zd$edeefd%Zdd&Zd'eddfd(Zd)ed*ee j!e"ge j!fe#e$fd+ede j!fd,Z%dd-ed.e&d/eddfd0Z'd1ed2e(ddfd3Z)d1ed4e"d5ddfd6Z*d'eddfd7Z+d'eddfd8Z,d'eedfddfd9Z-d'eedfddfd:Z.e/defd;Z0e0j1dZ4d?e3ddfd@Z5dAeddfdBZ6ddCZ7e/de8j9fdDZ:e:j1dEe8j9ddfdFZ:defdGZ;e/defdHZdMedNee"egefddf dOZ?ddIdPdLe>dMeddfdQZ@ddId dRdLe>dMedSeddfdTZAddIdPdLe>dMeddfdUZBddIdPdLe>dMeddfdVZCdId dRdLe>dMedSeddfdWZDdIdPdLe>dMeddfdXZEdIddYdLe>dMedZeddfd[ZFd\d]ddId^d_e>d`edaedbeedMeddf dcZGdddZHdeedfedgedeIeeeeffdhZJdiedeedfedgedjeedeef dkZKdiedeedfedgedjeedledeefdmZLddndiedeedfedgedoeeeeee(ffdpedeee(fdeefdqZMddndiedeedfedgedre2eeeee(ffdpeeeee(fdeefdsZNddtdiedeedfedgeduee"egefdeef dvZOddwdiedeedfedgedxedeef dyZPdiedeedfedgedze(deef d{ZQeRd|eedeIeeeffd}ZSd~edeededdfdZTdeeddfdZUeRde j!deeVjWfdZX ddiedeedfedgedeejYddf dZZ ddiededeejYdeefdZ[defdZ\defdZ]e/deeeffdZ^deefdZ_deefdZ`deefdZaebecdd]gdZddeeefdZfebecdd]gdZgdeeefdZhebecddecddgdZideeefdZjdeefdZkdeefdZldedeemddfdZndedeemddfdZoddZpdeeqefdeqfdZrdedeeqefdefdZsddZtddZudeedeIeeeffdZvd dddddeededededeedef dZwdedeeqdefdZxd dddeeeyeefdededefdZzdddeedeedeqfdZ{dddeedeedeqfdZ|deqdeefdZ}deqdej~fdZdeqdej~ddfdZdedee&fdZd ddeeqefdedefdZdeqdeefdZdedeefdZdejjdddddddedeeedejdedeee>deedee(dee j!defdƄZdedefdDŽZdefdȄZdeddfdʄZdd˄ZdZdZejeeΦZedd Цeed Ѧde jddfdӄZdZdZejeeΦZedAd֬צeddek٦ede jdeOܦeddeeצde jddfd߄ZdZdZejeZeddddede jdefededdeeצde jddfdZdZdZejeZede jdefededdeeצde jddfdZdZdZejeeΦZedd Цeed Ѧde jddfdZdZdZdZejeeΦZedAdצeddek٦ede jdeOܦeddeeצde jddfdZdZdZejeZeddddede jdehegeddeeצde jddfdZdZdZejeZede jdehegeddeeצde jddfdZdiedeedfedgedeef dZdiedeedfedgedeeeefdeef dZejdZed d dd ede jd eܦed e jdeܦeejddeejdeede jddffd Zdedeeedededdf dZÐddeeededdfdZĐddeddfdZdeIeeeefeeeeeeffdZƐdedeededdfdZejdZeeȦde jddfdZejdeΦZeeʦde jdeefdZejd Zee̦de jdeefd!Z͐dd#eeeeeeIe>eeffdede>fd$Zdiedeedfedgedeeeefdeef d%Zϐd&Zejed'ZeѠd(e jd)ejeiejeg*ZeҠd+e jd,ed -eed Ѧde jddfd.Zejd/ZeԠdd0eP1eԠde jdeOܦeed Ѧde jddfd2ZeRdd3Z֐d4edefd5Zِd6eddfd7Zdd8d9eedeefd:Zejd;Zeeܦde jdeefd<Zejd=Zeޠd>d?eO1eޠd@e jdAeOܦeeަde jdeefdBZejdCZeede jdeefdDZdEZejeZeZe堚dFdGddHe堚dIdJddKe堚dLdMdNdOeOPe堚dQdRdSdTeOPe堚dUdVddWedXYZe砚dZd[dd\e砚d]d^dd_e砚d d dd`e砚ddddadbZe㠚dce jedeede jdeefdeZde jddffdgZdheddfdiZddjZd ddeeeyeefdkededdfdlZdmZejeZedne jdoeOܦeede jddfdpZddneeddfdqZe/deefdrZdsZejeZedQdRdSdteOPed>d?eO1eede jdeefduZeZedvz ZdwZejeeΦZedndxצeede jdeefdyZdzeeddfd{Zdd|ed}eeddfd~Zd}eddfdZddZdefdZeRdeddfdZdeddfdZdeddfdZdededdfdZdededdfdZde>dede>ddfdZddeedefdZddZede"de>fdeddfdZede"gdfddfdZ de"gdfddfdZ de"gdfddfdZ ede"e j ge j fddfdZde"e j ge j fddfdZedZede"egefdeeddfdZde"e jge jfddfdZde"e jge jfddfdZede"e jge jfddfdZde"e jge jfddfdZde"de>fdeeddfdeefdZxZS(rraIAn easy but powerful framework for writing line-oriented command interpreters. Extends the Python Standard Library's cmd package by adding a lot of useful features to the out of the box configuration. Line-oriented command interpreters are often useful for test harnesses, internal tools, and rapid prototypes. zcNotes: This command is for internal use and is not intended to be called from the command line. testfilestabNrTiFT)persistent_history_filepersistent_history_lengthstartup_scriptsilence_startup_script include_py include_ipyallow_cli_argstranscript_filesallow_redirectionmultiline_commands terminators shortcuts command_setsauto_load_commandsallow_clipboardsuggest_similar_command completekeystdinstdoutrrrrrrrrrrrrrrrrrRc|st|dd| st|dd|t|||d|_| |_d|_d|_d|_tj |_ d|_ d|_ d|_d|_d|_i|_d|_t'|_i|_|d|_d|_d d g|_d |_||_||d d g|_i|_g|_d |_ i|_!d|_"tG|| ||_$d|_%g|_&tOj(|_)d|_*d|_+d|_,d |_-d|_.d|_/d|_0d |_1g|_2|rtfj45tfj46|}tfj47|rRdtOj8|}|r|dtrj:dtfj;z }|j2<|d|_=| rot}j?}|@dddd|A\}}|jBr||_=n&|r|j2C|n | r| |_=tjEFdrdx|_G|_Hnd|_Gd|_H||_Id|_JtjL|_Mi|_Nd|_OtjP|_Qd|_Rd|_Sd |_Td |_Ug|_Vg|_Wd|_Xd|_Yt||_[|\||r|D]}|]||r|^|_D]6}|j$`|\}}|std|d |7||_bd!|_cd|_ddS)"aJEasy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package. :param completekey: readline name of a completion key, default to Tab :param stdin: alternate input file object, if not specified, sys.stdin is used :param stdout: alternate output file object, if not specified, sys.stdout is used :param persistent_history_file: file path to load a persistent cmd2 command history from :param persistent_history_length: max number of history items to write to the persistent history file :param startup_script: file path to a script to execute at startup :param silence_startup_script: if ``True``, then the startup script's output will be suppressed. Anything written to stderr will still display. :param include_py: should the "py" command be included for an embedded Python shell :param include_ipy: should the "ipy" command be included for an embedded IPython shell :param allow_cli_args: if ``True``, then [cmd2.Cmd.__init__][] will process command line arguments as either commands to be run or, if ``-t`` or ``--test`` are given, transcript files to run. This should be set to ``False`` if your application parses its own command line arguments. :param transcript_files: pass a list of transcript files to be run on initialization. This allows running transcript tests when ``allow_cli_args`` is ``False``. If ``allow_cli_args`` is ``True`` this parameter is ignored. :param allow_redirection: If ``False``, prevent output redirection and piping to shell commands. This parameter prevents redirection and piping, but does not alter parsing behavior. A user can still type redirection and piping tokens, and they will be parsed as such but they won't do anything. :param multiline_commands: list of commands allowed to accept multi-line input :param terminators: list of characters that terminate a command. These are mainly intended for terminating multiline commands, but will also terminate single-line commands. If not supplied, the default is a semicolon. If your app only contains single-line commands and you want terminators to be treated as literals by the parser, then set this to an empty list. :param shortcuts: dictionary containing shortcuts for commands. If not supplied, then defaults to constants.DEFAULT_SHORTCUTS. If you do not want any shortcuts, pass an empty dictionary. :param command_sets: Provide CommandSet instances to load during cmd2 initialization. This allows CommandSets with custom constructor parameters to be loaded. This also allows the a set of CommandSets to be provided when `auto_load_commands` is set to False :param auto_load_commands: If True, cmd2 will check for all subclasses of `CommandSet` that are currently loaded by Python and automatically instantiate and register all commands. If False, CommandSets must be manually installed with `register_command_set`. :param allow_clipboard: If False, cmd2 will disable clipboard interactions :param suggest_similar_command: If ``True``, ``cmd2`` will attempt to suggest the most similar command when the user types a command that does not exist. Default: ``False``. do_pyNdo_ipy)rrrFT2z> eof_relative_run_scriptrTrjapp)rrrzKDocumented commands (use 'help -v' for verbose/'help ' for details):z No help on {}z0{} is not a recognized command, alias, or macro.z run_script  -tz--test store_truez1Test against transcript(s) in FILE (wildcards OK)actionhelpwinmorez less -RXFz less -SRXFr UncategorizedInvalid command name '': zDid you mean {}?)esetattr_initialize_plugin_systemsuperr[default_to_shellralways_show_hintdebugechorrDEFAULT_EDITOReditorfeedback_to_outputquietscripts_add_to_historytimingmax_completion_items _settables_always_prefix_settablesset_installed_command_sets_cmd_to_command_setsbuild_settablescontinuation_prompt self_in_pyhidden_commandsr_persistent_history_length_initialize_historyexclude_from_historymacros _py_historypy_bridge_name py_locals_in_pyr7statement_parser last_result _script_dirr ContextFlagsigint_protection_cur_pipe_proc_reader _redirecting_at_continuation_prompt_multiline_in_progress doc_header help_error default_errorbroken_pipe_warning_startup_commandsospathabspath expanduserexists quote_stringrREDIRECTION_OUTPUTdevnullappend_transcript_filesrDEFAULT_ARGUMENT_PARSER add_argumentparse_known_argstestextendsysplatformrpager pager_chopr exit_code threadingRLock terminal_lockdisabled_commandsdefault_categoryALPHABETICAL_SORT_KEYdefault_sort_keyallow_appended_spaceallow_closing_quotecompletion_hintformatted_completionscompletion_matchesdisplay_matchesmatches_delimitedmatches_sortedrt_command_parsers_register_subcommandsregister_command_set_autoload_commandsget_all_commandsis_valid_command ValueErrorrdefault_suggestion_messagecurrent_command)rYrrrrrrrrrrrrrrrrrrr script_cmdrcalloptscallargs command_setcur_cmdvaliderrmsg __class__s rZr[z Cmd.__init__.s4T ) D'4 ( ( ( * D(D ) ) ) &&((( [fMMM!&!2!&  ( "' &*# *,!02.3%9<$;=! )-  !&'=>(*$*C'   !8999&+I$6!)+ ')$*, 1@#8JV_2 2 2  !%')5:4E4G4GBF""(-$')#h*P$& -/  :W__RW-?-?-O-OPPNw~~n-- :O5+=n+M+MOO )R"Qi&B"Q"QRZ"Q"QQJ&--j9997;  6$<>>F   h|J}  ~ ~ ~!'!8!8!:!: Hh} 8)1&& 8&--h777  6%5D " < " "5 ) ) ++1 1DJ%DJ*DO / '_.. >@!07:6O%)!$( %'+-".0+-"' %*2A1F1F ""4(((  7+ 7 7 ))+6666  &  # # % % %,,.. P PG 1BB7KKME6 P !N'!N!Nf!N!NOOO P(?$*<'59r\)subclass_matchcommandset_typer c.fd|jDS)aFind all CommandSets that match the provided CommandSet type. By default, locates a CommandSet that is an exact type match but may optionally return all CommandSets that are sub-classes of the provided type :param commandset_type: CommandSet sub-class type to search for :param subclass_match: If True, return all sub-classes of provided type, otherwise only search for exact match :return: Matching CommandSets c^g|])}t|kst|'|*Src)type isinstance).0cmdsetr!r s rZ z(Cmd.find_commandsets..sJ   F||..>.jQWYhFiFi. ...r\)r)rYr!r s ``rZfind_commandsetszCmd.find_commandsetsws7     6    r\ command_namec6|j|S)zFind the CommandSet that registered the command name. :param command_name: command name to search :return: CommandSet that provided the command )rr)rYr*s rZrzCmd.find_commandset_for_commands (,,\:::r\ctj}djDdtttddffd |dS)z!Load modular command definitions.c,g|]}t|Srcr$r&rs rZr(z*Cmd._autoload_commands.. $g$g$g;T+%6%6$g$g$gr\commandset_typesrRNc|D]}|}|r |$tj|j}|vs@t |jdks(d|jvs|}|dS)NrrY)__subclasses__inspect signaturer[r parametersr)r1 cmdset_type subclassesinit_sigr'existing_commandset_typesload_commandset_by_typerYs rZr;z7Cmd._autoload_commands..load_commandset_by_types/ : : (7799  :++J7777&01EFFH#'@@@x233q88!)<<.r0r\z CommandSet z is already installedz,CommandSet settable prefix must not be emptyr{Duplicate settable: zDuplicate settable z is already registered.ct|to.t|do|jt SNr_r%rrr_rr#meths rZz*Cmd.register_command_set..@z$'A'A(BD*--(BM,,-@AAr\ predicateNc$i|] \}}|u || Srcrc)r&keyvalr's rZ z,Cmd.register_command_set..s+,},},}(#sknv|k|k|S#k|k|k|r\)+rr$r*r_ settablesalways_prefix_settablessettable_prefixstrip on_registerrr<tuplerrr r4 getmembersrr"rr#_install_command_functionrr$_install_completer_functionr%_install_help_functionrrrCMD_ATTR_HELP_CATEGORYr categorizeaddr on_registered Exception on_unregisterdelattrrvaluesitemson_unregistered)rYr'r: all_settablesrK prefixed_namemethodsrinstalled_attributes cmd_func_nameryrcompleter_func_name cmd_completerhelp_func_namecmd_helpattribs ` rZrzCmd.register_command_sets %h$g$Jf$g$g$g! <<4 4 4-md6ll>S.SVm.mnn n  ' i)//11 b12`aaa' T T#)#9 A AC A A  M1156RS6R6RSSS2 T ' i i-''56gC6g6g6ghhh( 4    sHS#X../ 0  BB     #6+KTRR!% 18 G G- ~',?(@(@(B(BC..}ndSYllNcddd$++M:::&;g&E# '0CT J J  ,44WmLLL(//0CDDD!1G!;"6>4@@'//BBB(//???5;)'2#GGNIDd,e,eG$^5EFFF  ( , ,V 4 4 4  & &v . . .  " " " " "     " " ". & &f%%%%555,33F;;;299;;;;,},},},}dF_FeFeFgFg,},},})  " " $ $ $  sE2KB1M6rrprogct|tr|}nt|tr||j}nht |r |}nNt|t jrtj |}ntdt|ddl m }||||S)aBuild argument parser for a command/subcommand. :param parent: CommandParent object which owns the command using the parser. When parser_builder is a classmethod, this function passes parent's class to it. :param parser_builder: means used to build the parser :param prog: prog value to set in new parser :return: new parser :raises TypeError: if parser_builder is invalid type z!Invalid type for parser_builder: r)_set_parser_prog)r%r__func__ classmethodrcallablerrcopydeepcopy TypeErrorr$ decoratorsrn)rYrrrlrrns rZrzCmd._build_parsers* nl 3 3 X#,,..FF  4 4 X#,,V-=>>FF n % % X#^%%FF (? @ @ X]>22FFV^@T@TVVWW W000000&&& r\command_func_namerycontextc|tst|dtd|jtst|jdtd|t td}t ||rtd|d|d|j|\}}|std|d|||jvr!| d |d |j|=||j vr!| d |d |j |=t|||dS) aeInstall a new command function into the CLI. :param command_func_name: name of command function to add This points to the command method and may differ from the method's name if it's being used as a synonym. (e.g. do_exit = do_quit) :param command_method: the actual command method which runs when the command function is called :param context: optional info to provide in error message. (e.g. class this function belongs to) :raises CommandSetRegistrationError: if the command function fails to install z does not begin with ''NAttribute already exists: z ()rrzDeleting alias 'z/' because it shares its name with a new commandzDeleting macro ') rr#r*r_rrrraliasespwarningrr)rYrvryrwrrrs rZrUzCmd._install_command_functions!++,?@@ r-1B.p.pZm.p.p.pqq q&112EFF x-1H.v.v`s.v.v.vww w#C(;$<$<$>$>? 4* + + l-.jK\.j.j`g.j.j.jkk k->>wGG v ]-.[w.[.[SY.[.[\\ \ dl " " MMeWeee f f f W% dk ! ! MMeWeee f f f G$'88888r\cmd_namerhct|z}t||rtd|t|||dSNrz)r$rr*r)rYr~rhrgs rZrVzCmd._install_completer_functionAsR3h> 4, - - b-.`K^.`.`aa a)=99999r\rj).Nct|z}t||rtd|t|||dSr)r%rr*r)rYr~rjris rZrWzCmd._install_help_functionHsN)H4 4 ( ( ]-.[>.[.[\\ \nh/////r\c||jvrm|||||t j|d}|D]\}}|t td}||jvr| |||j vr|j |=||j kr|j |t|t|zrt!|t|zt|t"|zrt!|t"|zt!||||j |dSdS)zuUninstalls a CommandSet and unloads all associated commands. :param cmdset: CommandSet to uninstall ct|to.t|do|jt SrBrCrDs rZrFz,Cmd.unregister_command_set..[rGr\rHN)r_check_uninstallabler]_unregister_subcommandsr4rTrr#renable_commandrr_rrrr$r^r%ra)rYr'rdrfryrs rZunregister_command_setzCmd.unregister_command_setOs T1 1 1  % %f - - -  " " "  ( ( 0 0 0D"2W"<===m,,,,  " " $ $ $  ( / / 7 7 7 7 7I 2 1r\cdtjddffd tjd}|D]7\}}||jkr'|j|}| |8dS)NrrRc|jD]v}t|tjrZ|jD]=}t |tjd}||urtd|>dSwdS)NzACannot uninstall CommandSet when another CommandSet depends on it) _actionsr%r_SubParsersActionchoicesr_rrPARSER_ATTR_COMMANDSETr*)rr subparserattached_cmdsetcheck_parser_uninstallabler's rZrz.check_parser_uninstallable{s /  fh&@AA%+^%:%:%<%<>> *1)Y=]_c*d*d*6?RX;X;X"= c##329====EE  r\ct|to.t|do|jt SrBrCrDs rZrFz*Cmd._check_uninstallable..s>:dH#=#=$>j))$> (()<==r\rH)rrr4rTr_rr)rYr'rdrfrycommand_parserrs ` @rZrzCmd._check_uninstallablezs x/F 4       9@8J >>9 9 9 .5 ? ? )M> 777!%!6!:!:>!J!J!-..~>>>  ? ?r\c||us||jvstdtj|d}|D]\}}t |t j}t |t j}t |t j}|j |d\}} |std|d| | } | d} | d d } | |j vr|j | j } n|| } | td | d ||j| }|td | d |dt"jdt&t(dt"jffd || }|||| d|}|j |jrt1|j|_|jD]}t5|t"jrt |t ji}|g|d<|j|d<|j|d<|j|d<|j|d<|j |d<|j!|d<|j"|d<|j#|d<|j$|d<|j%|d<d|d<|j&|fi|}t j'|i}|j(d i||)|*tW|t j,|nd S)!zRegister subcommands with their base command. :param cmdset: CommandSet or cmd2.Cmd subclass containing subcommands z;Cannot register subcommands with an unregistered CommandSetct|toMt|tjo3t|tjot|tjSrgr%rrrSUBCMD_ATTR_NAMESUBCMD_ATTR_COMMANDrrDs rZrFz+Cmd._register_subcommands..T:dH#=#=$<i899$<i;<<$<i:;;r\rHT) is_subcommandz Subcommand z is not valid: rrNCould not find command '' needed by subcommand: &Could not find argparser for command 'r subcmd_namesrRc|s|S|d}|jD]S}t|tjr7|jD]\}}||kr||ccSnTtd|d)NrzCould not find subcommand 'ry)poprr%rrrr`r*)rr cur_subcmd sub_action choice_namechoicefind_subcommands rZrz2Cmd._register_subcommands..find_subcommands#"!M)--a00 "(/J!*h.HII3=3E3K3K3M3MMM/K*j88'6v|'L'L L L L L L 9  22YPV2Y2Y2YZZZr\rparentsrlusagerepilogformatter_class prefix_charsfromfile_prefix_charsargument_defaultconflict_handler allow_abbrevFadd_helprc)-rr*r4rTrrrrrrrsplitrrocmd_funcrrrrr<rrrrbrJrr%rSUBCMD_ATTR_ADD_PARSER_KWARGSrlrrrrrrrr add_parserNS_ATTR_SUBCMD_HANDLER set_defaultsset_ap_completer_typeget_ap_completer_typerr)rYr'rd _method_namemethodsubcommand_namefull_command_namesubcmd_parser_buildersubcommand_validrcommand_tokensr*subcommand_names command_funcr target_parser subcmd_parserradd_parser_kwargsattached_parserdefaultsrs @rZrzCmd._register_subcommandss $&D,H"H"H-.kll l$ <<   %,Q Q  L&#*693M#N#NO%,VY5R%S%S $+FI4P$Q$Q !'+'<'M'Momq'M'r'r $ f# l12j2j2jbh2j2jkkk.4466N)!,L-abb1 t555#5lCT #}}\:: #12}\2}2}sy2}2}~~~!266|DDN%1m\mmcimm [(? [tTWy []e]t [ [ [ [ [ [,ON0B%f-1>1D%g.7D7P%m42?2F%h/;H;X%&788E8R%n5ANAd%&=>.rr\rHNrrr)rr*r4rTrrrrrrorrrrr%rr remove_parser) rYr'rdrrrr*rrrs rZrzCmd._unregister_subcommandssz $&D,H"H"H-.mnn n$ <<   %,   L&%fi.HIIO"69+HIILt555#5lCT #}}\:: #22}\2}2}sy2}2}~~~!266|DDN%2m\mmcimm)1  fh&@AA((999E/  r\c|jS)zFlags whether CommandSet settable values should always be prefixed. :return: True if CommandSet settable values will always be prefixed. False if not. )rrXs rZrOzCmd.always_prefix_settables(s ,,r\ new_valuec|js0|r.|jD]&}|jstd|jjd'||_dS)aSet whether CommandSet settable values should always be prefixed. :param new_value: True if CommandSet settable values should always be prefixed. False if not. :raises ValueError: If a registered CommandSet does not have a defined prefix z+Cannot force settable prefixes. CommandSet z) does not have a settable prefix defined.N)rrrPrrr_)rYrcmd_sets rZrOzCmd.always_prefix_settables0sv,  7  .$?gFWF`??? )2%%%r\ct|j}|jD]?}|j}|D]!\}}|jr|||jd|<|||<"@|S)zGet all available user-settable attributes. This includes settables defined in installed CommandSets. :return: Mapping from attribute-name to Settable of all user-settable attributes from r{)dictrrrNr`rOrP)rYrbrcmdset_settables settable_namesettables rZrNz Cmd.settables@s T_-- 3 < .get_allow_style_choices..is$@@@CHNN$$@@@r\)r AllowStyle)rs rZget_allow_style_choicesz4Cmd.build_settables..get_allow_style_choicesgs@@@@@ @r\valuec  tj|S#t$rL}t dtjjdtjjdtjjd|d}~wwxYw)z/Convert a string value into an ansi.AllowStyle.zmust be , z, or z (case-insensitive)N)rrupperrrALWAYSNEVERTERMINAL)rescs rZallow_style_typez-Cmd.build_settables..allow_style_typeks u{{}}55    Et5EE9NEE/EEE s#& A<AA77A< allow_stylez9Allow ANSI text style sequences in output (valid values: rr{)choices_providerrzBDisplay tab completion hint even when completion suggestions printrz Show full traceback on exceptionrzEcho command issued into outputrzProgram used by 'edit'rz)Include nonessentials in '|', '>' resultsrzBMaximum number of CompletionItems to display during tab completionrz!Don't print nonessential feedbackrz-Scripts and pyscripts add commands to historyrzReport execution timesN)rrr<rrrrrGrrrrrrint)rYrrs rZrzCmd.build_settablesds> As AtCy A A A A C DO       b?)bb-1_-BbbFJoF^bbb!%&9;R!S!S       '/suy z z    (7D2TVZ[[\\\ (641RTXYYZZZ (8S2JDQQRRR (#7?jlpqqrrr  +S2vx| } }    (7D2UW[\\]]] (#;TCrtxyyzzz (8T3KTRRSSSSSr\ctjS)zFRead-only property needed to support do_set when it reads allow_style.rrrXs rZrzCmd.allow_styles r\new_valc|t_dS)zESetter property needed to support do_set when it updates allow_style.Nr)rYrs rZrzCmd.allow_styles#r\cb|jo(t|jottjkS)z+Return whether tab completion is supported.) use_rawinputrrrBr;NONErXs rZ_completion_supportedzCmd._completion_supporteds' VT$*:%;%;V6;@VVr\c4tj|jS)a8Read-only property to get the visible prompt with any ANSI style escape codes stripped. Used by transcript testing to make it easier and more reliable when users are doing things like coloring the prompt using ANSI color codes. :return: prompt stripped of any ANSI escape codes )r strip_stylepromptrXs rZvisible_promptzCmd.visible_prompts ,,,r\ endstyledestmsgrrc| ||n|} tj|||dS#t$r2|jr'tj|jYdSYdSwxYw)a8Print message to a given file object. :param dest: the file object being written to :param msg: object to print :param end: string appended after the end of the message, default a newline :param style: optional style function to format msg with (e.g. ansi.style_success) N)rstyle_aware_writeBrokenPipeErrorrrstderrwrite)rYrrrr final_msgs rZprint_toz Cmd.print_tos#("3EE#JJJ  ;  "4I)>>        ! ! ! c9 % % !`d3ii.@``[^``IICI  4(33Iz 5g77_G +G44 4I I3E :::::r\c|js:|jr|||dS|||ddSdS)a Print nonessential feedback. Can be silenced with `quiet`. Inclusion in redirected output is controlled by `feedback_to_output`. :param msg: object to print :param end: string appended after the end of the message, default a newline rFr N)rrrr rs rZ pfeedbackz Cmd.pfeedbacks]z =& = Sc ***** CSe <<<<<  = =r\)rchoprczd}|jrY|jr@tjdst jdd}|r,|j s$| s| s||}tj tjjkrtj|}|j}|r|j} |j5ddl}||d|j|j}||dd ddddS#1swxYwYdS#t2$r2|jr'tj|jYdSYdSwxYw||| dS) a'Print output using a pager if it would go off screen and stdout isn't currently being redirected. Never uses a pager inside a script (Python or text) or when output is being redirected or piped or when stdout or stdin are not a fully functional terminal. :param msg: object to print :param end: string appended after the end of the message, default a newline :param chop: True -> causes lines longer than the screen width to be chopped (truncated) rather than wrapped - truncated text is still accessible by scrolling with the right & left arrow keys - chopping is ideal for displaying wide tabular data as is done in utilities like pgcli False -> causes lines longer than the screen width to wrap to the next line - wrapping is ideal when you want to keep users from having to use horizontal scrolling WARNING: On Windows, the text always wraps regardless of what the chop argument is set to FrTERMNTr)shellrrutf-8replacer)risattyrrrrrenvironrr in_pyscript in_scriptrrrrrrrr subprocessPopenPIPE communicateencoderrrrr) rYrrrfunctional_terminalrrr% pipe_procs rZppagedz Cmd.ppageds:$$ :     +4;#5#5#7#7 +|&&u-- +1G1G1S&*#  't'8 'AQAQASAS '\`\j\j\l\l '  I4?#888 ,Y77 JE ( ?+PP%%%% * 0 0d*/bfbm 0 n nI)))*:*:7I*N*NOOO PPPPPPPPPPPPPPPPPP # ? ? ?+?J$$T%=>>>>>>???  ? LL#L & & & & &s73E%:AE E%EE%E E%%5F! F!P)indentwidthdepthrdatar/r0r1c j||jtj|||||dS)a,Pretty print arbitrary Python data structures to self.stdout and appends a newline by default. :param data: object to print :param indent: the amount of indentation added for each nesting level :param width: the desired maximum number of characters per line in the output, a best effort will be made for long data :param depth: the number of nesting levels which may be printed, if data is too deep, the next level replaced by ... :param end: string appended after the end of the message, default a newline rN)rrpprintpformat)rYr2r/r0r1rs rZpprettyz Cmd.pprettyEs5 dk6>$u#M#MSV WWWWWr\c:d|_d|_d|_d|_g|_g|_d|_d|_ttj krtj |j dSttjkr|jtjj_dSdS)zkReset tab completion settings. Needs to be called each time readline runs tab completion. TrTFN)rrr r r r r rrBr;GNUrL#set_completion_display_matches_hook_display_matches_gnu_readline PYREADLINE_display_matches_pyreadlinerlmode_display_completionsrXs rZ_reset_completion_defaultszCmd._reset_completion_defaultsRs %)!#' !%'""$!!&# fj  89[ \ \ \ \ \ ) ) )484THK  1 1 1* )r\linebegidxendidxcddl}d}|jtj}|d|}|} t|d|} |s||kr| dn]#t $rO} t | dkr)|r'|d}|dd}|d|}||z }|dz}n ggfcYd} ~ SYd} ~ nd} ~ wwxYw|j| } d| D} |r| ddd| d<| | fS) aeGet all tokens through the one being completed, used by tab completion functions. :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :return: A 2 item tuple where the items are **On Success** - tokens: list of unquoted tokens - this is generally the list needed for tab completion functions - raw_tokens: list of tokens with any quotes preserved = this can be used to know if a token was quoted or is missing a closing quote Both lists are guaranteed to have at least 1 item. The last item in both lists is the token being tab completed **On Failure** - Two empty lists rNrTTzNo closing quotationrc6g|]}tj|Src)r strip_quotes)r& cur_tokens rZr(z-Cmd.tokens_for_completion..s#LLLI%$Y//LLLr\) rrrQUOTESr8rrrrsplit_on_punctuation) rYrArBrCrrunclosed_quote quotes_to_trytmp_line tmp_endidxinitial_tokensex raw_tokenstokenss rZtokens_for_completionzCmd.tokens_for_completionesu  ! )"233 =  " "!,Xkzk-B!C!C&.&J*>*>"))"--- " " "r774444%21%5N$1!""$5M#GVG}H.H!'!JJr6MMMMMM JJJJ " "4*??OO MLLLL  1'^CRC0JrNz!!s4A$$ B=.?B8-B=8B=text match_againstc fd|DS)atTab completion function that matches against a list of strings without considering line contents or cursor position. The args required by this function are defined in the header of Python's cmd.py. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param match_against: the strings being matched against :return: a list of possible tab completions c>g|]}||Src)r)r& cur_matchrTs rZr(z&Cmd.basic_complete..s-WWWiI|S)aPerform tab completion against a list but each match is split on a delimiter. Only the portion of the match being tab completed is shown as the completion suggestions. This is useful if you match against strings that are hierarchical in nature and have a common delimiter. An easy way to illustrate this concept is path completion since paths are just directories/files delimited by a slash. If you are tab completing items in /home/user you don't get the following as suggestions: /home/user/file.txt /home/user/program.c /home/user/maps/ /home/user/cmd2.py Instead you are shown: file.txt program.c maps/ cmd2.py For a large set of data, this can be visually more pleasing and easier to search. Another example would be strings formatted with the following syntax: company::department::name In this case the delimiter would be :: and the user could easily narrow down what they are looking for if they were only shown suggestions in the category they are at in the string. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param match_against: the list being matched against :param delimiter: what delimits each portion of the matches (ex: paths are delimited by a slash) :return: a list of possible tab completions Trr) rYr rr commonprefixrrr r)rYrTrArBrCrUrZmatches common_prefix prefix_tokensdisplay_token_indexrX match_tokens display_tokens rZdelimiter_completezCmd.delimiter_completesR%%dD&&-PP  ;%)D "G0099M)// ::M#$  =&)-&8&81&<#% ; ; (y99 ,-@ A $.$-M$++M::::r\)all_else flag_dictrdc0||||\}}|sgSg} |} t|dkr|d} | |vr|| } t| tr|||||| } nt | r| ||||} | S)a Tab completes based on a particular flag preceding the token being completed. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param flag_dict: dictionary whose structure is the following: `keys` - flags (ex: -c, --create) that result in tab completion for the next argument in the command line `values` - there are two types of values: 1. iterable list of strings to match against (dictionaries, lists, etc.) 2. function that performs tab completion (ex: path_complete) :param all_else: an optional parameter for tab completing any token that isn't preceded by a flag in flag_dict :return: a list of possible tab completions r)rSrr%rrYrq) rYrTrArBrCrerdrR_completions_matchesrUflags rZflag_based_completezCmd.flag_based_completes4..tVVDD  I   v;;??":Dy  )$  mX . . L"&"5"5dD&&R_"`"`  m $ $ L"/-dFF"K"K ""r\ index_dictc.||||\}}|sgSg} t|dz } || |} t| tr|||||| } nt | r| ||||} | S)aTab completes based on a fixed position in the input string. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param index_dict: dictionary whose structure is the following: `keys` - 0-based token indexes into command line that determine which tokens perform tab completion `values` - there are two types of values: 1. iterable list of strings to match against (dictionaries, lists, etc.) 2. function that performs tab completion (ex: path_complete) :param all_else: an optional parameter for tab completing any token that isn't at an index in index_dict :return: a list of possible tab completions r)rSrrr%rrYrq) rYrTrArBrCrlrdrRrhr]indexrUs rZindex_based_completezCmd.index_based_complete/s4..tVVDD  IF a#uh77  mX . . @))$ffmTTGGm $ $ @#mD$??Gr\ path_filterrqcdttffd }d|t|ks.|t|kr||tjjkrdtj}d}dds4tjtjd} d}nddg} | D] } | vrgcS dz} dr~ tjjd } | d kr |Stj | } d | tj nRtj s3tjtj| } d}tj | } fd | D} | rkd_ t| d kr3tj| d rd_d_| jd_t)| D]\}}jtj|tj|rErC| |xxtjjz cc<j|xxtjjz cc<|r9|tjjkr|n|tjjzfd| D} rfd| D} | S)aPerform completion of local file system paths. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param path_filter: optional filter function that determines if a path belongs in the results this function takes a path as its argument and returns True if the path should be kept in the results :return: a list of possible tab completions rRcTg}tjdrltj}tj|r-}r|tjjz }||nddl }| D]p}tj|j rJd|j z}|r+r|tjjz }||q|rd_ d_|S)Nrr~F)rrrrrrisdirseprpwdgetpwallpw_dirpw_namerr) users expanded_pathuserrwcur_pwcur_useradd_trailing_sep_if_dirrYrTs rZcomplete_usersz)Cmd.path_complete..complete_usersvsE |&&u-- 3 " 2 24 8 8 7==//'D., +LL&&& "llnn33Fw}}V]333#&#7#..t44368 (BGK 7!LL222 1-2)+0(Lr\FTrT*?rtrrHNc*g|]}| |Srcrc)r&crqs rZr(z%Cmd.path_complete..s&<<g|]}|ddSrTrr )r&cur_path to_replaces rZr(z%Cmd.path_complete..s+WWW88++JA>>WWWr\c>g|]}|dS)rr)r&rexpanded_tilde_pathorig_tilde_paths rZr(z%Cmd.path_complete..s.mmmYa8++,?RSTTmmmr\)r<rrrrrvgetcwdjoinrfindrdirnameglobr rurrsortrr enumerater rbasename)rYrTrArBrCrqrcwd cwd_added search_str wildcardswildcard sep_indexr]rnrXrrrrs`` ` @@@@rZ path_completezCmd.path_complete`sw,! S ! ! ! ! ! ! ! ! H#( SYY  6CII#5#5$v,"'+:U:U&* #ikk   !bikk377JIIc I%  t##III$Js## ! IIbgk155 ??)>+++ W// ;; #'z z"2&(g&8&8&I&I##W__T** !W\\")++zBB  )J''  "<<<<'<<%> ,1)+0( LLT2L 3 3 3"&D %.g$6$6 ? ? y$++BG,<,/// X$'27;$6$6SSC"'+.s,tATATApXZXabfhjhoXpXpr\rp)rrrrvrget_exes_in_pathr)rYrTrArBrCrs rZshell_cmd_completezCmd.shell_cmd_completes{ d Is## 0 4(?(?)$// /!! $4p4p"   r\compfuncc2||||\}}|sgSt|dkrd}d} d} d} d} d} |D]}|tjvrDd}|tjkr| tjkrgcSd} d} nU| tjvs| rgcSd} d} n<|jr5d} d} | tjkrd} n| s| tjtjfvrd} |} | r|||||S| r| ||||S|rgS|||||S)aFirst tab completion function for all commands, called by complete(). It determines if it should tab complete for redirection (|, >, >>) or use the completer function for the current command. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param compfunc: the completer function for the current command this will be called if we aren't completing for redirection :return: a list of possible tab completions rFNT) rSrrREDIRECTION_TOKENSREDIRECTION_PIPErrREDIRECTION_APPENDrr)rYrTrArBrCrrhrQhas_redirectionin_pipe in_file_redirdo_shell_completiondo_path_completion prior_tokenrGs rZ_redirect_completezCmd._redirect_complete s 224HH : I z??Q  #OG!M"' !& K'! (! (  <<<&*O!I$>>>&)*DDD#%III"&(- ')*FFF-F#%III"'(, +2*/').&"i&@@@.2++ 2KI4PR[Rn3o$o$o-1*' " K..tT66JJJ! F))$ffEEE  xdFF333r\matches_to_displaycttjkrdnttjkrdn|dfSfd|Dt fS)a}Add padding to the matches being displayed as tab completion suggestions. The default padding of readline/pyreadine is small and not visually appealing especially if matches have spaces. It appears very squished together. :param matches_to_display: the matches being padded :return: the padded matches and length of padding that was added  z rcg|]}|zSrcrc)r&rXpaddings rZr(z/Cmd._pad_matches_to_display..osHHH G#HHHr\)rBr;r8r;r)rrs @rZ_pad_matches_to_displayzCmd._pad_matches_to_displayZsa fj GG ) ) )GG&q( (HHHH5GHHH#g,,VVr\ substitutionr]longest_match_lengthc bttjkrd}|jr0|jr)d}t jd|jz|jrL|st jdt jd|jzdzn|j r3|j }d}|D]&}tj |}t||}'n|}| |\}}||z }t|d} d|D} tt t"tt%jd t)| zd zz} | | d<| | d d <d | d <t+j| t)| |t/d Sd S) aPrint a match list using GNU readline's rl_display_match_list(). :param substitution: the substitution written to the command line :param matches: the tab completion matches to display :param longest_match_length: longest printed length of the matches FTr rrencodingc0g|]}t|dS)rr)bytes)r&rXs rZr(z5Cmd._display_matches_gnu_readline..s%"j"j"j)5W#E#E#E"j"j"jr\rrHN)rBr;r8rr rrrr r rstyle_aware_wcswidthmaxrrrr<rctypesc_char_prrNrl_display_match_listrM) rYrr]r hint_printedrrX cur_lengthpadding_lengthencoded_substitutionencoded_matches strings_arrays rZr:z!Cmd._display_matches_gnu_readlineqs fj  L$ >)= >#    (y%I%I /23G/T/T,,U*1&6:5Q5QRd5e5e2"N$6$(-\G'L'L'L$"j"jWi"j"j"j!%T(5/%:V_PQTWXgThThPhklPl=mconsolerr rMr rorig_pyreadline_display)rYr]rrrhs rZr<zCmd._display_matches_pyreadlines f' ' ' L$ L)= L#   (..td6J/JKKK) <#9K$,224888  (..td6P/PSY/YZZZ#$$$$$ >B=Q%^T%9%9W^")-(D(DEW(X(X%"A((:;;;;;3 ( 'r\rctttj}|}| tj}|S)aDetermine what type of ArgparseCompleter to use on a given parser. If the parser does not have one set, then use argparse_completer.DEFAULT_AP_COMPLETER. :param parser: the parser to examine :return: type of ArgparseCompleter )rr$rArgparseCompleterrDEFAULT_AP_COMPLETER)r Completercompleter_types rZ_determine_ap_completer_typez Cmd._determine_ap_completer_types<T"4"FGH $*$@$@$B$B  !/DNr\custom_settingsc6 d}||j|}|j}|sdS|j}|dds9t |t |z } |d| zz }t |t |kr)t |t |z } || z }|| z }|}||||\} } | sdS|9||jvr |j } nw|| vrt|tj |zd}||} n=||}|dn|j|}||t|tj}||}||}|||}t)j|j|r | ddn | dd|} n|j} n}|jr|t3j|vr|j } nX|j} nP||j}||j|}t)j|j|jr| n| d} d| d}d|rV|dtjvrB|d|d|| d}||kr||||z}|}|||||| |_ |j rt3j!|j |_ t3j!|j"|_"|j"sddl#}|j#|j |_"sd}tHj%&|j }|j'rKtHj%&|j"}d|vs |r tQd |j"Drd }n"|r tQd |j Drd }|r:tQd |j Drd ndfd|j D|_ nrfd|j D|_ t |j dkr"|j)rr|j dxxz cc<dSdSdSdSdS)aPerform the actual completion, helper function for complete(). :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix text :param endidx: the ending index of the prefix text :param custom_settings: optional prepopulated completion settings rTNrHrr)rRrrFc3K|]}d|vV dSrNrcr&matchs rZ z*Cmd._perform_completion..{s'FvFvX]se|FvFvFvFvFvFvr\Tc3K|]}d|vV dSrrcrs rZrz*Cmd._perform_completion..s&*]*]E3%<*]*]*]*]*]*]r\c3K|]}d|vV dS)"Nrcrs rZrz*Cmd._perform_completion..s&7j7ju 7j7j7j7j7j7jr\ryrcg|]}|zSrcrc)r&rcompletion_token_quotes rZr(z+Cmd._perform_completion..s .s.s.sRW/E/M.s.s.sr\c>g|]}|ddSrr)r&rtext_to_removes rZr(z+Cmd._perform_completion..s**u*u*uTY5==Q+O+O*u*u*ur\)*rparse_command_onlyrcommand_and_argsisspacerrstriprSrrrrrr$rrrCMD_ATTR_PRESERVE_QUOTESrr functoolspartialcompletecompletedefaultrrrrpreserve_quotesrIrfindrr remove_duplicatesr rrrrr\r anyr)rYrTrArBrCrr statement expanded_line rstripped_lendiffrRrQcompleter_func func_attrfunc argparserrrrrUraw_completion_token actual_begidxrr add_quoter^display_prefixrrs @@rZ_perform_completionzCmd._perform_completions  "-@@FFI'G %6M %--// 5 !$D C ,>,> > }!44 =!!SYY..=))CII5$$!D"77ffMM   F  "$+%%!%!3D113333#D)*IG*SUYZZ (%.NN ==11D(, $:O:S:STX:Y:YI'I,A*1$ 8Z*[*["&"B"B7"K"K*.)J)J9)U)U$2N9d$C$C )2):%.7hz!""~~^defegeg^hry****.)=& 67e6LW6U6U+U+U!%!3!%!5 ">>?UVVN&'=tDDI&."9X+d::^dnrN  *"~"$  '$8$;y?O$O$O&:!%< "!&M//r ;;M&&!%mF&:!;&,&#'"9"9$ffVd"e"e  "- E&+&=d>U&V&VD ##(#:4;O#P#PD ' J '0ty1H'I'I$* v! !# 4 4T5L M M ) %%'W%9%9$:N%O%ONm+++3FvFvaeauFvFvFvCvCv+$( #%s*]*]TE\*]*]*]']']% $It477j7jRVRi7j7j7j4j4j-sSSps*.s.s.s.s[_[r.s.s.sD+  v*u*u*u*u]a]t*u*u*u'4*++q00T5M0Rh0'***.DD*****[- E- EX100000r\statec |dkr||jrv|j}|t jz}t |t jz}t |t jz}nt j}|}t |t |z } tt j| z d}tt j| z d}d|dkr||j j D]G\} } | | r-| |t d}|t z }nUHtjd} | ddd| t#j| }||||||rfd |jD|_t |jd kr/|t |kr|jr|jdxxd z cc<|jsG|j|j |j|j d|_ |j|S#t4$rYdSwxYw#t6$rj} t9| }|rN| jrt=j|}t=j tBj"d|zdztGYd} ~ dSd} ~ wtH$rB} |%|&| tGYd} ~ dSd} ~ wwxYw)uHOverride of cmd's complete method which returns the next possible completion for 'text'. This completer function is called by readline as complete(text, state), for state in 0, 1, 2, …, until it returns a non-string value. It should return the next possible completion starting with text. Since readline suppresses any exception raised in completer functions, they can be difficult to debug. Therefore, this function wraps the actual tab completion logic and prints to stderr any exception that occurs before returning control to readline. :param text: the current word that user is typing :param state: non-negative integer :param custom_settings: used when not tab completing the main command line :return: the next possible completion for text or None rrTNFrrCOMMANDzcommand, alias, or macro name)metavarrrcg|]}|zSrcrc)r&rshortcut_to_restores rZr(z Cmd.complete..s.p.p.pu/BU/J.p.p.pr\rrrTr)'r@rrlstriprLget_line_bufferr get_begidx get_endidxrrrrrrr/_get_commands_aliases_and_macros_for_completionrCustomCompletionSettingsrr rrrrr  IndexErrorr+rr rr rrrrMr\r r)rYrTrrlstripped_previousrArBrC orig_line num_strippedshortcutrhrrPerr_strrs @rZrz Cmd.completes"U zz//111/J)-)D)K)K)M)M&-0H0J0JJD!!344x7J7L7LLF !344x7J7L7LLFF!) 8 : :I$++--D#&y>>CII#=L!!4!6!6!EqIIF !4!6!6!EqIIF ')#Q;;?#:'+'<'FQQ !??844"2:/$(,?(@(@(B(B#CD"c*=&>&>>F!E""1!HRW!X!X!X++%$-!@$($X$X$Z$Z , +0*H*P*P((tVV_UUU'q.p.p.p.pX\Xo.p.p.pD+t.//1443t999L9LQUQj9L+A...#5...*/+00T5J0KKK(--$2G-HHH*.D' .u55   tt    "ggG %>8".w77G&sz4'>D3HIII"$$$44444    KKMMM LL     44444  sCJ K$ J11 J?;K>J??K N AL11 N>7M;;Nc|jduS)z(Return whether a text script is running.N)_current_script_dirrXs rZr$z Cmd.in_scripts't33r\c|jS)z9Return whether running inside a Python shell or pyscript.)rrXs rZr#zCmd.in_pyscripts {r\c|jjS)zGRead-only property to access the aliases stored in the StatementParser.)rr|rXs rZr|z Cmd.aliases s$,,r\c t|S)zZReturn an alphabetized list of names comprising the attributes of the cmd2 class instance.)dirrXs rZ get_namesz Cmd.get_names s4yyr\cDfdDS)zReturn a list of all commands.cg|]_}|tj!tt |>|t tjd`Srg)rrr#rqrrr&rrYs rZr(z(Cmd.get_all_commands.. st   y<== CK7SWY]K^K^B_B_ Y23355 6   r\rrXs`rZrzCmd.get_all_commands s8    ((    r\cDfdDS)z@Return a list of commands that have not been hidden or disabled.c8g|]}|jv |jv|Srcrr)r&rrYs rZr(z,Cmd.get_visible_commands.. s>   d222wdF\7\7\ 7\7\7\r\)rrXs`rZget_visible_commandszCmd.get_visible_commands s:    0022    r\Valuer0 divider_charc g}|jD]K}|j|g}|t||j|L|S)z9Return list of alias names and values as CompletionItems.)r|rr_alias_completion_tablegenerate_data_rowrYresultscur_keyrow_datas rZ_get_alias_completion_itemszCmd._get_alias_completion_items s_(*| n nG W-.H NN>'43O3a3abj3k3kll m m m mr\c g}|jD]P}|j|jg}|t||j|Q|S)z9Return list of macro names and values as CompletionItems.)rrrr_macro_completion_tabler#r$s rZ_get_macro_completion_itemszCmd._get_macro_completion_items) sb(*{ n nG G,23H NN>'43O3a3abj3k3kll m m m mr\ Description<c g}|jD]n}|j||j|jg}|t ||j|o|S)zKReturn list of Settable names, values, and descriptions as CompletionItems.)rN get_valuerrr_settable_completion_tabler#r$s rZ_get_settable_completion_itemsz"Cmd._get_settable_completion_items6 sw(*~ q qGw/99;;T^G=T=`aH NN>'43R3d3dem3n3noo p p p pr\ct|}t|j}t|j}t ||z|zS)zJReturn a list of visible commands, aliases, and macros for tab completion.)rrr|rr<)rYvisible_commands alias_names macro_namess rZrz3Cmd._get_commands_aliases_and_macros_for_completion@ sSt88::;;$,'' $+&& ${2[@AAAr\c`fdD}fd|DS)zReturn a list of help topics.cg|]_}|tj!tt |>|t tjd`Srg)rrr%rqrrrs rZr(z'Cmd.get_help_topics..I st   y9:: @HPTVZH[H[?\?\ Y/0022 3   r\c8g|]}|jv |jv|Srcr)r&topicrYs rZr(z'Cmd.get_help_topics..P s5{{{%d>R1R1RW\dhdzWzWzWzWzWzr\r)rY all_topicss` rZget_help_topicszCmd.get_help_topicsG sR    ((   |{{{:{{{{r\signumrhc|j|j|jsWd}|j6||jj}|| }|r|dSdSdS)zSignal handler for SIGINTs which typically come from Ctrl-C events. If you need custom SIGINT behavior, then override this method. :param signum: signal number :param _: the current stack frame or None NT)r send_sigintrrrrsigint_handler_raise_keyboard_interrupt)rYr=rhraise_interruptrs rZr@zCmd.sigint_handlerR s  % 1  & 2 2 4 4 4% 1"O#/">>t?S?[\\ **5*D*D*F*F&FO 1..00000 1 1  1 1r\c4tjd|zdS)a#Signal handler for SIGHUP and SIGTERM. Only runs on Linux and Mac. SIGHUP - received when terminal window is closed SIGTERM - received when this app has been requested to terminate The basic purpose of this method is to call sys.exit() so our exit handler will run and save the persistent history file. If you need more complex behavior like killing threads and performing cleanup, then override this method. :param signum: signal number :param _: the current stack frame or None N)rexit)rYr=rhs rZtermination_signal_handlerzCmd.termination_signal_handlerh s vr\c td)zRaise a KeyboardInterrupt.zGot a keyboard interrupt)KeyboardInterruptrXs rZrAzCmd._raise_keyboard_interruptx s :;;;r\rcNt|tst|n|S)aRan just before the command is executed by [cmd2.Cmd.onecmd][] and after adding it to history (cmd Hook method). :param statement: subclass of str which also contains the parsed input :return: a potentially modified version of the input Statement object See [cmd2.Cmd.register_postparsing_hook][] and [cmd2.Cmd.register_precmd_hook][] for more robust ways to run hooks before the command is executed. See [Hooks](../features/hooks.md) for more information. )r%r6)rYrs rZprecmdz Cmd.precmd| s',6i+K+KZy###QZZr\stopc|S)aRan just after a command is executed by [cmd2.Cmd.onecmd][] (cmd inherited Hook method). :param stop: return `True` to request the command loop terminate :param statement: subclass of str which also contains the parsed input See [cmd2.Cmd.register_postcmd_hook][] and [cmd2.Cmd.register_cmdfinalization_hook][] for more robust ways to run hooks after the command is executed. See [Hooks](../features/hooks.md) for more information. rc)rYrKrs rZpostcmdz Cmd.postcmd s  r\cdS)akRan once when the [cmd2.Cmd.cmdloop][] method is called (cmd inherited Hook method). This method is a stub that does nothing and exists to be overridden by subclasses. See [cmd2.Cmd.register_preloop_hook][] for a more robust wayto run hooks before the command loop begins. See [Hooks](../features/hooks.md) for more information. NrcrXs rZpreloopz Cmd.preloop r\cdS)axRan once when the [cmd2.Cmd.cmdloop][] method is about to return (cmd inherited Hook Method). This method is a stub that does nothing and exists to be overridden by subclasses. See [cmd2.Cmd.register_postloop_hook][] for a more robust way to run hooks after the command loop completes. See [Hooks](../features/hooks.md) for more information. NrcrXs rZpostloopz Cmd.postloop rPr\c^|j|}|j|j|jfS)arParse the line into a command name and a string containing the arguments. NOTE: This is an override of a parent class method. It is only used by other parent class methods. Different from the parent class method, this ignores self.identchars. :param line: line read by readline :return: tuple containing (command, args, line) )rrrargsr)rYrArs rZ parselinez Cmd.parseline s/)<|d|j |j j| z |j5| ||| |r d|j _ dddn #1swxYwYnJ#|j5| ||| |r d|j _ dddw#1swxYwYwxYwn#t2tf$rYnt4$r"}|d |Yd}~nd}~wt8$r}||Yd}~nd}~wt:$r|r|sYnzt<$r2}t?|j tBr |j |_"d}Yd}~nDd}~wtF$r }|j$dd}~wtJ$r}|&|Yd}~nd}~wwxYw |'||}n5#t:$r |r|sYn#t<$r2}t?|j tBr |j |_"d}Yd}~nd}~wtF$r }|j$dd}~wtJ$r}|&|Yd}~nd}~wwxYw# |'||}w#t:$r |r|sYwYwt<$r2}t?|j tBr |j |_"d}Yd}~wd}~wtF$r }|j$dd}~wtJ$r}|&|Yd}~wd}~wwxYwxYw|S) aTop-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks. :param line: command line to run :param add_to_history: If True, then add this command to history. Defaults to True. :param raise_keyboard_interrupt: if True, then KeyboardInterrupt exceptions will be raised if stop isn't already True. This is used when running commands in a loop to be able to stop the whole loop and not just the current command. Defaults to False. :param py_bridge_call: This should only ever be set to True by PyBridge to signify the beginning of an app() call from Python. It is used to enable/disable the storage of the command's stdout. :param orig_rl_history_length: Optional length of the readline history before the current command was typed. This is used to assist in combining multiline readline history entries and is only populated by cmd2. Defaults to None. :return: True if running of commands should stop rNFrY)tzrVz Elapsed: TzInvalid syntax: )(datetime_input_line_to_statementrPostparsingData_postparsing_hooksrKrr-rr pause_storage_redirect_outputnowtimezoneutcPrecommandData _precmd_hooksrJonecmdPostcommandData_postcmd_hooksrMrr_restore_outputr0r)r r/rH SystemExitr%coderrr. wrapped_exr\r_run_cmdfinalization_hooks)rYrArVrWrXrYr^rKrpostparsing_datapostparsing_funcredir_saved_state timestart precmd_data precmd_func postcmd_data postcmd_funcrPs rZonecmd_plus_hookszCmd.onecmd_plus_hooks s0  a !55dSi5jjI &5eYGG $($;   #3#34D#E#E #(E)2I#(D %%$GK , 9+II%:49 1(,(=(=i(H(H% IIIIIIIIIIIIIII%-11X5F5J1KK %3I>> #'#5;;K"-+k":":KK'1 !KK 22 {{9^{LL &5dIFF $($7>>L#/< #=#=LL$(||D)44;nNN#lx/@/D/DHYH]/D/^/^aj/j#l#lmmm+99(4,,Y8IJJJ%948 1 999999999999999T+99(4,,Y8IJJJ%948 1 9999999999999999%n5    D 1 1 1 KK/2// 0 0 0 0 0 0 0 0    KKOOOOOOOO    '     "'3'' )!#DDDDDD# * * *-T )    LL          !66tYGG$   +D   bgs++-%'WDN' . . .m- ! ! ! R         ! !66tYGG$   +D   bgs++-%'WDN' . . .m- ! ! ! R         ! sA#I.H5$B% H%B))H,B)-DH=I'G7+ I7G;;I>G;?II  'H>2 I >I I I I  I O!L9O!! L9*JO! L9J.)O!.L9O! L9 (K83O!8 L9L  L9L4/O!4L99O!=MO' O0(N O*N22 O?OO!R#O:9R:R R R(Q>R RQ R%Q?:R?RRcp|j5tjdsH|jr/ddl}|ddg}|dddn #1swxYwYtj ||}|j D] }||}|j S)z#Run the command finalization hooks.rrNsttysane) rrrrrr!r%r&r(rCommandFinalizationData_cmdfinalization_hooksrK)rYrKrr%procr2rs rZrpzCmd._run_cmdfinalization_hooks3 s  # # #<**511 #dj6G6G6I6I #"!!!!''(899  """ # # # # # # # # # # # # # # #-dI>>/  D4::DDysA(A<<BBrVstop_on_keyboard_interruptcmdsrc2|D]}t|tr|j}|jr||j| ||||rdS`#t$r'}|r||Yd}~n Yd}~d}~wwxYwdS)aRun commands in an automated fashion from sources like text scripts or history replays. The prompt and command line for each command will be printed if echo is True. :param cmds: commands to run :param add_to_history: If True, then add these commands to history. Defaults to True. :param stop_on_keyboard_interrupt: if True, then stop running contents of cmds if Ctrl-C is pressed instead of moving to the next command in the list. This is used when the commands are part of a group, like a text script, which should stop upon Ctrl-C. Defaults to False. :return: True if running of commands should stop rVrWTNF) r%r2rawrrrryrHr )rYrrVrrArPs rZruncmds_plus_hookszCmd.runcmds_plus_hooksE s$  D$ ,, xy 5  3T33444 ))Rl*  44 %   -KKOOOEEEEE  usA## B-BBr[cdtddffd } |j|}|jr |jrn|jsnn2#t $r%|j|}|jsYnwxYw d|_|dz|_| |j }|dkrd}| ||d|z }|r%|j|}||nF#t$r9| d|jd }Yd |_nwxYwd |_n #d |_wxYw<|j st|||S) aKeep accepting lines of input until the command is complete. There is some pretty hacky code here to handle some quirks of self._read_command_line(). It returns a literal 'eof' if the input pipe runs out. We can't refactor it because we need to retain backwards compatibility with the standard library version of cmd. :param line: the line being parsed :param orig_rl_history_length: Optional length of the readline history before the current command was typed. This is used to assist in combining multiline readline history entries and is only populated by cmd2. Defaults to None. :return: the completed Statement :raises Cmd2ShlexError: if a shlex error occurs (e.g. No closing quotation) :raises EmptyStatement: when the resulting Statement is blank rrRNcP|jsdStjkr?tjtjdz tjk?t |}dks|tjkrtj|dSdS)zNCombine all lines of a multiline command into a single readline history entry.Nrr)multiline_commandrLget_current_history_lengthremove_history_itemr3get_history_item add_history)rformatted_commandrYs rZcombine_rl_historyz3Cmd._complete_statement..combine_rl_history{ s%-Y5P-577:PPP,X-P-R-RUV-VWWW577:PPP!39 = = &**.?8C\]sCtCt.t.t$%677777/u.tr\Trr^CrTF)r6rparser terminatorr)rrr_read_command_linerrrHrr-)rYrArYrrnextlines ` rZ_complete_statementzCmd._complete_statementj s" 8) 8 8 8 8 8 8 81 5  177== .93G 2"   !1DDTJJ  2   5/3,/3Tk+ 2243KLLu$$ $HLL***X'2 $ 5 H H N NI&&y111$    T""" 177;; /4,,   05,,u,4444c1 5f  ! 9%%%sA(AA,A65A6:A7C21E29D5+E4D55E E c g}d} |||}| |j}d}|j|jvrD|j|vr;||j||}|t |}nnv||jkrFt|j||j|j |j |j |j |j |j|j }|S)aParse the user's input line and convert it to a Statement, ensuring that all macros are also resolved. :param line: the line being parsed :param orig_rl_history_length: Optional length of the readline history before the current command was typed. This is used to assist in combining multiline readline history entries and is only populated by cmd2. Defaults to None. :return: parsed command line as a Statement :raises Cmd2ShlexError: if a shlex error occurs (e.g. No closing quotation) :raises EmptyStatement: when the resulting Statement is blank NTr[) rrarg_listrrsuffixpipe_tooutput output_to)rrrrr_resolve_macror-r6rTrrrrrrr)rYrArY used_macrosr rresolve_results rZr_zCmd._input_line_to_statement s    00Nd0eeI %M )-& DK//I4E[4X4X""9#4555!%!4!4Y!?!?!)((%% *  % %"!)"+"+"=$/ '!) '#-   Ir\c|j|jvrt|jd|j|j}t|j|jkr9|jdkrdnd}|d|jd|jd|dS|j}t|jd d }|D]{}|j rd |j zd z}d|j zdz}n,d|j zdz}|j t|j }| |d} | d|z| dz}||j|jdD] } |d| zz } ||jzS)zResolve a macro and return the resulting string. :param statement: the parsed statement from the command line :return: the resolved macro or None on error z is not a macrorrTsz The macro 'z' expects at least z argumentNc|jSrg) start_index)mas rZrFz$Cmd._resolve_macro.. sr\T)rKreversez{{z}}{})maxsplitrr)rrrrrminimum_arg_countr rsorted is_escaped number_strargvrrsplit post_command) rYrmacropluralresolvedreverse_arg_list macro_argr replacementpartsstmt_args rZrzCmd._resolve_macro s  DK / /i/@@@AA A I-. y! " "U%< < < 2a77RRSF KKvi&7vvELcvvntvv w w w4;!%.6O6OY]^^^) 9 9I# H!I$884? !I$883>  9#77#= 'nS1E-F-FG OOJO;;EQx+-a8HH"*5+B+D+DE ' 'H h &HH)000r\c Tddl}tjtt|jt j|j|j}d}|j snB|j rtj \}}t|}ttt|d}i} t jdkr |j| d<n+d| d<tjd} | r| | d <|j|j f|t'|jtjr|jn|jt't jtjr|jn t jdd | } t/j|j5| d dddn #1swxYwY| j@||t;d | jd d|_tj| tt|jt j}|xt _|_nQ|j rI|j!r|j tDj#krdnd} ttttj$|j!| d}n"#tJ$r} t;d| d} ~ wwxYwd|_|xt _|_n|j&st;dtO}tttQj)d}d|_|xt _|_|j tDj#kr3|j*||j+||_|j|_|S)a*Set up a command's output redirection for >, >>, and |. :param statement: a parsed statement from the user :return: A bool telling if an error occurred and a utils.RedirectionSavedState object :raises RedirectionError: if an error occurs trying to pipe or redirect rNwwin32 creationflagsTstart_new_sessionSHELL executable)rrrrg?zPipe process exited with code z before command could runar)r> bufferingzFailed to redirect outputzClipboard access not allowedzw+)r>),r%rRedirectionSavedStaterrrrrrrrrpipeopenrCREATE_NEW_PROCESS_GROUPr"rr&r%StdSimr'r contextlibsuppressTimeoutExpiredwait returncodecloser/ redirecting ProcReaderrrrrrFOSErrorrrtempfile TemporaryFilerflush)rYrr%rscmd_pipe_proc_readerread_fdwrite_fd subproc_stdin new_stdoutkwargsrrr>rPcurrent_paste_buffers rZrczCmd._redirect_output! s "7  % %sz43MtO`   <@%V (   R ( " GX!MMM!%fd8S.A.A!B!BJ &(F|w&&*4*M''.2*+ w//1+0F<($:#!#*4T[%,*O*O`zUYU`*4SZ*N*N^zTWT^   D$Z%>??   #               *##%%%  """&'r'r'r'rsss,0  )#(#3D$vt{:S:SUXU_#`#` '1 1CJ  " ("! ((.)2NNNssTWP!%fd53EiFY3Z3Zaeqr.s.s.s!t!tJJPPP*+FGGROP15!-+55 T[[ +K*+IJJJ(8'9'9$!&(*@d*K*K*KLL 04!-+55 T[#y'CCCK%%&:;;;K%%'''&:"-9  s*<FF"%F"->  ' X$B_B_`i`qBrBr-r-> X WD;BBCTUUWW WG G ///tr\cFt||Srg)rKr)rYrs rZrzCmd._suggest_similar_command sw(A(A(C(CDDDr\)rjcompletion_moderrrrUrrrjrrrrrUc  d ddd  f d } d fd } jrtjr t |} j5| dddn #1swxYwYt | } j5| dddn #1swxYwYn+#j5| dddw#1swxYwYwxYwt } jr$tj || dnÉjr_ |dj j } t| d krd } nKj } t| r!jr || nd } | d S) aRead input from appropriate stdin value. Also supports tab completion and up-arrow history while input is being entered. :param prompt: prompt to display to user :param history: optional list of strings to use for up-arrow history. If completion_mode is CompletionMode.COMMANDS and this is None, then cmd2's command list history will be used. The passed in history will not be edited. It is the caller's responsibility to add the returned input to history if desired. Defaults to None. :param completion_mode: tells what type of tab completion to support. Tab completion only works when self.use_rawinput is True and sys.stdin is a terminal. Defaults to CompletionMode.NONE. The following optional settings apply when completion_mode is CompletionMode.CUSTOM: :param preserve_quotes: if True, then quoted tokens will keep their quotes when processed by ArgparseCompleter. This is helpful in cases when you're tab completing flag-like tokens (e.g. -o, --option) and you don't want them to be treated as argparse flags when quoted. Set this to True if you plan on passing the string to argparse with the tokens still quoted. A maximum of one of these should be provided: :param choices: iterable of accepted values for single argument :param choices_provider: function that provides choices for single argument :param completer: tab completion function that provides choices for single argument :param parser: an argument parser which supports the tab completion of multiple arguments :return: the line read from stdin with all trailing new lines removed :raises Exception: any exceptions raised by input() and stdin.readline() FNrRcT sttjkrdSrt j t jjkr'dtdtdttfd}|}nt jj krj }nb /tjd dd  t j }t#jj | }t j|t jj ks ~gt)d t jd zD])}t j|*t j  D]}t j|d dS)z.Configure readline tab completion and history.NrTrrRcdSrgrc)rTrs rZ complete_nonezACmd.read_input..configure_readline..complete_none5 s#tr\FrargT)suppress_tab_hintrrrUr)rr)rBr;rrrL get_completerrCompletionModerrrCOMMANDSrrrrrrr set_completerrangerrr clear_historyr)r complete_funcriitemrrrUrrjrrreadline_configuredsaved_completer saved_historyrYs rZconfigure_readlinez*Cmd.read_input..configure_readline$ s# g&<&<))++ 6"*"8":":#e&:&???$C$$ $$$$%2MM%(<(EEE$(MMM~!0!HRW!X!X!X++!.2$+-=&/ ,',&DV]l&m&m&mO$-$5dmUd$e$e$eM&}555%"6"???7CV " q("E"G"G!"KLLGGA!(()B1)E)EFFFF&(((& '33 ,T2222"&   r\crttjkrdSrt j,t jD]}t j|ddS)z,Restore readline tab completion and history.NF)rBr;rrrLrrr)rrrrrYs rZrestore_readlinez(Cmd.read_input..restore_readline\ s' 'V[*@*@))++ 8&777(&((()//D(...."'   r\rrTrrrz r])rrrr!r<rinputrrrrrrLrr)rYrrjrrrrrUrrrescaped_promptrArrrs` ``````` @@@rZ read_inputzCmd.read_input s6V$37-1 6 '6 '6 '6 '6 '6 '6 '6 '6 '6 '6 '6 '6 '6 '6 '6 'p ( ( ( ( ( ( ( ( ("  # y!! : +%5f%=%=N/--**,,,--------------- 00D/++((***+++++++++++++++/++((***++++++++++++++++ww9:J$$%8%8%8%8999Z     LLRL ( ( ( K     :&&((D4yyA~~ :&&((D4yy 94LLF!2D!2!2333{{6"""sfC' A>2 C>BCBC B66B:=B:C. C" C."C& &C.)C& *C.c tjt5|jdddn #1swxYwY||t jj|j S#t$rY|j dSwxYw#|j wxYw)aRead command line from appropriate stdin. :param prompt: prompt to display to user :return: command line text of 'eof' if an EOFError was caught :raises Exception: whatever exceptions are raised by input() except for EOFError N)rr) rr RuntimeErrorrreleaserrrracquireEOFError)rYrs rZrzCmd._read_command_line s )$\22 - -"**,,, - - - - - - - - - - - - - - -??65;O;X?YY   & & ( ( ( (       & & ( ( ( ( (     & & ( ( ( (sEB A B AB A (B B2B51B22B55Cc$t}ttjkrt jd|rCttjkrMtttjttj j |_ dt_ t j|_t j|jd}|dt&jz }|dt&jz }|d|jjz }t j|_t j|t j|jdz|S)zSet up readline with cmd2-specific settings, called at beginning of command loop. :return: Class containing saved readline settings zset horizontal-scroll-mode offNz rTz : complete)rQrBr;r8rLparse_and_bindrrrrrOc_void_prrWrrUrrrrrIREDIRECTION_CHARSrrget_completer_delimsrVset_completer_delimsr)rYrhcompleter_delimss rZ_set_up_cmd2_readlinezCmd._set_up_cmd2_readline sH 344 fj   #$D E E E  % % ' ' E&*$$ 26eV[Ibdjds=t=t=z1{1{!.26)/*2*@*B*B  '  "4= 1 1 1 '   (8 9 9 9   (C D D D  (=(I J J J '/'D'F'F  $  )*: ; ; ;  #D$4|$C D D D  r\rhcr|rtj|jtj|jt tjkr'tj d|j t_ dSt tj krttjj_dSdSdS)zRestore saved readline settings, called at end of command loop. :param readline_settings: the readline settings to restore N)rrLrrUrrVrBr;r8r9rWrOrr;rr=r>r?)rYrhs rZ_restore_readlinezCmd._restore_readline s  % % ' ' P  "#4#> ? ? ?  )*;*B C C C&*$$" out.txt zname of this alias)rzwhat the alias resolves to)rr command_argszarguments to pass to command)nargsrrUaliascreatecd|_|j|j\}}|s|d|dS|j|vr|ddS|j|jvr|ddStj}| |jj tj |j ||j}|j r |dd|j zz }|j|jvrdnd}|d |jd |||j|j<d |_dS) zCreate or overwrite an alias.FzInvalid alias name: Nz,Alias cannot have the same name as a commandz*Alias cannot have the same name as a macror overwrittencreatedAlias '' T)rrrrr rrrrrrrunquote_specific_tokensr"rrr|r)rYrTrrtokens_to_unquoterresults rZ _alias_createzCmd._alias_create7 sr!->>tyII v  KK7v77 8 8 8 F 9--// / / KKF G G G F 9 # # KKD E E E F&8  !6!BCCC %d&79JKKK    7 S388D$5666 6E#')t|";"; 4ty44F44555"' TYr\zdelete aliasesz8Delete specified aliases or all aliases if --all is used)rz-az--allrzdelete all aliasesrnameszalias(es) to delete)r#rrdescriptive_headerdeletecd|_|jr0|j|ddS|js|dd|_dStj|jD]F}||jvr"|j|=|d|d-|d|dGdS) zDelete aliases.TzAll aliases deletedz/Either --all or alias name(s) must be specifiedFr) ' deleted' does not existN) rallr|rrr/r rrrYrTcur_names rZ _alias_deletezCmd._alias_deletei s  8 F L   LL. / / / / / F KKI J J J$D   !3DJ?? F Ft|++ X.LL!>8!>!>!>????KK D( D D DEEEE  F Fr\z list aliaseszList specified aliases in a reusable form that can be saved to a startup script to preserve aliases across sessions Without arguments, all aliases will be listed.zalias(es) to listr<cri|_tj}||jj|jrtj|jnt|j |j }g}|D]}||j vr| |!t|j |}|d}|dd}tj|||} |r| dd|zz } |d|d| | |j|<|D]}|d|ddS) z4List some or all aliases as 'alias create' commands.rrrNrz alias create r) ' not found)rrrrrrr/rrrr|rrr8quote_specific_tokensrrr  rYrTtokens_to_quoteto_list not_foundrrRrr"rLs rZ _alias_listzCmd._alias_list sm#6t4@AAA9=x%)$*555PTP\bfbwIxIxIx!  ) )D4<''  &&&!d!344FQiG!!"":L  ' o F F FC 4sSXXl3333 LL55555 6 6 6%(D T " " 5 5D KK3$333 4 4 4 4 5 5r\zXManage macros A macro is similar to an alias, but it can contain argument placeholders.zSee also: aliascN|j}||dS)zManage macros.Nrrs rZdo_macroz Cmd.do_macro r!r\zcreate or overwrite a macrozCreate or overwrite a macroaA macro is similar to an alias, but it can contain argument placeholders. Arguments are expressed when creating a macro using {#} notation where {1} means the first argument. The following creates a macro called my_macro that expects two arguments: macro create my_macro make_dinner --meat {1} --veggie {2} When the macro is called, the provided arguments are resolved and the assembled command is run. For example: my_macro beef broccoli ---> make_dinner --meat beef --veggie broccoli Notes: To use the literal string {1} in your command, escape it this way: {{1}}. Extra arguments passed to a macro are appended to resolved command. An argument number can be repeated in a macro. In the following example the first argument will populate both {1} instances. macro create ft file_taxes -p {1} -q {2} -r {1} To quote an argument in the resolved command, quote it during creation. macro create backup !cp "{1}" "{1}.orig" If you want to use redirection, pipes, or terminators in the value of the macro, then quote them. macro create show_results print_results -type {1} "|" less Because macros do not resolve until after hitting Enter, tab completion will only complete paths while typing a macro.zname of this macrozwhat the macro resolves torcd|_|j|j\}}|s|d|dS|j|vr|ddS|j|jvr|ddStj}| |jj tj |j ||j}|j r |dd|j zz }g}t!jt$j|}d}t)} |} t!jt$j| d} t3| } | d kr|d dS| | t7|| }|t%| | d #t<$rYnwxYwt?| |kr|d |d dSt!jt$j |} | } t!jt$j| d} |t%| | d #t<$rYnwxYw|j|j!vrdnd}|"d|jd|tG|j||||j!|j<d|_dS)zCreate or overwrite a macro.FzInvalid macro name: Nz,Macro cannot have the same name as a commandz+Macro cannot have the same name as an aliasrrTrz'Argument numbers must be greater than 0)rrrzNot all numbers between 1 and z) are present in the argument placeholdersr'r(Macro 'r*)rrrr)$rrrrr rr|rrrrrr+r"rrrefinditerr5macro_normal_arg_patternr__next__findall digit_patterngrouprrZrrstart StopIterationrmacro_escaped_arg_patternrrr4)rYrTrrr,rrnormal_matches max_arg_numarg_numsrX cur_num_strcur_numescaped_matchesr-s rZ _macro_createzCmd._macro_create sy!->>tyII v  KK7v77 8 8 8 F 9--// / / KKF G G G F 9 $ $ KKE F F F F&8  !6!BCCC %d&79JKKK    7 S388D$5666 6EX%FNN 55  s*3355 !j)?ARARSSTUV k**Q;;KK IJJJF W%%%!+w77 Y__5F5FS^kp q q qrrr s    D  x==K ' ' KKoooo p p p F+h&H%PP  r+4466 !j)?ARARSSTUV Y__5F5FS^ko p p pqqq  r    D #')t{":":  4ty44F44555!&DIUValt!u!u!u DIs-A6H:AH H$#H$5BK99 LLz delete macrosz6Delete specified macros or all macros if --all is usedzdelete all macroszmacro(s) to deletecd|_|jr0|j|ddS|js|dd|_dStj|jD]F}||jvr"|j|=|d|d-|d|dGdS) zDelete macros.TzAll macros deletedz/Either --all or macro name(s) must be specifiedFrDr3r4N) rr5rrrr/r rrr6s rZ _macro_deletezCmd._macro_deletePs  8 F K      LL- . . . . . F KKI J J J$D   !3DJ?? F Ft{** H-LL!>8!>!>!>????KK D( D D DEEEE  F Fr\z list macroszList specified macros in a reusable form that can be saved to a startup script to preserve macros across sessions Without arguments, all macros will be listed.zmacro(s) to listc|i|_tj}||jj|jrtj|jnt|j |j }g}|D]}||j vr| |!t|j |j}|d}|dd}tj|||} |r| dd|zz } |d|d| | |j|<|D]}|d|ddS) z3List some or all macros as 'macro create' commands.rrrNrz macro create rDr:)rrrrrrr/rrrrrrr8rr;rrr r<s rZ _macro_listzCmd._macro_listusp#6t4@AAA9=w%)$*555PTP[aeavIwIwIw!  ) )D4;&&  &&&!T!2!899FQiG!!"":L  ' o F F FC 4sSXXl3333 LL55555 6 6 6%(D T " " 5 5D KK3$333 4 4 4 4 5 5r\ct|}t|}t||z}||||||S)z'Completes the command argument of help.)rr<rr<rY)rYrTrArBrCtopicsr4 strs_to_matchs rZcomplete_help_commandzCmd.complete_help_commandsfT))++,,t88::;;V&6677 ""4vv}MMMr\ arg_tokensc|dd}|sgS||x}|j|x}gStj||} | |||||dS)z+Completes the subcommands argument of help.rrN subcommands)rrrrrcomplete_subcommand_help) rYrTrArBrCr^rrrrUs rZcomplete_help_subcommandszCmd.complete_help_subcommandss Y'* IMM'** *D 3TEZE^E^_cEdEd8d 7mI&;ItLL 11$ffjYfNghhhr\zGList available commands or provide detailed help for a specific commandz-vz --verbosez6print a list of all commands with descriptions of eachzcommand to retrieve help forr`z"subcommand(s) to retrieve help for complete_helpcd|_|jr|jr||jdS||j}t |t j|jzd}|dn|j |}|H|Ftj ||}| | |jddS|(t|jdS|0|j)| t%j|dS|j|j}||dd|_dS)zHList available commands or provide detailed help for a specific command.TNrTrFr)rrverbose _help_menurrrr%rrrrr format_helpr`rdo_helprbpydocgetdocrrr )rYrTr help_funcrrUrrs rZrhz Cmd.do_helpsm | )t| ) OODL ) ) ) ) )==..Di&@4<&OQUVVI $ $2G2K2KD2Q2QII$9.CItTT  Y2243CDD" MMMMM& -----!dl&> U\$//00000/00>> G 777#(   r\headercmdlenmaxcolc&|r|||jrCtjd|jt j|}|||||dz |dSdS)aPrint groups of commands and topics in columns and an optional header. Override of cmd's print_topics() to handle headers with newlines, ANSI style sequences, and wide characters. :param header: string to print above commands being printed :param cmds: list of topics to print :param cmdlen: unused, even by cmd's version :param maxcol: max number of display columns to fit into rT) fill_charr0rN)rrulerr align_leftr widest_line columnize)rYrlrrmrndividers rZ print_topicszCmd.print_topicss   LL z &*24K[\bKcKcddd W%%% NN4! , , , LLNNNNN   r\str_list display_widthc bs|ddSfdttD}|rtd|t}|dkr|ddStdtD]}||zdz |z}g}d}t|D]u} d} t|D]<} | || zz} | |krn+| } t | t j| } =|| || dzz }||krnv||krnt}d}dg}t|D]} g}t|D]/} | || zz} | |krd n| } || 0|r|d s |d =|r|d  tt|D]'} tj || ||  || <(|d |dS) a0Display a list of single-line strings as a compact set of columns. Override of cmd's columnize() to handle strings with ANSI style sequences and wide characters. Each column is only as wide as necessary. Columns are separated by two spaces (one was not legible enough). zNcJg|]}t|t| Src)r%r)r&rrws rZr(z!Cmd.columnize..s.ZZZAZQR UX=Y=YZaZZZr\z"str_list[i] not a string for i in rrrgr-rTrHrr) rrrrtrrrrrrrr)rYrwrx nonstringssizenrowsncols colwidthstotwidthcolcolwidthrowrxtextss ` rZrtz Cmd.columnizes  LL # # # FZZZZs8}}!5!5ZZZ  OMMMNN N8}} 199 LL! % % % F1c(mm,,  EE\A%%/EIHU||   <<KKCeck)ADyy  A"8T-Fq-I-IJJHH  ***HqL(m++E,=(()MMEEI<< + +CEU||  %#+%t))BB! Q b  "I b  SZZ(( P P"-eCj #OOOc LL5)) * * * * + +r\recR|\}}}}|s7||j||j||n||j||jdt ||jD]}||||| ||j||| |j |dd| |j |dddS)z8Show a list of commands which help can be displayed for.rrrr.N) _build_command_infor doc_leader _print_topicsrrkeysrrrv misc_header undoc_header)rYre cmds_catscmds_doc cmds_undoc help_topicscategorys rZrfzCmd._help_menu,s*7;7O7O7Q7Q4 8Z I LL ) ) )   t' B B B B LL ) ) ) LLfL 5 5 5"9>>#3#39NOOO K K""8Yx-@'JJJJ   t4h H H H $*KR@@@ $+ZR@@@@@r\ct||j}t||j}g}g}i}|D]}t t ||}d}||jv} ||vr||| }t|tj rLt|tj } | | g|| ||js|s| r||||||||fS)NrF)rr<rrrr rrrrrrXr setdefaultrrb) rYrr4rrrrr has_help_func has_parserrs rZrzCmd._build_command_info?sfT11339NOOO "$";";"="=4CXYYY  " *, ' + +G T]]7%;%;<> + 'i.N O O$$Xr222(#**73333 + +* +((((!!'****(J ;;r\cddl}|rY|s|||dddStd|D}tdt|d}tdd}t ||g|j }|} |r| |d z|} | r| | d z| } |D]?} | | x} |j | x}|j }n| | vrt|tj| z}|}t#j|5|j} t)t*||_|||_n #||_wxYw dddn #1swxYwY|}n| j}|rt1|nd}|| |g}| |d zA|| dSdS) z>Print topics, switching between verbose or traditional output.rNrr.c6g|]}tj|Srcrr)r&rs rZr(z%Cmd._print_topics..gs#UUUWd7@@UUUr\rTrrr)iorvrrErFrqStringIOrgenerate_dividerr<rrrrrrr%rredirect_stdoutrrrgetvaluerbrJr#r)rYrlrrerwidest name_column desc_column topic_table table_str_bufrur[rr cmd_parserdocrkr- stdout_origcmd_desc table_rows rZrzCmd._print_topics^s > 7= 7!!&$B77777UUPTUUUVV%Rs62??? $Rr222 ); *DSWS]^^^ !# 7!'' 666%66888!''$777--//#$:$:G$(MM'$:$::C '+&;&?&?&I&II V(4!F**$+D)2Lw2V$W$W !#(7?? : :*.+K:.266.B.B ) /: k 9 9 9 9  : : : : : : : : : : : : : : :%oo//'.>AH4S999bH!, = =w>Q R RI!'' D(89999 ]335566666}> 7> 7s*?G $F4,G 4 F==G  G G zList available shortcutsctjjfd}dd|D}d|d_dS)zList available shortcuts.c:|dS)Nr)r)rrYs rZrFz"Cmd.do_shortcuts..sQUQfQfghijgkQlQlr\rrc3<K|]}|dd|dVdS)r: rNrc)r&scs rZrz#Cmd.do_shortcuts..s8JJ2be..r!u..JJJJJJr\zShortcuts for other commands: TN)rrrrrr)rYrhsorted_shortcutsr-s` rZ do_shortcutszCmd.do_shortcutssr"$"7"AGlGlGlGlmmmJJ9IJJJJJ ?v??@@@r\zCalled when Ctrl-D is pressedcT||dS)zQuit with no arguments, called when Ctrl-D is pressed. This can be overridden if quit should be called differently. rT)rdo_quitrYrhs rZdo_eofz Cmd.do_eofs% ||Br\zExit this applicationcd|_dS)zExit this application.T)rrs rZrz Cmd.do_quits tr\ Your choice? optsc Ht|tr}tttt t tftt||}n|}g}|D]}t|tr| ||f/ | |d|dfT#t$r&| |d|dfYwxYwt|D]%\}\}}| d|dz|fz& | |} nE#t$rd} | Yn#t$r| dwxYw| s` t!| } | dkrt|| dz dS#t"tf$r,| d| dt%|d YnwxYw) aPresent a numbered menu to the user. Modeled after the bash shell's SELECT. Returns the item chosen. Argument ``opts`` can be: | a single string -> will be split into one-word options | a list of strings -> will be offered as options | a list of tuples -> interpreted as (value, text), so that the return value can differ from the text advertised to the user rrz %2d. %sTrTrryz4' isn't a valid choice. Pick a number between 1 and :)r%rrr<rSr rziprrrrrrr rHrrr) rYrr local_opts fulloptionsoptidxrhrTresponsers rZselectz Cmd.selectsj dC  d5hsm);#<=tC VZV`V`VbVbDcDc?d?deeJJJ79  9 9C#s## 9""C:....9&&AA'78888!999&&AA'7888889' 44 8 8NC!T LLa6 7 7 7 7 t ??622    $    T"""   tXA::$$"6A:.q11 + t t t rrr_bcn_o_orrrsssss t% ts6 #C---DDE-- F/ F/6,G##:H H c |dd} |j|}n%#t$r}t|dz|d}~wwxYwtjt jg} d} | | | |j|j |j |j tj | |} ||||\} } | ||||| ddS) z$Completes the value argument of set.paramrrNrr)rrrrrUr)rNrr+rrrrset_parser_parentrrrrrUrrrSr)rYrTrArBrCr^rrrsettable_parserarg_namerUrhrQs rZcomplete_set_valuezCmd.complete_set_values7#A& S~e,HH S S S!%*H"HIIs R S*A3K`Jabbb$$ %$%6( %   ';OTRR 224HH :!!$ffjnMMMs  A;AzSet a settable parameter or show current settings of parameters Call without arguments for a list of all settable parameters with their values. Call with just param to view that parameter's value.)rrrzparameter to set or viewrrznew value for settable)r#rrUrc0d|_|js|ddS|jr |j|j}n/#t$r"|d|jdYdSwxYw|jr |}|tj |j| |jd|d|d|_n7#t$r*}|d |jd |Yd}~nd}~wwxYwdS|jg}n&t|j}d }td |D}t|t!j|}t%|| t%dd t%dd g}t'||j} | | i|_t-||jD]o} |j| }| ||jg} | | | ||j| <pdS)z@Set a settable parameter or show current settings of parameters.Fz There are no settable parametersNz Parameter 'z4' not supported (type 'set' for list of parameters).z - was: z now: TzError setting rNamec6g|]}tj|Srcr)r&rs rZr(zCmd.do_set..Rs#TTT5d7>>TTTr\rrr,r-r.rr)rrNr}rrr rr0 set_valuerrFrrr<rrrrrErFrqgenerate_headerrrrr#) rYrTr orig_valuerPto_show name_labelmax_name_widthcolstablerr's rZdo_setz Cmd.do_set.s!~  MM< = = = F : 2 >$*5    j$*jjjkkk z ,!)!3!3!5!5J&&u'9$*'E'EFFFLLDJ!e!e !e!eXM_M_MaMa!e!efff'+D$$ "EEEKK C C Cr C CDDDDDDDDE zlGG4>..0011G TTGTTTUU^T-Fz-R-RSS :^ 4 4 4 7" % % % = + + +  Dtz::: U**,,---G)>??? ; ;E~e,Hx1133X5IJH LL00:: ; ; ;&.&8&8&:&:D U # #  ; ;s*A(A.-A.9AC55 D)? D$$D)z(Execute a command as if at the OS promptzthe command to run)rrUc Jddl}ddl}i}tjdrd}n5|jjdz}tj d}|r||d<|j g|j }tj |d|}|j5|j|ft#|jtjr|jn|jt#tjtjr|jn tjd d |} tj| t/t0|jtj} | | j|_| j|kr|ddddS#1swxYwYdS) z)Execute a command as if at the OS prompt.rNrl:rHrrrT)rrr)signalr%rrrSIGINTrrr"rrr"rexpand_user_in_tokensrrr&r%rrr'rrrrrrrrA) rYrTrr%rctrl_c_ret_coderrRexpanded_commandr proc_readers rZrz Cmd.do_shellns  !# < " "5 ) ) -(OO%m1B6OJNN7++E -',|$,3!23 #F+++88F++ # 1 1#:# *4T[%,*O*O`zUYU`*4SZ*N*N^zTWT^   D *4fdk1J1JCJWWK       $D /11..000' 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s!C*FFFcgd}|D]@}tjt5tj|=dddn #1swxYwYAtjt_tjt_dS)aReset the dynamic objects in the sys module that the py and ipy consoles fight over. When a Python console starts it adopts certain display settings if they've already been set. If an ipy console has previously been run, then py uses its settings and ends up looking like an ipy console in terms of prompt and exception text. This method forces the Python console to create its own display settings since they won't exist. IPython does not have this problem since it always overwrites the display settings when it is run. Therefore, this method only needs to be called before creating a Python console. )ps1ps2ps3N) rrrr__dict____displayhook__ displayhook__excepthook__ excepthook) attributescur_attrs rZ_reset_py_displayzCmd._reset_py_displays+** " + +H$X.. + +L* + + + + + + + + + + + + + + +-+s<A A interpct}ttjkrCt dt jdzD].}|jt j |/t j |j D]}t j || rttjkrtt t#jt$t"jj|j_t.t$_dt0jvrDdt0jvrt0jd|_t0jdt0jd<t j|j_t jt<ttjkrt jdn0ttj krtBt j"j#_$t j%|j_&|'d|'d|'d|(t0j)|_*|j)t0_)t0j+|_,|j+t0_+|S)zsSet up interactive Python shell environment. :return: Class containing saved up cmd2 environment. r gnureadlinerLNz!from rlcompleter import Completerzimport readlinez4readline.set_completer(Completer(locals()).complete))-rerBr;rrrLrrjrrrrrrr8rrrrOr rrhrWorig_rl_basic_quotesrmodulesrirrVrorig_rl_delimsr9r;rr=r>r?rrUruncoderrrkrrl)rYrcmd2_envrrs rZ_set_up_py_shell_envzCmd._set_up_py_shell_envs- !?? fk ! !1hACCaGHH F F ''(A!(D(DEEEE  " $ $ $( + +$T****))++ Wfj((>Bv{+DfoVV\??H.;7K-3$ 33&447:{:7NH425+m2L J/4<4Q4S4S*1-n===fj((@FFFF 1116P6]-3$ 33#3; # J 7 7 76>6NCK 3333 " ! O O )(43r\pyscriptrc d|_dd}ddlm}|r|jnd}|||}d}|r|d dS d|_d }|j}|||j <||d <||d <|j r||d <|Btj |} t| 5} | }dddn #1swxYwYnh#t $r[} |d| d| Yd} ~ |j5| |t$_ d|_ddddS#1swxYwYdSd} ~ wwxYwd|d<| |d<t't$j }t$j dtj tj | nd|d<d|_t/|} |r) | |n<#t2$rYn/wxYwd} d|j d}dt$jdt$jd| d|d }d} |j5|| }dddn #1swxYwY| |d n#t2$rYnwxYw|j5|||dddn #1swxYwY|dnP#|j5|||dddn #1swxYwY|dwxYw|j5| |t$_ d|_dddn #1swxYwYn9#|j5| |t$_ d|_dddw#1swxYwYwxYw|j S) aRun an interactive Python shell or execute a pyscript file. Called by do_py() and do_run_pyscript(). If pyscript is None, then this function runs an interactive Python shell. Otherwise, it runs the pyscript file. :param pyscript: optional path to a pyscript file to run. This is intended only to be used by do_run_pyscript() after it sets up sys.argv for the script. (Defaults to None) :return: True if running of commands should stop FrRNct)zUExit an interactive Python environment, callable from the interactive Python console.)r,rcr\rZpy_quitz Cmd._run_python..py_quit/s% %r\rPyBridgeTr]=Recursively entering interactive Python shells is not allowedrTquitrErYzError reading script file 'r__main__r___file__r __console__)localszFType "help", "copyright", "credits" or "license" for more information.z]Use `Ctrl-D` (Unix) / `Ctrl-Z` (Windows), `quit()`, `exit()` to exit. Run CLI commands with: z("command ...")zPython z on rr)bannerexitmsgzNow exiting Python shell...r])!r py_bridgerrr#r rrrrrrrrrrrrrrr<insertrrrr BaseExceptionversionrrinteractrrrK)rYrrrrVrsaved_sys_pathpy_code_to_run local_varsexpanded_filenamefrPrcprt instructionsrsaved_cmd2_envs rZ _run_pythonzCmd._run_python!s! & & & &      9AJ44dHT.AAA        KKW X X X4T $DKN ,,..J.7Jt* +!(Jv !(Jv  *%) 6"#$&G$6$6x$@$@! /002A)*222222222222222   KK X>O X XTV X XYYY444n' $ $!--CH#  $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s *4 :&): :&"&ch27??27??CT3U3U#V#VWWWW*7 :& $D 'z:::F" @NN>2222$D `S.2.ASSS_3;^^CL^^D^^l^^^!%@/KK)-)B)B6)J)JKKKKKKKKKKKKKKK OO62O>>>>$D /CC)5 22>BBBCCCCCCCCCCCCCCCLL!>????/CC)5 22>BBBCCCCCCCCCCCCCCCLL!>????' $ $!--CH#  $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' $ $!--CH#  $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ~sjA$N=C9 C-! C9-C11C94C15C98N9 EEN)E  EEEBN>HN H#N"H##5NJ% J6 J%JJ% J J%$L% J2/L1J22L5N<K  N K$$N'K$(NM L-! M-L1 1M4L1 5MNM::M>M>N<N0$ N<0N4 4N<7N4 8N<zRun an interactive Python shellc*|S)zdRun an interactive Python shell. :return: True if running of commands should stop. )rrs rZrz Cmd.do_pys!!!r\z+Run a Python script file inside the console script_pathzpath to the script filescript_argumentszarguments to pass to scriptcd|_tj|j|_|jds<|d|jd|dd}|dkrdStj } |jg|j t_ | |j }|t_ n#|t_ wxYw|S) zoRun a Python script file inside the console. :return: True if running of commands should stop F.pyryz' does not have a .py extensionYes Noz.Continue to try to run it as a Python script? YesNr) rrrrrendswithr}rrrrr)rYrT selection orig_args py_returns rZdo_run_pyscriptzCmd.do_run_pyscripts !7--d.>??((//  MMOd.OOO P P P H.^__IE!!tH  !(A4+@ACH(($2B(CCI!CHHyCH s 4CC#z Run an interactive IPython shellcd|_ ddlmcm} |}n#t$r ddlm}YnwxYwddlm}ddl m }n&#t$r| dYdSwxYwdd l m}|r| d dSd |_ d |_||}|j} || |j<|jr|| d <|} d |jd| j_|| g| |d|||jd|_S#d|_wxYw)zfEnter an interactive IPython shell. :return: True if running of commands should stop FrNr9)TerminalInteractiveShell)TerminalIPythonAppz IPython package is not installedrrrTrYzVEntering an IPython shell. Type exit, quit, or Ctrl-D to exit. Run CLI commands with: z("command ...") )configruser_nszNow exiting IPython shell...)rtraitlets.config.loaderrloader NameErrorIPythonr:!IPython.terminal.interactiveshellrIPython.terminal.ipappr ImportErrorr rrr#rrrrrrConfigInteractiveShellbanner2rclear_instancerK) rYrhtraitlets_loaderr:_dummyrrrrrrs rZrz Cmd.do_ipys5 !  > > > > > > > > > 2& 2 2 211111111 2                 KK: ; ; ;44              KKW X X X4 DK I ,,..J.7Jt* + *%) 6"&,,..FQ*.*=QQQ  # + Mb* E E E E LL7 8 8 8  - - / / / $ 3 3 5 5 5>DKK%DK    s4 99)9)9AAB;E E$z;View, run, edit, save, or clear previously entered commandsz-rz--runzrun selected history itemsz-ez--editz(edit and then run selected history itemsz-oz --output_fileFILEz,output commands to a script file, implies -s)rrrUrz --transcriptTRANSCRIPT_FILEzKcreate a transcript file by re-running the commands, implies both -r and -sz-cz--clearzclear all history formattingtitlez-sz--scriptz>output commands in script format, i.e. without command numbersz-xz --expandedz\output fully parsed commands with any aliases and macros expanded, instead of typed commandszSdisplay history and include expanded commands if they differ from the typed commandzEdisplay all commands, including ones persisted from previous sessionszempty all history items a one history item by number a..b, a:b, a:, ..b items by indices (inclusive) string items containing string /regex/ items matching regular expressionr)r#rc  d|_|jrt|js*|js#|js|js|js|js|jrC| d| |j dS|js|jrf|js|js|js|js|jrC| d| |j dS|jrd|_|j |j re tj|j nJ#t $rYn>t"$r2}|d|j d|d|_Yd}~dSd}~wwxYwt&t(jkrt-jdS||}|jrp|js,|d|d n>|t7|}d|_|S|jrt;jd d \}}tj|d 5}|D]I}|j j!r|"|jd ,|"|j#d J dddn #1swxYwY |$||%tMj'|tj|S#tj|wxYw|jrDtj()tj(*|j} tW| d 5}|D]I} | j j!r|"| jd ,|"| j#d J dddn #1swxYwYtY|dkrdnd} |-tY|d| d| d|_n#t"$r%}|d| d|Yd}~nd}~wwxYw|jr;|.t7||jn\|/D]@\} } | | 0| |j|j|jA||_dS)zView, run, edit, save, or clear previously entered commands. :return: True if running of commands should stop Fz(-v cannot be used with any other optionsNz3-s and -x cannot be used with -c, -r, -e, -o, or -tTzError removing history file 'rz9Cowardly refusing to run all previously entered commands.zEIf this is what you want to do, specify '1:' as the range of history.z.txt)rrTrrrrTrz commandz saved to zError saving history file ')scriptexpandedre)1rreredit output_filerun transcriptr4r3rhistory_parser format_usagerjrrrFileNotFoundErrorrr rBr;rrLr _get_historyrrr<r_rmkstempfdopenrrrr run_editor do_run_scriptrrrrrrrr_generate_transcriptr`pr)rYrTrPrjrKfdfnamefobjr full_pathrrrhis rZ do_historyzCmd.do_historyCs ! < z TY $*: dh $/ ]a]j nrny  GHHH T0==??@@@t K 4= tz TY $JZ ^b^f jnjy  LLN O O O LL,99;; < < <4 : #D  L   +  Id:;;;;(D   KK e@\ e eac e efff',D$44444 &+%%&(((4##D)) 8. '8  WXXX cdddd..tGNN4D4D/E/EFF#'  Y& ' (TBBBIB2s## 7t&~~//77G(:7 g&6#:#:#:;;;; gk#5#5#56666 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7  !&&&))%*;8 JJ$-';';';<<<< JJ$(7777 8888888888888888 #7||q00c#g,,UUUU)UUVVV#'   N N N L)LLLLMMMMMMMM N _ '  % %d7>>+;+;&<&>M!Q11AP Q1P!!Q1$P!%Q11 R ;RR zOrderedDict[int, HistoryItem]cb|jr t|j}t||j|iS#t $rYnwxYwd|jvs d|jvr&|j|j|j}n|jdr@|j dr&|j |j|j}nF|j |j|j}n |jd|j}|S)zIf an argument was supplied, then retrieve partial contents of the history; otherwise retrieve entire history. This function returns a dictionary with history items keyed by their 1-based index in ascending order. z..r/) rrrrjrrspanr5rr regex_search str_search)rYrTint_argrjs rZr<zCmd._get_historys$ 8 7 dh--"GT\-=-=g-F-F#GHHH    tx3$(??,++DHdh??$$T** Ftx/@/@/F/F F,33DHdhGG,11$(DHEEl''TX66Gsj krc|jD]]} tC| j"} tGj$} | d ks| tGj%| krtGj&| \dSdS)aMInitialize history using history related attributes. :param hist_file: optional path to persistent history file. If specified, then history from previous sessions will be included. Additionally, all history will be written to this file when the application exits. NzPersistent history file 'z' is a directoryT)exist_okz2Error creating persistent history file directory 'rrbr\z%Cannot read persistent history file 'rrrz-Error decompressing persistent history data 'z@ The history file will be recreated when this application exits.z*Error processing persistent history data ')'r1rjrrrrrrur rmakedirsrrrr;atexitregister_persist_historylzma LZMAErrorModuleNotFoundErrorbz2r decompressdecodejson from_jsonJSONDecodeErrorr start_sessionrBr;rr3rrLrrr)rYrO hist_file_dirrPrEcompressed_bytesrTdecompress_libdecompress_exceptions history_jsonr]rrcur_history_lengths rZrzCmd._initialize_historysNyy  +4D ( FGOOBG$6$6y$A$ABB  7== # #  KKOIOOO P P P F 22   K  5 5 5 5 5    KKc]cc_acc d d d FFFFF   i&& /$#'99;;  / / / / / / / / / / / / / / /  # # #"       KKR RRbRR S S S FFFFF   '0$-...   F R ) ) ) )=K=U>>|++-- '001D1Dg1D1V1VWW hd2D99 -T +,,, - - - - - - - - - - - - - - - - - - h h h KKfA]ffbdff g g g g g g g g g hsH!!C B>1 C >CC CC D C;;Dtranscript_filecd|_tjtj|}tj|}tj|rtj|tjs| d|ddSd} |j 5|j }|j }d|_ dddn #1swxYwYd} |D]$} d} d} t| tr| j} | D]%} | r| |j| dz } d} | |j| dz } &| | z } t'jt+t,|j }t+t,||_ || |d }n.#t0$r!}| |d}Yd}~nd}~wwxYw|d z }| |d d z } |rn&|j 5||_ t+t,||_ dddn #1swxYwYnE#|j 5||_ t+t,||_ dddw#1swxYwYwxYw|t7|kr|d |d t;|d5}|| dddn #1swxYwY|d krdnd}||d|d|dd|_dS#t@$r&}| d|d|Yd}~dSd}~wwxYw)z#H#H#H#HHg% d64;&?&?@@"6622  11$'5152DD )   KKOOODDDDDD ! foo//77UCCC E' 9 9& "6<88  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9' 9 9& "6<88  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 #g,, & & MMj\jjj k k k $os++ 't :&&& ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 2>1B1B--HdF NNlbbVbbP_bbb c c c#D     S S S KKQQQRQQ R R R R R R R R R Ss?IC( I(C,,I/C,0B/I F98I9 G$GIG$$9I$"IIIJ &"J J J J J J L> L6 L>LL> L L>> M.M))M.zRun a text editor and optionally open a file with it The editor used is determined by a settable parameter. To set it: set editor (program-name) file_pathz)optional path to a file to open in editorc:||jdS)z5Run a text editor and optionally open a file with it.N)r?rz)rYrTs rZdo_editz Cmd.do_edits '''''r\c:|jstdtjtj|j}|r7|dtjtj|zz }||dS)zRun a text editor and optionally open a file with it. :param file_path: optional path of the file to edit. Defaults to None. :raises EnvironmentError: if self.editor is not set zGPlease use 'set editor' to specify your text editing program of choice.rN)rrrrrrrr)rYrzrs rZr?zCmd.run_editors { ecdd d$RW%7%7 %D%DEE  O sU/0B0B90M0MNNN NG gr\c.|jr |jdSdS)zMAccessor to get the current script directory from the _script_dir LIFO queue.rHN)rrXs rZrzCmd._current_script_dirs"   (#B' 'tr\a7Run commands in script file that is encoded as either ASCII or UTF-8 text Script should contain one command per line, just like the command would be typed in the console. If the -t/--transcript flag is used, this command instead records the output of the script commands to a transcript for testing purposes. z4record the output of the script as a transcript filecLd|_tjtj|j}|dr7|d|d|dd}|dkrdS tj |d kr d |_dStj |s| d|d dSt|d 5}|}dddn #1swxYwYn3#t $r&}| d|d|Yd}~dSd}~wwxYwt#|j} |jtj||jr@||tj|j|jnv|||jd }d |_||j5|t#|jkr|jdddS#1swxYwYS |j5|t#|jkr|jdddn #1swxYwYnU#|j5|t#|jkr|jdddw#1swxYwYwxYwdS)Run commands in script file that is encoded as either ASCII or UTF-8 text. :return: True if running of commands should stop Frryz' appears to be a Python filerz,Continue to try to run it as a text script? rNrTz,' is not an ASCII or UTF-8 encoded text filerrzProblem accessing script from 'rr]r)rrrrrrrr}rgetsizer is_text_filer rrrprrrrrr8rArrrr) rYrTr|rtargetscript_commandsrPorig_script_dir_countrKs rZr@zCmd.do_run_scripts4 !(:(:4;K(L(LMM   ! !% ( (  MMJmJJJ K K K H.\]]IE!!t w}--22#' t%m44  [ [[[\\\tmg666 =&"(++--":":"<"< = = = = = = = = = = = = = = =    KKP-PPBPP Q Q Q44444 !$D$4 5 5 +   # #BGOOM$B$B C C C ))#G&&t77#'#>* ..##'#>/3/ $( ' + +(C0@,A,AAA$((*** + + + + + + + + + + + + + + + +' + +(C0@,A,AAA$((*** + + + + + + + + + + + + + + +' + +(C0@,A,AAA$((*** + + + + + + + + + + + + + + + +ts*E-E1E'D5) E5D99E<D9=E E1 E,,E1 B#K32I11I5 8I5 2KK KL!2L L!L L!L L!z If this is called from within an already-running script, the filename will be interpreted relative to the already-running script's directory.zKNotes: This command is intended to only be used within text file scripts.z a file path pointing to a scriptc|j}tj|jpd|}|t j|S)rrT)rzrrrrr@rr)rYrTrz relative_paths rZdo__relative_run_scriptzCmd.do__relative_run_scriptsI N  T%=%CYOO !!%"4]"C"CDDDr\transcript_pathsc ddl}ddl}ddl}ddlm}Gfdd|}t j|tj}|s dd_ dSd tttjdd }t!|} t!|dkrd nd } t%jt jd dddtjd|d|jdt.dtjdtjdt%jd| d| d|j_tjdgt_|} t9t:t jtj} | | } |}| !| }||z }|"rkt%j#tj| $d| d| d|dd}t j|d}%|dS| $}|&d}||d&d }||z} ||dd_ dS)!a"Run transcript tests for provided file(s). This is called when either -t is provided on the command line or the transcript_files argument is provided during construction of the cmd2.Cmd instance. :param transcript_paths: list of transcript test file paths rNr) Cmd2TestCaseceZdZZdS)0Cmd._run_transcript_tests..TestMyAppCaseN)r_r`racmdapprXsrZ TestMyAppCaser0sFFFr\r)rz%No test files found - nothing to testr{rTrz cmd2 transcript test =)rpT)boldz platform z -- Python z, cmd2-z , readline-zcwd: z cmd2 app: z collected z transcript)streamrz passed in z.3fz seconds zAssertionError:zFile )'timeunittestcmd2r8rrfiles_from_glob_patternsrR_OKr rrmaprr version_inforrrr align_centerr __version__rBrrrrrrrrTextTestRunnerr7 wasSuccessfulrrrr)rYrrrrrrtranscripts_expandedverinfonum_transcriptsrtestcaserrunner start_time test_resultsexecution_time finish_msg error_str end_of_trace file_offsetrLs` rZ_run_transcript_testszCmd._run_transcript_testss`                L    %=>NWYW^___#  KK? @ @ @DN F((3sC$4RaR$899::233/00A553 TZ 23KWZ [ [ [bfggghhh ppp'pp$JZppgnppqqq *RY[[**+++ /#(1+//000 TZ Q_ Q Q Q QX\]]]^^^#7 HQK= =??fel3:6677(((77YY[[ zz(++ z1  % % ' '   "3:v{{}} = = =i_iiiiNiiiiJ+J#FFFJ MM* % % % % % I$>>*;<t2j|t2jn>t,t.jkr)t&jjj |tC|j"dStd ) aaDisplay an important message to the user while they are at a command line prompt. To the user it appears as if an alert message is printed above the prompt and their current input text and cursor location is left alone. This function needs to acquire self.terminal_lock to ensure a prompt is on screen. Therefore, it is best to acquire the lock before calling this function to avoid raising a RuntimeError. This function is only needed when you need to print an alert or update the prompt while the main thread is blocking at the prompt. Therefore, this should never be called from the main thread. Doing so will raise a RuntimeError. :param alert_msg: the message to display to the user :param new_prompt: If you also want to change the prompt that is displayed, then include it here. See async_update_prompt() docstring for guidance on updating a prompt. :raises RuntimeError: if called from the main thread. :raises RuntimeError: if called while another thread holds `terminal_lock` z5async_alert should not be called from the main threadNF)blockingrTr)terminal_columnsrrA cursor_offsetrz"another thread holds terminal_lock)#rcurrent_thread main_threadrrDrrr rneed_prompt_refreshrAshutilget_terminal_sizecolumnsrDEFAULT_TERMINAL_WIDTHrasync_alert_strr=rLrr>rBr;r8rrrrr;r=r>rrMr)rYrrupdate_terminalrr terminal_strs rZ async_alertzCmd.async_alert]s(  # % %)>)@)@ @ @VWW W $"3  F   % %u % 5 5+ E$O 'T! "&%( '')) +"&dk*** % $*#;#;#=#=#E#iIi  $3%5022!133"...'     fj((J$$\222J$$&&&& 111K$,22<@@@#$$$   & & ( ( ( ( (CDD Dr\c2|d|dS)aUpdate the command line prompt while the user is still typing at it. This is good for alerting the user to system changes dynamically in between commands. For instance you could alter the color of the prompt to indicate a system status or increase a counter to report an event. If you do alter the actual text of the prompt, it is best to keep the prompt the same width as what's on screen. Otherwise the user's input text will be shifted and the update will not be seamless. If user is at a continuation prompt while entering a multiline command, the onscreen prompt will not change. However, self.prompt will still be updated and display immediately after the multiline line command completes. :param new_prompt: what to change the prompt to :raises RuntimeError: if called from the main thread. :raises RuntimeError: if called while another thread holds `terminal_lock` rTNr)rYrs rZasync_update_promptzCmd.async_update_prompts " Z(((((r\c0|ddS)aRefresh the oncreen prompt to match self.prompt. One case where the onscreen prompt and self.prompt can get out of sync is when async_alert() is called while a user is in search mode (e.g. Ctrl-r). To prevent overwriting readline's onscreen search prompt, self.prompt is updated but readline's saved prompt isn't. Therefore when a user aborts a search, the old prompt is still on screen until they press Enter or this method is called. Call need_prompt_refresh() in an async print thread to know when a refresh is needed. :raises RuntimeError: if called from the main thread. :raises RuntimeError: if called while another thread holds `terminal_lock` rTNrrXs rZasync_refresh_promptzCmd.async_refresh_prompts r\c~tr|jsdSt o|j o|jt kS)z\Check whether the onscreen prompt needs to be asynchronously refreshed to match self.prompt.F)rDrr@rrr?rXs rZrzCmd.need_prompt_refreshsJ $"3 5%&&&nt/K+KnPTP[_l_n_nPnnr\r1ctsdS tjt j|tjdS#t$rYdSwxYw)a,Set the terminal window title. NOTE: This function writes to stderr. Therefore, if you call this during a command run by a pyscript, the string which updates the title will appear in that command's CommandResult.stderr data. :param title: the new window title N)rDrrrr set_titlerr|r0s rZset_window_titlezCmd.set_window_titlesr  F  J  T^E22 3 3 3 J           DD sAA A*)A*c||jvrdStj|z}tj|z}tj|z}|j|}t |||j|jt||nt |||j|j t||nt |||j |j|=dS)zhEnable a command by restoring its functions. :param command: the command being enabled N) rrr#r%r$rrorpr^rq)rYrrfrirgdcs rZrzCmd.enable_commands $0 0 0 F!5? "3g='=G #G ,mR%8999   # D. ) ) ) ) D."*: ; ; ;  ( D- . . . . D-r/D E E E  "7 + + +r\rct|jD]H}|j|j}t|tjd|kr||IdS)z`Enable an entire category of commands. :param category: the category to enable N)r<rrorrrXr)rYrr~rs rZenable_categoryzCmd.enable_categorysg T344 . .H)(3DDtY=tDDPP##H--- . .r\message_to_printc ||jvrdS||}|td|dtj|z}tj|z}tj|z}t|t||dt||d|j|<tj |j | tj |}t|||t|||t||ddS)aDisable a command and overwrite its functions. :param command: the command being disabled :param message_to_print: what to print when this command is run or help is called on it while disabled The variable cmd2.COMMAND_NAME can be used as a placeholder for the name of the command being disabled. ex: message_to_print = f"{cmd2.COMMAND_NAME} is currently disabled" Nryz' does not refer to a commandrn)rcgSrgrc)_args_kwargss rZrFz%Cmd.disable_command..4sRr\)rrr|rr#r%r$rmrrr_report_disabled_command_usager  COMMAND_NAMEr)rYrrrorfrirgnew_funcs rZdisable_commandzCmd.disable_commands/ d, , , F ==11  # !KW!K!K!KLL L!5? "3g='=G+:-!$==&t-@$GG+ + + w'$  /BRBZBZ[d[qszB{B{    mX...nh/// )+G+GHHHHHr\c|}|D]L}||}t|tjd|kr|||MdS)aDisable an entire category of commands. :param category: the category to disable :param message_to_print: what to print when anything in this category is run or help is called on it while disabled. The variable cmd2.COMMAND_NAME can be used as a placeholder for the name of the command being disabled. ex: message_to_print = f"{cmd2.COMMAND_NAME} is currently disabled" N)rrrrrXr)rYrr all_commandsr~rs rZdisable_categoryzCmd.disable_category6su,,.. $ A AH==**DtY=tDDPP$$X/?@@@ A Ar\rrc4||ddS)zReport when a disabled command has been run or had help called on it. :param _args: not used :param message_to_print: the message reporting that the command is disabled :param _kwargs: not used FrN)r )rYrrrs rZrz"Cmd._report_disabled_command_usageFs! $% 88888r\introctjtjurtdddl}||j}||j|jtj dst||j }||j |j ||j }||j |j |j|jD] }| ||j%|d|jDn>|||_|j||j||jD] }| ||j||j|tj ds6||j |||j ||jS)aDeal with extra features provided by cmd2, this is an outer wrapper around _cmdloop(). _cmdloop() provides the main loop equivalent to cmd.cmdloop(). This is a wrapper around that which deals with the following extra features provided by cmd2: - transcript testing - intro banner - exit code :param intro: if provided this overrides self.intro and serves as the intro banner printed once at start z&cmdloop must be run in the main threadrNrcLg|]!}tj|"Src)rrr)r&tfs rZr(zCmd.cmdloop..ws('`'`'`2(:(:2(>(>'`'`'`r\)rrrrr getsignalrr@rrrSIGHUPrFSIGTERMrr _preloop_hooksrOrrrrr_postloop_hooksrRrr)rYrroriginal_sigint_handleroriginal_sighup_handleroriginal_sigterm_handlerrs rZcmdloopz Cmd.cmdloopPsC  # % %Y-B-D-D D DGHH H  "("2"26="A"A fmT%8999|&&u-- K&,&6&6v}&E&E # MM&-)H I I I'-'7'7'G'G $ MM&.$*I J J J ""$$$'  D DFFFF   ! -  & &'`'`I_'`'`'` a a a a " z% TZ((( MMOOO(  D DFFFF  ""$$$  fm%<===|&&u-- D MM&-)@ A A A MM&.*B C C C~r\cZg|_g|_g|_g|_g|_g|_dS)zInitialize the plugin system.N)rrrarhrkr~rXs rZrzCmd._initialize_plugin_systems88:9;df]_`bxz###r\r.countc tj|}t|j}||kr)|dkrdnd}t |jd|d|d|dS)z5Ensure a function has the given number of parameters.rrTrz has z positional argument , expected N)r4r5rr6rtr_)clsrrr5nparamrs rZ_validate_callable_param_countz"Cmd._validate_callable_param_countst%d++ Y)** U??!Q;;RRCFt}ii6iiviibgiijj j ?r\c||dt|\}}|t|jd|dS)z@Check parameter and return types for preloop and postloop hooks.rNz) must have a return type of 'None', got: )rrIrtr_)rrrhret_anns rZ_validate_prepostloop_callablez"Cmd._validate_prepostloop_callablesV **4333t__ 7  t}``W^``aa a  r\cd|||j|dS)zFRegister a function to be called at the beginning of the command loop.N)rrrrYrs rZregister_preloop_hookzCmd.register_preloop_hooks3 ++D111 ""4(((((r\cd|||j|dS)z@Register a function to be called at the end of the command loop.N)rrrrs rZregister_postloop_hookzCmd.register_postloop_hooks3 ++D111 ##D)))))r\c|ttdtf|dt |\}}|st |jdtt| }|tj krt |jd|tj krt |jddS)z7Check parameter and return types for postparsing hooks..rzJ parameter is missing a type hint, expected: 'cmd2.plugin.PostparsingData'zI must have one parameter declared with type 'cmd2.plugin.PostparsingData'zC must declare return a return type of 'cmd2.plugin.PostparsingData'N) rrrr rIrtr_nextiterr_rr`)rr type_hintsrpar_anns rZ_validate_postparsing_callablez"Cmd._validate_postparsing_callables **4c0BD+I+I1MMM'oo G zt}xxxyy ytJ--//0011 f, , ,t}wwwxx x f, , ,t}qqqrr r - ,r\cd|||j|dS)zYRegister a function to be called after parsing user input but before running the command.N)rrarrs rZregister_postparsing_hookzCmd.register_postparsing_hooks3 ++D111 &&t,,,,,r\CommandDataType data_typec|ttdtf|dt |\}}|st |jd|tt| \}}||krt d|jd|d||t |jd|||krt |jd |d|dS) z@Check parameter and return types for pre and post command hooks..r- parameter is missing a type hint, expected: zargument 1 of z has incompatible type rNz0 does not have a declared return type, expected z has incompatible return type ) rrrr rIrtr_rrr`)rrrrr param_namers rZ_validate_prepostcmd_hookzCmd._validate_prepostcmd_hooks **4c0BD+I+I1MMM'oo G ht}ff[dffgg g"4 (8(8(:(:#;#;<< G i  rT]rrSZrrgprrss s ?t}ii^giijj j i  t}kkGkk`ikkll l r\cz||tj|j|dS)z9Register a hook to be called before the command function.N)rrrgrhrrs rZregister_precmd_hookzCmd.register_precmd_hooks8 &&tV-BCCC !!$'''''r\cz||tj|j|dS)z8Register a hook to be called after the command function.N)rrrjrkrrs rZregister_postcmd_hookzCmd.register_postcmd_hooks8 &&tV-CDDD ""4(((((r\c||dt|\}}|s#t|jdtjt t|\}}|tjkr&t|jdtjd||tjkr#t|jdtjdS)z@Check parameter and return types for command finalization hooks.rrz, must have one parameter declared with type z, got: z& must declare return a return type of N) rrIrtr_rr}rrr`)rrrrrhrs rZ"_validate_cmdfinalization_callablez&Cmd._validate_cmdfinalization_callables **4333'oo G }t}{{[a[y{{|| |$z//112233 7 f4 4 4=~~fNl~~u|~~  f4 4 4t}ttTZTrttuu u 5 4r\cd|||j|dS)zdRegister a hook to be called after a command is completed, whether it completes successfully or not.N)rr~rrs rZregister_cmdfinalization_hookz!Cmd.register_cmdfinalization_hooks5 //555 #**400000r\cmd_support_funccmd_selfcJt|}|t|tr|t||r|}ngd}g}|jD]>}t ||kr|}n&t||r||?|t|dkr|d}|S|S)a Attempt to resolve a candidate instance to pass as 'self'. Used for an unbound class method that was used when defining command's argparse object. Since we restrict registration to only a single CommandSet instance of each type, using type is a reasonably safe way to resolve the correct object instance. :param cmd_support_func: command support function. This could be a completer or namespace provider :param cmd_self: The `self` associated with the command or subcommand Nrr)rH issubclassr!r%rr$rr)rYr r  func_class func_selfcandidate_setsinstalled_cmd_sets rZ_resolve_func_selfzCmd._resolve_func_self s +==M*N*N   !jZ&H&H !(J// 2$ ! 35)-)EAA%-..*<<$5 ""3Z@@A&--.?@@@$^)<)<)A)A .q 1I  r\)rNNr])rTrg)r.)F)r(r_r`rarbr find_editorrINTERNAL_COMMAND_EPILOG norm_foldr natural_keysNATURAL_SORT_KEYrrr<r__annotations__rrrrrrr!r[r$r)rrrr&rrrrStaticArgParseBuilderClassArgParseBuilderrr rUrrVrWrrrrpropertyrOsetterrrGrNrrrrrrrrr r rrr rr}rrr,r6r@rSrSrYrcrkrorrrrrr:r<rrrrrrr$r#r|rrrrFrEr"rr(r*r+r1r2rr<r r@rFrAr6rJrMrOrRrUryrpr2rrr_rrrcrlrrirrrrrrrrQrrralias_description alias_epilogrr alias_parseradd_subparsersr( Namespacer alias_create_descriptionalias_create_epilogalias_create_parserr REMAINDERr'rr.alias_delete_helpalias_delete_descriptionalias_delete_parser ZERO_OR_MORErr8alias_list_helpalias_list_descriptionalias_list_parserr@macro_description macro_epilog macro_parserrBmacro_create_helpmacro_create_descriptionmacro_create_epilogmacro_create_parserrUmacro_delete_helpmacro_delete_descriptionmacro_delete_parserrWmacro_list_helpmacro_list_descriptionmacro_list_parserrYr]rb help_parserOPTIONALrrurrr^rhrvrtrfrrshortcuts_parserr eof_parserr quit_parserrrrset_descriptionr set_parserr shell_parserrrrrerrr py_parserrrun_pyscript_parserripython_parserrhistory_descriptionr9add_mutually_exclusive_grouphistory_action_groupadd_argument_grouphistory_format_grouphistory_arg_helprHr<rrVrAedit_description edit_parserr|r?rrun_script_descriptionrun_script_parserr@relative_run_script_descriptionrelative_run_script_epilogrelative_run_script_parserrrrrrrrrrrrrrrrprrrrrr`rrrrrrgrrjrr}rrobjectr __classcell__)rs@rZrrrrs#-'U&((N p "O)&(IxS "'''!"&#' G9 (*)- ', !#04"&26+/.27;#' $(-+G9G9G9G9G9 G9 "% G9$'G9G9!%G9G9G9G9#49-G9 G9%T#Y/G9 d3i(!G9"DcN+#G9$x 34%G9&!'G9()G9*"&+G9, -G9G9G9G9G9G9R ]b    Z0@  UY  fjkufv     ;;@T;;;;55550J:J$JJJJX$$  # R00 1 !  " $$  $$$$L'9'93'9P['9fi'9sw'9'9'9'9R:C: :Z^::::0s0hy>Q0VZ0000)8Z)8D)8)8)8)8V?:?$????8cE*e2C,DcccccJ+eJ4E.F+4++++Z----X-# 2 2$ 2 2 2$# 2 73=1   X 2X2$2222 KC KD K K K K(T(T(T(TX T_   X #4?#t####WtWWWW----X-04 ;;;g;;  ; #,- ; ;;;;61411131S1D1111a$Daaa#aCaTaUYaaaa#D###C#c#T####5D555C5c5T5555/3;;;3;;;QU;;;;615 = = =S =# = = = = =.22'2'2'#2's2'2'$2'2'2'2'h34"]anr X X XC XC XC XXVY] Xhk Xw{ X X X XUUUU&>"#>"s>"C>"ERVWZR[]abe]fRfLg>">">">"@XXX X  X  } X cXXXX*BBB B  B  } BB cBBBBX?C/#/#/#/#/# /#  /# U8C=-#?@@A /#hsm]:;/# c/#/#/#/#rCG///// /  / Cx}m'C!DDE /5# !=>?/ c////p8<OOOOO O  Ohud{34O cOOOOblq   s # s C dh uyz}u~    0O4sO4#O4sO4CO4[hO4mqrumvO4O4O4O4bWDIW%S SVBWWWW\W,;!;!*.s);!KN;! ;!;!;!;!z<49<<<<<@ X-D N`NrIs   \  {pEpEpE"pE,/pE9<pEOWX]XvOwpE pEpEpEpEfbffff #f6>u?]6^f #ffffP444444T-c3h---X-49 $s)     d3i    *k66'+D+D+D*ETXYYYT.-A*k66'+D+D+D*ETXYYYT.-A"-ffWB.G.G.GP]egIhIhIh-ix|!}!}!}^0DBcBBBB |c | | | |1S1Xi-@1T1111,)9LQU <<<< [in 5 [) [ [ [ [ D U9c>-B t             Mc MeCcM&: M M M M" $).$04@@@@ @ #' @  @!) @ @@@@Dt@SX\, $+0 ###D%tCy01# # %) #  ####JY]XXXXQT XajXXXXt^b333S3XVY]3fo3333j&1 &1hsm&1&1&1&1Pm!)m!8Sm!m!m!m!^@@uGb@gk@@@@8CC(=CCCC"RV!3!3!3in 5!3$!3Z^!3!3!3!3Fx~$EE EEEE(,050D0I %+/:>-148]#]#]#]#$s)$ ]# - ]#  ]#(3-(]###67]#M*]#01]# ]#]#]#]#~))))))&&!'=&!&!&!&!PP3IPdPPPP (D(D(D(D^x'L:?:GXamnnnL tDDD^L$777X/D87 > DB/A,5H$$V2F$GGG$$4Gv%$$h07Uan%gx)N#NSN#NsNW[\_W`NNNNii"i,/i9<iJNsTXY\T]~J^i ciiii :/9]K k,5m*1O[pX/6Zf wsw..:)))^K  ")H.")4")")")")")! ")H3htCy.A3X[`d$5+5+(49"55+c5+SW5+5+5+5+nAA$A4AAAA&B7CB7tCyB74B7DB7B7B7B7H?>Kefff^$%% h0 T   &% 983+=>->>>>@"O-"OD"O"O"O"OH8<tttx}tttttl87DefffI^I"x)"htn""""B/AN{|||$$]9R^k$lll$$("4;Xdq%^'((H$68D>)(B=_EUVVV^N##Zx1ZhtnZZZ$#Zx!38W0[`+aaa^.// EH,> E8D> E E E0/ E<d3i<D<<<<|FEFESFEhsmFEtFEFEFEFEP)c)d))))&"oToooo\$,c,d,,,,@......&Is&Ic&Id&I&I&I&IPAAAAAAA 9S9C9\_9dh9999DDXc]DcDDDDV{{{{k(382DkSkUYkkk[kb(2t82Dbbbb[b)(2t8*<))))) *8BH+=*$****  s(F?mLPQ`Lam mmm[m((63H2I6K`2`)a(fj(((( )(F4J3KVMc3c*d)im)))) vV;\\]v vvv[v 1f<=v?]]^1 11112"38,2 E4/02 &  22222222r\)rbrrurrrrrr4rr4rirErrrrnr collectionsrrcollections.abcrrrtypesr r typingr r r rrrrrrrTrrrrrrrrr clipboardrrcommand_definitionr r!r"r#r$r%rur&r'r( exceptionsr)r*r+r,r-r.r/r0rjr1r2r3parsingr4r5r6r7r8rr&r#r:rl_utilsr;r<r=r>r?r@rArBrCrD table_creatorrErFrGrHrIrJrKrrrrrLrMrrr;r=r>r?rr8rrNrin_dllrOrr rrrQrermrrrrprrtrrrcr\rZr^sG<    ######                                              Z%%&&%%%%%%&&&&&&&&&&&&&&&                         fkJ'T' 334444 3X244N&###"*+"2"G FJ         %+O$:$:'?XE\'\](&?0?0?0?0?0?0?0?0DfTfTfTfTfT#'fTfTfTfTfTs-DDD