igdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZmZddlmZddlmZmZddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#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/m0Z0m1Z1dd l2m3Z3m4Z4dd l5m6Z6m7Z7dd l,m8Z8m9Z9m:Z:m;Z;ddlZ>m?Z?ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHddlImJZJmKZKmLZLddlMmNZNmOZOmPZPmQZQmRZR ddlSmTZTn #eU$rYnwxYwddlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`ddlambZbmcZcddl.mdZdmeZemfZfmgZge^eWjhkr)e jije)jke_nddlVmlZlmmZmeljnZoe^eWjpkreljqjrjsZtnUe^eWjukrJddlvZvddlVmwZwevjxyewdZze'e{evj'ezevj|j}Z~GddZGddZedgdZer(egejfZee&de7fgejfZneZeZGd 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)redirect_stdout) FrameType ModuleType)IO TYPE_CHECKINGAnyCallableDictIterableListMappingOptionalSetTextIOTupleTypeTypeVarUnioncast)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_classstrip_doc_annotationssuggest_similar)readlinerl_force_redisplay) readline_librl_basic_quote_charactersceZdZdZddZdS)_SavedReadlineSettingszQreadline settings that are backed up when switching between readline environmentsreturnNc0d|_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 -1rVN__name__ __module__ __qualname____doc__r_r`r^rUrUs.[[222222r`rUceZdZdZddZdS) _SavedCmd2EnvzVcmd2 environment settings that are backed up when entering an interactive Python shellrVNcdt|_d|_g|_d|_d|_dSN)rUreadline_settingsreadline_modulehistory sys_stdout sys_stdinr\s r^r_z_SavedCmd2Env.__init__s1!7!9!959"$ ,0+/r`rarbrgr`r^riris.``000000r`riDisabledCommandcommand_function help_functioncompleter_functionCmdceZdZdZd dZededefdZdede fd Z dede e j fd Zdeddfd ZdS) _CommandParsersz Create and store all command method argument parsers for a given Cmd instance. Parser creation and retrieval are accomplished through the get() method. cmdrvrVNc"||_i|_dSrk)_cmd_parsers)r]rys r^r_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..rX)rdreAttributeError)r}s r^_fully_qualified_namez%_CommandParsers._fully_qualified_namesC $/OO.2MOO O   22 s  !!cJ||}t|S)z Return 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)r]r}parsers r^ __contains__z_CommandParsers.__contains__s!.))F||r`cn||}|sdS||jvr|jtsdS|jt td}t |tjd}|j |p|j }|j ||}|dSddl m }||||j:t|dr*|jjrt%|jj|_||j|<|j|S)z Return 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. Nr_set_parser_prog __wrapped__)rr|rc startswithr(lengetattrrCMD_ATTR_ARGPARSERr{find_commandset_for_command _build_parser decoratorsr descriptionhasattrrrfrNr)r]r}full_method_namecommandparser_builderparentrrs r^rz_CommandParsers.getsR  55nEE 4 4= 0 0!*556IJJ t$-c2E.F.F.H.HIG$^Y5QSWXXNY::7CCPtyFY,,V^DDF~t        VW - - -!)gnm.T.T)YgYsY{)%:>;U;]%^%^".4DM* +}  !1222r`cV||}||jvr |j|=dSdS)z,Remove a given method's parser if it exists.N)rr|)r]r}rs r^removez_CommandParsers.remove!s<55nEE t} , , ./// - ,r`)ryrvrVN)rcrdrerfr_ staticmethodr%strrrrrargparseArgumentParserrrrgr`r^rxrxs ????kc\;4"3+"3(8;R2S"3"3"3"3H0[0T000000r`rxc*)eZdZdZejZdZejZ ej Z dddddddddddddddddd d e d e ed e ed e dede dedededede ee dede ee de ee de ee e fde eededededdf(fdZddd eed!edeefd"Zd#e de efd$Zdd%Zd&eddfd'Zd(ed)e eejegejfe e!fde ejfd*Z"dd+e d,e#d-e ddfd.Z$d/e d0e%ddfd1Z&d/e d2ed3ddfd4Z'd&eddfd5Z(d&eddfd6Z)d&eedfddfd7Z*d&eedfddfd8Z+e,defd9Z-e-j.d:eddfd;Z-e,de/e e0ffd<Z1d=e0ddfd>Z2d?e ddfd@Z3ddAZ4e,de5j6fdBZ7e7j.dCe5j6ddfdDZ7defdEZ8e,de fdFZ9dGddHdIe:e dJe;dKe dLe ee ge fddf dMZ<ddGdNdJe;dKe ddfdOZ=ddGddPdJe;dKe dQeddfdRZ>ddGdNdJe;dKe ddfdSZ?ddGdNdJe;dKe ddfdTZ@dGddPdJe;dKe dQeddfdUZAdGdNdJe;dKe ddfdVZBdGddWdJe;dKe dXeddfdYZCddZZDd[e d\ed]edeEee ee ffd^ZFd_e d[e d\ed]ed`ee dee f daZGd_e d[e d\ed]ed`ee dbe dee fdcZHdddd_e d[e d\ed]edeee eee e%ffdfedee e%fdee fdgZIdddd_e d[e d\ed]edhe/eeee e%ffdfe eee e%fdee fdiZJddjd_e d[e d\ed]edke ee gefdee f dlZKddmd_e d[e d\ed]ednedee f doZLd_e d[e d\ed]edpe%dee f dqZMeNdree deEee effdsZOdte duee dveddfdwZPduee ddfdxZQeNdyejdeeRjSfdzZT dd_e d[e d\ed]ed{e ejUddf d|ZV dd_e d}ed{e ejUde e fd~ZWdefdZXdefdZYe,dee e ffdZZdee fdZ[dee fdZ\dee fdZ]e^e_ddgdZ`deeafdZbe^e_ddgdZcdeeafdZde^e_dde_ddgdZedeeafdZfdee fdZgdee fdZhdede eiddfdZjdede eiddfdZkddZldeeme fdemfdZndedeeme fdefdZoddZpddZqd[e deEe e e ffdZrdddddd[e dededede edef dZsdede emdefdZtddddeeeuee fdededefdZvddd[e de edemfdZwddd[e de edemfdZxdemde e fdZydemdejzfdZ{demdejzddfdZ|de de e#fdZ}dddeeme fdedefdZ~demde efdZde de e fdZdejjddddddde de ee dejdede ee;de ede e%dye ejde fdZde de fdZdefdZdeddfdZdd„ZdZdZejeeŦZeddǦeedȦdejddfdʄZdZdZejeeŦZed?dͬΦeddegЦedejdeKӦeddeeΦdejddfdքZdZdZeje٦Zeddddݬަedejdebe`eddeeΦdejddfdZdZdZeje٦Zedejdebe`eddeeΦdejddfdZdZdZejeeŦZeddǦeedȦdejddfdZdZdZdZejeeŦZed?dΦeddegЦedejdeKӦeddeeΦdejddfdZdZdZeje٦ZeddddަedejdedeceddeeΦdejddfdZdZdZeje٦ZedejdedeceddeeΦdejddfdZd_e d[e d\ed]edee f dZd_e d[e d\ed]edee ee fdee f dZejd٦ZedddܐdަedejdeӦedejdeӦeejddeejdeedejddffd Zde de ee d ed eddf d Zdd e ee d eddfdZddeddfdZdeEee ee fee ee ee ffdZde dee deddfdZejd٦ZeeĦdejddfdZejdeŦZeeƦdejde efdZejd٦ZeeȦdejde efdZɐddee ee eeEe;e e ffde de;fdZd_e d[e d\ed]edee ee fdee f dZːdZejedZe͠dejd efeeejeg!ZeΠd"ejd#ed$eedȦdejddfd%Zejd&٦ZeРdd'eL(eРdejdeKӦeedȦdejddfd)ZeNdd*ZҐd+edefd,ZՐd-eddfd.Zdd/d0e e de efd1Zejd2٦Zeeئdejde efd3Zejd4٦Zeڠd5d6eK(eڠd7ejd8eKӦeeڦdejde efd9Zejd:٦Zeeܦdejde efd;Zݐddܐd?ަe᠖d@dAdܐdBަe᠖dCdDdEdFeKGe᠖dHdIdJdKeKGe᠖dLdMdܐdNަeߠdOPZe㠖dQdRdܐdSަe㠖dTdUdܐdVަe㠖dddܐdWަe㠖dddܐdXަdYZeߠdZeje[eeߦdejde efd\Zdejdd]fd^Zd_e ddfd`ZddaZdddeeeuee fdbe deddfdcZddZeje٦Ze렖deejdfeKӦeedejddfdgZddee e ddfdhZe,de e fdiZdjZeje٦ZedHdIdJdkeKGed5d6eK(eedejde efdlZeZedmz ZdnZejeeŦZededoΦeedejde efdpZdqee ddfdrZddse dte e ddfduZdte ddfdvZddwZdefdxZeNdye ddfdzZde ddfd{Zd|e ddfd}Zde d~e ddfdZd|e d~e ddfdZde;d~e de;ddfdZdde e defdZddZedede;fdeddfdZedegdfddfdZdegdfddfdZdegdfddfdZedeej gej fddfdZ deej gej fddfdZ e dZ edee ge fdee ddfdZdeejgejfddfdZdeejgejfddfdZedeejgejfddfdZdeejgejfddfdZdede;fdeeddfde efdZxZS(rvuKAn 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.tabNrXiFT)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 completekeystdinstdoutrrrrrrrrrrrrrrrrrVcV |st|dd| st|dd|t|||d|_| |_d|_d|_d|_tj |_ d|_ d|_ d|_d|_d|_t#|_d|_t)|_i|_|d|_d|_d d g|_d |_||_||d d g|_t#|_g|_ d |_!t#|_"d|_#tI|| ||_%d|_&g|_'tQj)|_*d|_+d|_,d|_-d |_.d|_/d|_0d|_1d |_2g|_3|rthj56thj57|}thj58|rRdtQj9|}|r|dttj;dthj<z }|j3=|d|_>| rotj@}|Adddd|B\}}|jCr||_>n&|r|j3D|n | r| |_>tjFGdrdx|_H|_Ind|_Hd|_I||_Jd|_KtjM|_Nt#|_Od|_PtjQ|_Rd|_Sd|_Td |_Ud |_Vg|_Wg|_Xd|_Yd|_Zt||_\|]||r|D]}|^||r|_|`D]6}|j%a|\}}|std|d |7||_cd!|_dd|_edS)"aUAn easy 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_scriptrXrnapp)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 {}?)fsetattr_initialize_plugin_systemsuperr_default_to_shellralways_show_hintdebugechorvDEFAULT_EDITOReditorfeedback_to_outputquietscripts_add_to_historytimingmax_completion_itemsdict _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_pyr<statement_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_sortedrx_command_parsers_register_subcommandsregister_command_set_autoload_commandsget_all_commandsis_valid_command ValueErrorrdefault_suggestion_messagecurrent_command)r]rrrrrrrrrrrrrrrrrrr script_cmdrcalloptscallargs command_setcur_cmdvaliderrmsg __class__s r^r_z Cmd.__init__;sCV ) D'4 ( ( ( * D(D ) ) ) &&((( [fMMM!&!2!&  ( "' &*# %'!04vv.3%9<$;=! $(  !&'=>(*$*C'   !8999&+I$6!)- ')$*. /#8JV_! ! !  !%')"'!2!4!4BF""(-$')#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 / '_.. >BVV!0!$ 9%)!$(  "&(".0+-"' $!0 5 5 ""4(((  7+ 7 7 ))+6666  &  # # % % %,,.. P PG 1BB7KKME6 P !N'!N!Nf!N!NOOO P(?$*<'59r`)subclass_matchcommandset_typer'c.fd|jDS)a Find 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|'|*Srg)type isinstance).0cmdsetr(r's r^ z(Cmd.find_commandsets..sJ   F||..>.jQWYhFiFi. ...r`)r)r]r(r's ``r^find_commandsetszCmd.find_commandsetss7     6    r` command_namec6|j|S)z Finds the CommandSet that registered the command name :param command_name: command name to search :return: CommandSet that provided the command )rr)r]r1s r^rzCmd.find_commandset_for_commands (,,\:::r`ctj}djDdtttddffd |dS)z!Load modular command definitions.c,g|]}t|Srgr+r-r"s r^r/z*Cmd._autoload_commands.. $g$g$g;T+%6%6$g$g$gr`commandset_typesrVNc|D]}|}|r |$tj|j}|vs@t |jdks(d|jvs|}|dS)Nrr])__subclasses__inspect signaturer_r parametersr)r8 cmdset_type subclassesinit_sigr.existing_commandset_typesload_commandset_by_typer]s r^rBz7Cmd._autoload_commands..load_commandset_by_types/ : : (7799  :++J7777&01EFFH#'@@@x233q88!)<<.r7r`z CommandSet z is already installedz,CommandSet settable prefix must not be emptyrDuplicate settable: zDuplicate settable z is already registered.ct|to.t|do|jt SNrcr,r rrcrr(meths r^z*Cmd.register_command_set..@z$'A'A(BD*--(BM,,-@AAr` predicateNc$i|] \}}|u || Srgrg)r-keyvalr.s r^ z,Cmd.register_command_set..s+,},},}(#sknv|k|k|S#k|k|k|r`),rr+r/rc settablesalways_prefix_settablessettable_prefixstripkeys on_registerrrrrr r r; getmembersrr'rr(_install_command_functionrr)_install_completer_functionr*_install_help_functionrrrCMD_ATTR_HELP_CATEGORYr categorizeaddr on_registered Exception on_unregisterdelattrrvaluesitemson_unregistered)r]r.rA all_settablesrQ prefixed_namemethodsr installed_attributes cmd_func_namer}rcompleter_func_name cmd_completerhelp_func_namecmd_helpattribs ` r^rzCmd.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,},},})  " " $ $ $  s5E2K))B1NrrcDd}t|tr|}nst|tr||}nHt |r |}n.t|t jrtj|}|Srk) r,r__func__ classmethodcallablerrcopydeepcopy)r]rrrs r^rzCmd._build_parsers59 nl 3 3 3#,,..FF  4 4 3#,,VJJFF n % % 3#^%%FF (? @ @ 3]>22F r`command_func_namer}contextc|tst|dtd|jtst|jdtd|t td}t ||rtd|d|d|j|\}}|std|d|||jvr!| d |d |j|=||j vr!| d |d |j |=t|||dS) an Install 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/rcrrrraliasespwarningrr)r]rxr}ryrr$r%s r^r[zCmd._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_namernct|z}t||rtd|t|||dSNr|)r)rr/r)r]rrnrms r^r\zCmd._install_completer_functionCsR3h> 4, - - b-.`K^.`.`aa a)=99999r`rp).Nct|z}t||rtd|t|||dSr)r*rr/r)r]rrpros r^r]zCmd._install_help_functionJsN)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)z} Uninstalls a CommandSet and unloads all associated commands :param cmdset: CommandSet to uninstall ct|to.t|do|jt SrHrIrJs r^rLz,Cmd.unregister_command_set..^rMr`rNN)r_check_uninstallablerc_unregister_subcommandsr;rZrr(r enable_commandrrcrrrr)rdr*rg)r]r.rjrlr}rs r^unregister_command_setzCmd.unregister_command_setQs T1 1 1  % %f - - -  " " "  ( ( 0 0 0D"2W"<===m,,,,  " " $ $ $  ( / / 7 7 7 7 7I 2 1r`cdtjddffd tjd}|D]7\}}||jkr'|j|}| |8dS)NrrVc|jD]v}t|tjrZ|jD]=}t |tjd}||urtd|>dSwdS)NzACannot uninstall CommandSet when another CommandSet depends on it) _actionsr,r_SubParsersActionchoicesrerrPARSER_ATTR_COMMANDSETr/)rr subparserattached_cmdsetcheck_parser_uninstallabler.s r^rz.check_parser_uninstallable~s /  fh&@AA%+^%:%:%<%<>> *1)Y=]_c*d*d*6?RX;X;X"= c##329====EE  r`ct|to.t|do|jt SrHrIrJs r^rLz*Cmd._check_uninstallable..s>:dH#=#=$>j))$> (()<==r`rN)rrr;rZrcrr)r]r.rjrlr}command_parserrs ` @r^rzCmd._check_uninstallable}s 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 jt |t j}|j |d\}}|s"tdt|d| } | d} | d d } | |j vr|j | j} n|| } | "td | d t||j| } | "td | d t|dt$jdt(tdt$jffd | | }t+t$j|||}d dlm}||| d||j |jrt7|j|_|jD]}t;|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||,|-t]|t j/|nd S)"z Register 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|tjSrkr,r rrSUBCMD_ATTR_NAMESUBCMD_ATTR_COMMANDrrJs r^rLz+Cmd._register_subcommands..T:dH#=#=$<i899$<i;<<$<i:;;r`rNT) is_subcommandz Subcommand z is not valid: rrNCould not find command '' needed by subcommand: &Could not find argparser for command 'r subcmd_namesrVc|s|S|d}|jD]S}t|tjr7|jD]\}}||kr||ccSnTtdd)NrzCould not find subcommand 'r{)poprr,rrrrfr/)rr cur_subcmd sub_action choice_namechoicefind_subcommandfull_command_names r^rz2Cmd._register_subcommands..find_subcommands#"!M)--a00 "(/J!*h.HII3=3E3K3K3M3MMM/K*j88'6v|'L'L L L L L L 9  22dPa2d2d2deeer`rrparentsprogusagerepilogformatter_class prefix_charsfromfile_prefix_charsargument_defaultconflict_handler allow_abbrevFadd_helprg)0rr/r;rZrrrrrrrrsplitr rscmd_funcrrrrrrrrrrrfrNrr,rSUBCMD_ATTR_ADD_PARSER_KWARGSrrrrrrrrr add_parserNS_ATTR_SUBCMD_HANDLER set_defaultsset_ap_completer_typeget_ap_completer_typerr)r]r.rj method_namemethodsubcommand_namesubcmd_parser_buildersubcommand_validr%command_tokensr1subcommand_names command_funcr target_parser subcmd_parserrradd_parser_kwargsattached_parserdefaultsrrs @@r^rzCmd._register_subcommandss< $&D,H"H"H-.kll l$ <<   $+X X  K#*693M#N#NO%,VY5R%S%S $+FI4P$Q$Q !'+'<'M'Momq'M'r'r $ f# o12mO@T@T2m2mek2m2mnnn.4466N)!,L-abb1 t555#5lCT #}}\:: #1b|bbUXY_U`U`bb"266|DDN%1p\ppcfgmcncnpp f(? ftTWy f]e]t f f f f f f f,ON0B%f-1>1D%g.7D7P%m42?2F%h/;H;X%&788E8R%n5ANAd%&=>.rr`rNNrrr)rr/r;rZrrrrr rsrrrrrr,rr remove_parser) r]r.rjrrrr1rrrs r^rzCmd._unregister_subcommandss $&D,H"H"H-.mnn n$ <<   $+   K%fi.HIIO"69+HIILt555#5lCT #}}\:: #2b|bbUXY_U`U`bb"266|DDN%2p\ppcfgmcncnpp)1  fh&@AA((999E3  r`c|jS)z Flags whether CommandSet settable values should always be prefixed :return: True if CommandSet settable values will always be prefixed. False if not. )rr\s r^rUzCmd.always_prefix_settables6s ,,r` new_valuec|js0|r.|jD]&}|jstd|jjd'||_dS)a Set 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)rrrVrr&rc)r]rcmd_sets r^rUzCmd.always_prefix_settables?sv,  7  .$?gFWF`??? )2%%%r`ct|j}|jD]?}|j}|D]!\}}|jr|||jd|<|||<"@|S)z Get 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)rrrrTrfrUrV)r]rhrcmdset_settables settable_namesettables r^rTz Cmd.settablesPsT_-- 3 < .get_allow_style_choices..}s$@@@CHNN$$@@@r`)r AllowStyle)rs r^get_allow_style_choicesz4Cmd.build_settables..get_allow_style_choices{s@@@@@ @r`valuec  tj|S#t$rGt dtjjdtjjdtjjdwxYw)z/Converts a string value into an ansi.AllowStylezmust be , z, or z (case-insensitive))rrupperrrALWAYSNEVERTERMINAL)rs r^allow_style_typez-Cmd.build_settables..allow_style_types u{{}}55    Et5EE9NEE/EEE s #&AA7 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)rvrrrrrrLrrrrr rint)r]rrs r^rzCmd.build_settablesxs> Ac Ad3i 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)zERead-only property needed to support do_set when it reads allow_stylerrr\s r^rzCmd.allow_styles r`new_valc|t_dS)zDSetter property needed to support do_set when it updates allow_styleNr)r]rs r^rzCmd.allow_styles#r`cb|jo(t|jottjkS)z*Return whether tab completion is supported) use_rawinputrrrGr@NONEr\s r^_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_stylepromptr\s r^visible_promptzCmd.visible_prompts ,,,r` endstyledestmsgrrc| ||n|} tj|||dS#t$r2|jr'tj|jYdSYdSwxYw)aA Print 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)r]rrrr final_msgs r^print_toz Cmd.print_tos #("3EE#JJJ  ;  "4I)>>        ! ! ! c9 % % !`d3ii.@``[^``IICI  4(33Iz 5g77_G +G44 4I I3E :::::r`c|js:|jr|||dS|||ddSdS)aFor printing 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 r^ 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) r]rrrfunctional_terminalrrr% pipe_procs r^ppagedz Cmd.ppaged%s:$$ :     +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!c:d|_d|_d|_d|_g|_g|_d|_d|_ttj krtj |j dSttjkr|jtjj_dSdS)zr Resets tab completion settings Needs to be called each time readline runs tab completion TrXFN)rrrrrrrrrGr@GNUrP#set_completion_display_matches_hook_display_matches_gnu_readline PYREADLINE_display_matches_pyreadlinerlmode_display_completionsr\s r^_reset_completion_defaultszCmd._reset_completion_defaults[s %)!#' !%'""$!!&# 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) agUsed by tab completion functions to get all tokens through the one being completed. :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 rNrXTzNo closing quotationrc6g|]}tj|Srg)r strip_quotes)r- cur_tokens r^r/z-Cmd.tokens_for_completion..s#LLLI%$Y//LLLr`) rvrQUOTESr=rrrrsplit_on_punctuation) r]r7r8r9rvunclosed_quote quotes_to_trytmp_line tmp_endidxinitial_tokensex raw_tokenstokenss r^tokens_for_completionzCmd.tokens_for_completionnsu  ! )"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)a Basic tab 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|]}||Srg)r)r- cur_matchrJs r^r/z&Cmd.basic_complete..s-WWWiI|S)a Performs tab completion against a list but each match is split on a delimiter and 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) rOrrr commonprefixrrrr)r]rJr7r8r9rKrPmatches common_prefix prefix_tokensdisplay_token_indexrN match_tokens display_tokens r^delimiter_completezCmd.delimiter_completesR%%dD&&-PP  ;%)D "G0099M)// ::M#$  =&)-&8&81&<#% ; ; (y99 ,-@ A $.$-M$++M::::r`)all_else flag_dictrZc0||||\}}|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 rrIrr,rrOru) r]rJr7r8r9r[rZrH_completions_matchesrKflags r^flag_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 } | |vr || } n|} 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 rr^) r]rJr7r8r9rcrZrHr_rSindexrKs r^index_based_completezCmd.index_based_complete8s4..tVVDD  IF a J  &u-MM$M mX . . @))$ffmTTGGm $ $ @#mD$??Gr` path_filterrhcdttffd }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} | rld_ t| d kr3tj| d rd_d_| jd_t)| D]\}}jtj|tj|rErC| |xxtjjz cc<j|xxtjjz cc<|r:|tjjkr|n|tjjzfd| D} rfd| D} | S)aPerforms 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 rVcTg}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_pathuserrncur_pwcur_useradd_trailing_sep_if_dirr]rJs r^complete_usersz)Cmd.path_complete..complete_users|sE |&&u-- 3 " 2 24 8 8 7==//'D., +LL&&& "llnn33Fw}}V]333#&#7#..t44368 (BGK 7!LL222 1-2)+0(Lr`FTrX*?rkrr>Nc*g|]}| |Srgrg)r-crhs r^r/z%Cmd.path_complete..s&<<g|]}|ddSrXrr )r-cur_path to_replaces r^r/z%Cmd.path_complete..s+WWW88++JA>>WWWr`c>g|]}|dS)rr)r-rexpanded_tilde_pathorig_tilde_paths r^r/z%Cmd.path_complete..s.mmmYa8++,?RSTTmmmr`)rrrrrrmgetcwdjoinrfindrdirnameglobrrlrrsortr r enumeraterrbasename)r]rJr7r8r9rhrxcwd cwd_added search_str wildcardswildcard sep_indexrSrerNrwrrrs`` ` @@@@r^ path_completezCmd.path_completels{ ! S ! ! ! ! ! ! ! ! H#( SYY  6CII#5#5$v,"'+:U:U&* #ikk   !bikk377JIIc I%  t##III$Js## ! IIbgk155 ??)>+++"$!3!3J!?!?J'+:I:&6O*,'*<*<_*M*M''W__T** !W\\")++zBB  )J''  "<<<<'<<%> ,1)+0( LLT2L 3 3 3"&D %.g$6$6 ? ? y$++BG,<,/// X"'+%%!$JJ!$rw{!2JWWWWwWWW# nmmmmmelmmmr`)complete_blankrc|s|sgS|ds'tjj|vrt j|S|||||dS)aPerforms completion of executables either in a user's path or a given path :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 complete_blank: If True, then a blank will complete all shell commands in a user's path. If False, then no completion is performed. Defaults to False to match Bash shell behavior. :return: a list of possible tab completions rkc~tj|ptj|tjSrk)rrrlaccessX_OK)rs r^rLz(Cmd.shell_cmd_complete..s-RW]]SWEXEXEt\^\efjlnls\t\tr`rg)rrrrmrget_exes_in_pathr)r]rJr7r8r9rs r^shell_cmd_completezCmd.shell_cmd_completes{ d Is##  4(?(?)$// /%%dFF8t8t& 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)aCalled by complete() as the first tab completion function for all commands 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) rIrrREDIRECTION_TOKENSREDIRECTION_PIPErrREDIRECTION_APPENDrr)r]rJr7r8r9rr_rGhas_redirectionin_pipe in_file_redirdo_shell_completiondo_path_completion prior_tokenr=s r^_redirect_completezCmd._redirect_completes224HH : I z??Q  #OG!M"' !& K'! (! (  <<<&*O!I$>>>&)*DDD#%III"&(- ')*FFF-F#%III"'(, +2*/').&"i&@@@.2++ 2KI4PR[Rn3o$o$o-1*' " ..tT66JJJ# ))$ffEEE!  xdFF333r`matches_to_displaycttjkrdnttjkrdn|dfSfd|Dt fS)a}Adds 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|]}|zSrgrg)r-rNpaddings r^r/z/Cmd._pad_matches_to_display..xsHHH G#HHHr`)rGr@r.r1r)rrs @r^_pad_matches_to_displayzCmd._pad_matches_to_displaydsa fj GG ) ) )GG&q( (HHHH5GHHH#g,,VVr` substitutionrSlongest_match_lengthc Rttjkrd}|jr0|jr)d}t jd|jz|jrL|st jdt jd|jzdzn|j r+|j }d}|D]}tj |}||kr|}n|}| |\}}||z }t|d} d|D} ttt tt#jd t'| zd zz} | | d<| | d d <d | d <t)j| t'| |t-d Sd S) aPrints 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-rNs r^r/z5Cmd._display_matches_gnu_readline..s%"j"j"j)5W#E#E#E"j"j"jr`rr>N)rGr@r.rrrrrrrrstyle_aware_wcswidthrrrrrctypesc_char_prrRrl_display_match_listrQ) r]rrSr hint_printedrrN cur_lengthpadding_lengthencoded_substitutionencoded_matches strings_arrays r^r0z!Cmd._display_matches_gnu_readlinezs fj  L$ >)= >#    (> %)%>y%I%I %(<<<3=0> *1&6:5Q5QRd5e5e2"N$6$(-\G'L'L'L$"j"jWi"j"j"j!%T(5/%:V_PQTWXgThThPhklPl=mrr)rHrrFc3K|]}d|vV dSrNrgr-matchs r^ z*Cmd._perform_completion..s'FvFvX]se|FvFvFvFvFvFvr`Tc3K|]}d|vV dSrrgrs r^rz*Cmd._perform_completion..s&*]*]E3%<*]*]*]*]*]*]r`c3K|]}d|vV dS)"Nrgrs r^rz*Cmd._perform_completion..s&MME3%<MMMMMMr`r{rcg|]}|zSrgrg)r-rcompletion_token_quotes r^r/z+Cmd._perform_completion..s .s.s.sRW/E/M.s.s.sr`c>g|]}|ddSrr)r-rtext_to_removes r^r/z+Cmd._perform_completion..s**u*u*uTY5==Q+O+O*u*u*ur`)*rparse_command_onlyrcommand_and_argsisspacerrstriprIrrrrrr)rrrCMD_ATTR_PRESERVE_QUOTESrr functoolspartialcompletecompletedefaultrrrrpreserve_quotesr?rfindrrremove_duplicatesrrvrrrRranyr)r]rJr7r8r9rr statement expanded_line rstripped_lendiffrHrGcompleter_func func_attrfunc argparserrrrrYraw_completion_token actual_begidxrv add_quoterTdisplay_prefixrrs @@r^_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****.)= (:W8Nw8W8W-W-W%)%7NN%)%9NN ">>?UVVN&'=tDDI&."9X+d::^dnrN  *"~"$  '$8$;y?O$O$O&:!%< "!&M//r ;;M&&!%mF&:!;&,&#'"9"9$ffVd"e"e  "0 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\*]*]*]']']% $ItMMT5LMMMMM514..14..s.s.s.s[_[r.s.s.sD+  v*u*u*u*u]a]t*u*u*u'4*++q00T5M0Rh0'***.DD*****a0 E0 E^100000r`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)uGOverride 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 rrXNFrrCOMMANDzcommand, alias, or macro name)metavarrrcg|]}|zSrgrg)r-rshortcut_to_restores r^r/z Cmd.complete..s.p.p.pu/BU/J.p.p.pr`rrr}Tr)'r6rrlstriprPget_line_bufferr get_begidx get_endidxmaxrrrrrr/_get_commands_aliases_and_macros_for_completionrCustomCompletionSettingsrrrrrr r IndexErrorr0rr rr rrrrQrbr r)r]rJrrlstripped_previousr7r8r9 orig_line num_strippedshortcutr_rrFerr_strrs @r^rz 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 runningN)_current_script_dirr\s r^r$z Cmd.in_script s't33r`c|jS)z8Return whether running inside a Python shell or pyscript)rr\s r^r#zCmd.in_pyscript s {r`c|jjS)zFRead-only property to access the aliases stored in the StatementParser)rr~r\s r^r~z Cmd.aliases s$,,r`c t|S)zZReturn an alphabetized list of names comprising the attributes of the cmd2 class instance.)dirr\s r^ get_namesz Cmd.get_names s4yyr`cDfdDS)zReturn a list of all commandscg|]_}|tj!tt |>|t tjd`Srk)rrr(rurrr-rr]s r^r/z(Cmd.get_all_commands.. st   y<== CK7SWY]K^K^B_B_ Y23355 6   r`r r\s`r^rzCmd.get_all_commands s8    ((    r`cDfdDS)z?Return a list of commands that have not been hidden or disabledc8g|]}|jv |jv|Srgrr )r-rr]s r^r/z,Cmd.get_visible_commands..% s>   d222wdF\7\7\ 7\7\7\r`)rr\s`r^get_visible_commandszCmd.get_visible_commands# s:    0022    r`ValuePwidth divider_charc g}|jD]K}|j|g}|t||j|L|S)z8Return list of alias names and values as CompletionItems)r~rr"_alias_completion_tablegenerate_data_rowr]resultscur_keyrow_datas r^_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)z8Return list of macro names and values as CompletionItems)rrrr"_macro_completion_tablerrs r^_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)zJReturn list of Settable names, values, and descriptions as CompletionItems)rT get_valuerrr"_settable_completion_tablerrs r^_get_settable_completion_itemsz"Cmd._get_settable_completion_itemsH sw(*~ q qGw/99;;T^G=T=`aH NN>'43R3d3dem3n3noo p p p pr`ct|}t|j}t|j}t ||z|zS)zIReturn a list of visible commands, aliases, and macros for tab completion)rrr~rlist)r]visible_commands alias_names macro_namess r^rz3Cmd._get_commands_aliases_and_macros_for_completionR sSt88::;;$,'' $+&& ${2[@AAAr`c`fdD}fd|DS)zReturn a list of help topicscg|]_}|tj!tt |>|t tjd`Srk)rrr*rurrrs r^r/z'Cmd.get_help_topics..[ st   y9:: @HPTVZH[H[?\?\ Y/0022 3   r`c8g|]}|jv |jv|Srgr)r-topicr]s r^r/z'Cmd.get_help_topics..b s5{{{%d>R1R1RW\dhdzWzWzWzWzWzr`r)r] all_topicss` r^get_help_topicszCmd.get_help_topicsY sR    ((   |{{{:{{{{r`signumr_c|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)r]r7r_raise_interruptr"s r^r:zCmd.sigint_handlerd 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)r]r7r_s r^termination_signal_handlerzCmd.termination_signal_handlerz s vr`c td)z,Helper function to raise a KeyboardInterruptzGot a keyboard interrupt)KeyboardInterruptr\s r^r;zCmd._raise_keyboard_interrupt s :;;;r`rcNt|tst|n|S)a Hook method executed just before the command is executed by [cmd2.Cmd.onecmd][] and after adding it to history. :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,r;)r]rs r^precmdz Cmd.precmd s',6i+K+KZy###QZZr`stopc|S)aHook method executed just after a command is executed by [cmd2.Cmd.onecmd][]. :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. rg)r]rErs r^postcmdz Cmd.postcmd s  r`cdS)aHook method executed once when the [cmd2.Cmd.cmdloop][] method is called. See [cmd2.Cmd.register_preloop_hook][] for a more robust way to run hooks before the command loop begins. See [Hooks](../features/hooks.md) for more information. Nrgr\s r^preloopz Cmd.preloop s  r`cdS)aHook method executed once when the [cmd2.Cmd.cmdloop][] method is about to return. 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. Nrgr\s r^postloopz Cmd.postloop s  r`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)r]r7rs r^ parselinez Cmd.parseline s/)<r |j|_ d}Yd}~nCd}~wtB$r }|j"d}~wtF$r}|$|Yd}~nd}~wwxYw |%||}nF#t6$r}|r|s|Yd}~n0d}~wt8$r2}t;|jt>r |j|_ d}Yd}~nd}~wtB$r }|j"d}~wtF$r}|$|Yd}~nd}~wwxYw# |%||}w#t6$r}|r|s|Yd}~wYd}~wd}~wt8$r2}t;|jt>r |j|_ d}Yd}~wd}~wtB$r }|j"d}~wtF$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 rNFrRrOz Elapsed: TzInvalid syntax: )&datetime_input_line_to_statementrPostparsingData_postparsing_hooksrErr2rr pause_storage_redirect_outputnowPrecommandData _precmd_hooksrDonecmdPostcommandData_postcmd_hooksrGrr_restore_outputr5r.r r4rB SystemExitr,coderrr3 wrapped_exrbr_run_cmdfinalization_hooks)r]r7rOrPrQrRrVrErpostparsing_datapostparsing_funcredir_saved_state timestart precmd_data precmd_func postcmd_data postcmd_funcrFs r^onecmd_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%-1133 %3I>> #'#5;;K"-+k":":KK'1 !KK 22 {{9^{LL &5dIFF $($7>>L#/< #=#=LL$(||D)44;VNN#Tx/@/D/D/F/F/R#T#TUUU+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#   -     LL          !66tYGG$   +DH   bgs++-%'WDN' $ $ $m# ! ! ! R         ! !66tYGG$   +DH   bgs++-%'WDN' $ $ $m# ! ! ! R         ! sA#H6.G+5$B% G+%B))G+,B)-C8G+%H6,'G H6G##H6&G#'H6+H23'H& H2&H* *H2-H* .H22H65O6L(O L(I/*O/ L(<JO L(#J.)O. L(;(K(#O( L(5K<< L( L#O#L((O,M OM O'(N O!N(( O5OORO0/R0 R:P  R R(Q?R RQ R%Q?:R?RRcp|j5tjdsH|jr/ddl}|ddg}|dddn #1swxYwYtj ||}|j D] }||}|j S)z"Run the command finalization hooksrrNsttysane) rrrrrr!r%r&r(rCommandFinalizationData_cmdfinalization_hooksrE)r]rErr%procdatars r^rfzCmd._run_cmdfinalization_hooksL s  # # #<**511 #dj6G6G6I6I #"!!!!''(899  """ # # # # # # # # # # # # # # #-dI>>/  D4::DDysA(A<<BBrOstop_on_keyboard_interruptcmdsrxc2|D]}t|tr|j}|jr||j| ||||rdS`#t$r'}|r||Yd}~n Yd}~d}~wwxYwdS)a Used when commands are being run in an automated fashion 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 rOrPTNF) r,r7rawrrrrorBr )r]ryrOrxr7rFs r^runcmds_plus_hookszCmd.runcmds_plus_hooks^ s$  D$ ,, xy 5  3T33444 ))Rl*  44 %   -KKOOOEEEEE  usA## B-BBrTcdtddffd } |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 rrVNcP|jsdStjkr?tjtjdz tjk?t |}dks|tjkrtj|dSdS)zMCombine all lines of a multiline command into a single readline history entryNrr)multiline_commandrPget_current_history_lengthremove_history_itemr8get_history_item add_history)rformatted_commandrRs r^combine_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^CrXF)r;rparser terminatorr.rrr_read_command_linerrrBrr2)r]r7rRrrnextlines ` r^_complete_statementzCmd._complete_statement 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  *   y ) ) )sA(AA,A65A6:A7C21E29D5+E4D55E E c g}d} |||}| |j}d}|j|jvrD|j|vr;||j||}|t|}nn||jkrFt|j ||j|j |j |j |j |j|j|j }|S)a Parse 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 NTrT) r|rarg_listrrsuffixpipe_tooutput output_to)rr|rrrXr_resolve_macror2r;rMrrrrrrr)r]r7rR used_macrosrrresolve_results r^rWzCmd._input_line_to_statement s   00Nd0eeI %M )-& DK$4$4$6$6669;LT_;_;_""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)z Resolve 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 macrorrXsz The macro 'z' expects at least z argumentNc|jSrk) start_index)mas r^rLz$Cmd._resolve_macro..) sr`T)rQreversez{{z}}{})maxsplitrr)rrrXrrrminimum_arg_countr rsorted is_escaped number_strargvrrsplit post_command) r]rmacropluralresolvedreverse_arg_list macro_argr replacementpartsstmt_args r^rzCmd._resolve_macro s  DK$4$4$6$6 6 6i/@@@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}ddl}tjt t |jtj|j|j }d}|j sn>|j rtj \}}||d}t t ||d} t} tjdkr |j| d<n+d| d<tjd } | r| | d <|j|j f|t+|jtjr|jn|jt+tjtjr|jn tjdd | } | d n#|j$rYnwxYw| j@|| t;d | jdd|_tj| t t |jtj}| xt_|_nS|j rK|j!r|j tDj#krdnd} t t ttj$|j!| d} n$#tJ$r}t;d|d}~wwxYwd|_| xt_|_n|j&st;dtO}t t tQj)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 rNrwwin32 creationflagsTstart_new_sessionSHELL executable)rrrrg?zPipe process exited with code z before command could runar)r4 bufferingzFailed to redirect because: zClipboard access not allowedzw+)r4),ior%rRedirectionSavedStaterrrrrrrrrpipeopenrrCREATE_NEW_PROCESS_GROUPr"rr&r,StdSimr'rwaitTimeoutExpired returncodecloser4 redirecting ProcReaderrrrrr<OSErrorrr#tempfile TemporaryFilerflush)r]rrr%ricmd_pipe_proc_readerread_fdwrite_fd subproc_stdin new_stdoutkwargsrrur4rFcurrent_paste_buffers r^r[zCmd._redirect_output= s  "7  % %sz43MtO`   <@%Y (   U ( " GXGGGS11M!%fbggh.D.D!E!EJ &*VVF|w&&*4*M''.2*+ w//1+0F<($:#!#*4T[%,*O*O`zUYU`*4SZ*N*N^zTWT^   D  #,    *##%%%  """&'r'r'r'rsss04!-','7d64;>W>WY\Yc'd'd$+55 T[[  " ("! ((.)2NNNssTWP!%fd53EiFY3Z3Zaeqr.s.s.s!t!tJJPPP*+N"+N+NOOOP15!-+55 T[[ +K*+IJJJ(8'9'9$!&(*@d*K*K*KLL 04!-+55 T[#y'CCCK%%&:;;;K%%'''&:"-9  s*F F$#F$+=A>rctj|z}t||d}t|rt t |ndS)z Get the function for a command :param command: the name of the command Example: ```py helpfunc = self.cmd_func('help') ``` helpfunc now contains a reference to the ``do_help`` method N)rr(rrurr%)r]r func_namers r^rz Cmd.cmd_func sB1G; tY--*24..BtK&&&dBr`rUct|ts||}||j}|r_|j|jvr*|j|jvr|r|j| ||_ ||}d|_ n!#d|_ wxYw| |}||ndS)aThis executes the actual do_* method for a command. If the command provided doesn't exist, then it executes default() instead. :param statement: intended to be a Statement instance parsed command from the input stream, alternative acceptance of a str is present only for backward compatibility with cmd :param add_to_history: If True, then add this command to history. Defaults to True. :return: a flag indicating whether the interpretation of commands should stop NF) r,r;rWrrrr rnrrdefault)r]rrOrrEs r^r_z Cmd.onecmd s)Y// A55i@@I}}Y.//  +!)BBB%T-CCC"D ##I... ,'0$tI'+$$t$++++<< **D'ttU2s B B#c|jr=d|jvr|j|||jS|j|j}|j r<| |jx}r |d|j |z }| |ddS)zExecuted when the command given isn't a recognized command implemented by a do_* method. :param statement: Statement object with parsed input rrFr N) rrrnrdo_shellrrformatrr_suggest_similar_commandrr )r]rerr_msgsuggested_commands r^rz Cmd.default s  d777 ##I...==!;<< <(// 0ABBG+ \dFcFcdmduFvFv1v1B \[ ? F FGX Y Y[[[ KKUK 3 3 34r`cFt||Srk)rOr)r]rs r^rzCmd._suggest_similar_command sw(A(A(C(CDDDr`)rncompletion_moderrrrYrrrnrrrrrYc  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) a Read 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() FNrVcT 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 historyNrJrrVcdSrkrg)rJrs r^ complete_nonezACmd.read_input..configure_readline..complete_noneY s#tr`FrargT)suppress_tab_hintrrrYr)rr)rGr@rrrP get_completerrCompletionModerrrCOMMANDSrrrrrrr set_completerrangerrr clear_historyr)r complete_funcriitemrrrYrrnrrreadline_configuredsaved_completer saved_historyr]s r^configure_readlinez*Cmd.read_input..configure_readlineH 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 historyNF)rGr@rrrPrrr)rrrrr]s r^restore_readlinez(Cmd.read_input..restore_readline s' 'V[*@*@))++ 8&777(&((()//D(...."'   r`rrXrrrz ra)rrrr!rArinputrrrrrrPrr)r]rrnrrrrrYrrrescaped_promptr7rrrs` ``````` @@@r^ 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  "" ! V ,,, !!###z**,,t99>> D z**,,t99!y8 %6%6%6777 D{{6"""sfC' A>2 C>BCBC B66B:=B:C. C" C."C& &C.)C& *C.ch |jn#t$rYnwxYw||tjj|jS#t$rY|jdSwxYw#|jwxYw)a  Read 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 )rr) r release RuntimeErrorrrrracquireEOFError)r]rs r^rzCmd._read_command_line s ) "**,,,,    ??65;O;X?YY   & & ( ( ( (       & & ( ( ( ( (     & & ( ( ( (s9A, *A,*(A,, B6BBBB1c$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)z Called at beginning of command loop to set up readline with cmd2-specific settings :return: Class containing saved readline settings zset horizontal-scroll-mode offNz rXz : complete)rUrGr@r.rPparse_and_bindrrrrrSc_void_prr[rrYrrrrr?REDIRECTION_CHARSrrget_completer_delimsrZset_completer_delimsr)r]rlcompleter_delimss r^_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`rlcr|rtj|jtj|jt tjkr'tj d|j t_ dSt tj krttjj_dSdSdS)z Called at end of command loop to restore saved readline settings :param readline_settings: the readline settings to restore N)rrPrrYrrZrGr@r.r/r[rSrr1rr3r4r5)r]rls r^_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)nargsrrYaliascreatecd|_|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) rFzInvalid 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_tokensrrrr~r)r]rMr$r%tokens_to_unquoterresults r^ _alias_createzCmd._alias_create` 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)rrrdescriptive_headerdeletecd|_|jr0|j|ddS|js|dd|_dStj|jD]F}||jvr"|j|=|d|d-|d|dGdS) zDelete aliasesTzAll aliases deletedz/Either --all or alias name(s) must be specifiedFr! ' deleted' does not existN) rallr~r rr'r rrr]rMcur_names r^ _alias_deletezCmd._alias_delete 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-cti|_tj}||jj|jrtj|j}nt|j |j }g}|D]}||j vr| |!t|j |}|d}|dd}tj|||} |r| dd|zz } |d|d| | |j|<|D]}|d|ddS) z3List some or all aliases as 'alias create' commandsr}rrNrz alias create r! ' not found)rrrrrrr'rrrr~r rr=quote_specific_tokensrrr  r]rMtokens_to_quoteto_list not_foundrrHrrrRs r^ _alias_listzCmd._alias_list sp#6t4@AAA : F-dj99GGT\t/DEEEG!  ) )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)z Manage macrosNrrs r^do_macroz Cmd.do_macro rr`zcreate or overwrite a macroCreate 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| | | |kr| }|t%| | d n#t:$rYnwxYwt=| |kr|d |d dSt!jt$j|} | } t!jt$j| d} |t%| | d n#t:$rYnwxYw|j|j vrdnd}|!d|jd|tE|j||||j |j<d|_dS)r;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 placeholdersrr Macro 'r")rrrr)#rrrrr rr~rrrrrr#rrrrefinditerr:macro_normal_arg_patternr__next__findall digit_patterngrouprr`rstart StopIterationrmacro_escaped_arg_patternrrr9)r]rMr$r%r$rrnormal_matches max_arg_numarg_numsrN cur_num_strcur_numescaped_matchesr%s r^ _macro_createzCmd._macro_create sx!->>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  *3355 !j)?ARARSSTUV k**Q;;KK IJJJF W%%%[((")KY__5F5FS^kp q q qrrrr     # * x==K ' ' KKoooo p p p F+h&H%PP  +4466 !j)?ARARSSTUV Y__5F5FS^ko p p pqqqq      #')t{":":  4ty44F44555!&DIUValt!u!u!u DIs-A5H:AH HH/BK22 K?>K?z 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) z Delete macrosTzAll macros deletedz/Either --all or macro name(s) must be specifiedFr=r+r,N) rr-rr rr'r rrr.s r^ _macro_deletezCmd._macro_delete~s  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|j}nt|j |j }g}|D]}||j vr| |!t|j |j}|d}|dd}tj|||} |r| dd|zz } |d|d| | |j|<|D]}|d|ddS) z2List some or all macros as 'macro create' commandsr}rrNrz macro create r=r2)rrrrrrr'rrrrr rr=rr3rrr r4s r^ _macro_listzCmd._macro_listss#6t4@AAA : E-dj99GGT[d.CDDDG!  ) )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)rr6rr-rO)r]rJr7r8r9topicsr. strs_to_matchs r^complete_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 helprrN subcommands)rrrrrcomplete_subcommand_help) r]rJr7r8r9rWrrrrYs r^complete_help_subcommandszCmd.complete_help_subcommandss Y'* IMM'** *D 3TEZE^E^_cEdEd8d 7mI&;ItLL 11$ffjYfNghhhr`GList available commands or provide detailed help for a specific commandz-vz --verbosez6print a list of all commands with descriptions of eachzcommand to retrieve help forrYz"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)r\TNrXrFr)rrverbose _help_menurrrr*rrrrr format_helprYrdo_helprfpydocgetdocrrr )r]rMr help_funcrrYrr&s r^rbz 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)a Print 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 rX) fill_charrrN)rrulerr align_leftr widest_line columnize)r]rfryrgrhdividers r^ print_topicszCmd.print_topicss   LL z &*24K[\bKcKcddd W%%% NN4! , , , LLNNNNN   r`str_list display_widthc ds|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]0} | || zz} | |krd } n| } || 1|r|d s |d =|r|d  tt|D]'} tj || ||  || <(|d |dS) a.Display 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| Srg)r,r)r-rrqs r^r/z!Cmd.columnize..3s.ZZZAZQR UX=Y=YZaZZZr`z"str_list[i] not a string for i in rrr]rXr>rr) rrr TypeErrorrrrrrrlr)r]rqrr nonstringssizenrowsncols colwidthstotwidthcolcolwidthrowrxtextss ` r^rnz Cmd.columnize(s  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||  %#+%99AA  A Q b  "I b  SZZ(( P P"-eCj #OOOc LL5)) * * * * + +r`r_cR|\}}}}|s7||j||j||n||j||jdt ||jD]}||||| ||j||| |j |dd| |j |dddS)z7Show a list of commands which help can be displayed forrrr}rN) _build_command_infor doc_leader _print_topicsrrrXr r rp misc_header undoc_header)r]r_ cmds_catscmds_doc cmds_undoc help_topicscategorys r^r`zCmd._help_menuas*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)Nr}F)rr6r rrr%rrrrrr^r setdefaultrrf) r]rr.rrrrr has_help_func has_parserrs r^rzCmd._build_command_infotsfT11339NOOO "$";";"="=4CXYYY  " *, ' + +G T]]7%;%;<> + 'i.N O O$$Xr222(#**73333 + +* +((((!!'****(J ;;r`cddl}|rT|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#|5|j} t't(||_|||_n #||_wxYw dddn #1swxYwY|}n| j}|rt/|nd}|| |g}| |d z<|| dSdS) zXCustomized version of print_topics that can switch between verbose or traditional outputrNrrc6g|]}tj|Srgrr)r-rs r^r/z%Cmd._print_topics..s#UUUWd7@@UUUr`rXrrr)rrprrJrKrkStringIOrgenerate_dividerr6rrrrrrr*rrrrgetvaluerfrNrr)r]rfryr_rwidest name_column desc_column topic_table table_str_bufrorTrr cmd_parserdocrer% stdout_origcmd_desc table_rows r^rzCmd._print_topicss > 7= 7!!&$B77777UUPTUUUVV%Rs62??? $Rr222 ); *DSWS]^^^ !# 7!'' 666%66888!''$777--//#$:$:G$(MM'$:$::C '+&;&?&?&I&II V(4!F**$+D)2Lw2V$W$W !#-V44 : :*.+K:.266.B.B ) /: k 9 9 9 9  : : : : : : : : : : : : : : :%oo//'.>AH4S999bH!, = =w>Q R RI!'' D(89999 ]335566666}> 7> 7s*:G$F/'G/ F88GG G List available shortcutsctjjfd}dd|D}d|d_dS)rc:|dS)Nr)r )rr]s r^rLz"Cmd.do_shortcuts..sQUQfQfghijgkQlQlr`r}rc3ZK|]&}d|d|dV'dS)z{}: {}rrN)r)r-scs r^rz#Cmd.do_shortcuts..s8TTR8??2a5"Q%88TTTTTTr`zShortcuts for other commands: TN)rrrrrr)r]r_sorted_shortcutsr%s` r^ do_shortcutszCmd.do_shortcutssr"$"7"AGlGlGlGlmmmTTCSTTTTT ?v??@@@r`zCalled when Ctrl-D is pressedcT||dS)z Called when Ctrl-D is pressed and calls quit with no arguments. This can be overridden if quit should be called differently. rX)rdo_quitr]r_s r^do_eofz Cmd.do_eofs% ||Br`Exit this applicationcd|_dS)rT)rrs r^rz Cmd.do_quits tr` Your choice? optsc Rt|tr}tttt t tftt| | }n|}g}|D]}t|tr| ||f/ | |d|dfT#t$r&| |d|dfYwxYwt|D]%\}\}}| d|dz|fz& ||} nJ#t$rd} | Yn(t $r} | d| d} ~ wwxYw| se t#| } | dkrt|| dz dS#t$tf$r,| d| d t'|d YnwxYw) aPresents 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 userrrz %2d. %sTrXrNr{z4' isn't a valid choice. Pick a number between 1 and :)r,rrrrr rr-ziprrrrrrrrBrrr) r]rr local_opts fulloptionsoptidxr_rJresponserFrs r^selectz Cmd.selectsp 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% tsB #C---DDE-- F4 F4F//F4;,G((:H%$H%c |dd} |j|}n #t$rt|dzwxYwtjt jg}d} || | |j|j |j |j tj ||} ||||\} } | ||||| ddS) z#Completes the value argument of setparamrrrr)rrrrrYrN)rTrr0rrrvset_parser_parentrrrrrYrrrIr) r]rJr7r8r9rWrrsettable_parserarg_namerYr_rGs r^complete_set_valuezCmd.complete_set_value+s 7#A& J~e,HH J J J!%*H"HII I J*A3K`Jabbb$$ %$%6( %   ';OTRR 224HH :!!$ffjnMMMs ;zSet 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)rrrYrc0d|_|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 parametersFz There are no settable parametersNz Parameter 'z4' not supported (type 'set' for list of parameters).z - was: z now: TzError setting z: Namec6g|]}tj|Srgr)r-rs r^r/zCmd.do_set..s#TTT5d7>>TTTr`rrr%r&r'rr})rrTrrrr rr) set_valuerr<rrbr-rXrrrrJrKrkgenerate_headerrr rr) r]rMr orig_valuerFto_show name_labelmax_name_widthcolstablerr s r^do_setz Cmd.do_setas!~  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)(Execute a command as if at the OS promptzthe command to run)rrYc dddl}ddl}t}tjdrd}n5|jjdz}tj d}|r||d<|j g|j z}tj|d|}|j5|j|ft%|jtjr|jn|jt%tjtjr|jn tjd d |} tj| t1t2|jtj} | | j|_| j|kr|ddddS#1swxYwYdS) rrNrl:r>rrrT)rrr)signalr%rrrrSIGINTrrr"rrrrexpand_user_in_tokensrrr&r,rrr'rrrrrrrr;) r]rMrr%rctrl_c_ret_coderrHexpanded_commandru proc_readers r^rz Cmd.do_shells  !% < " "5 ) ) -(OO%m1B6OJNN7++E -',|$,$"33 #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*F%%F),F)cgd}|D] } tj|=#t$rYwxYwtjt_tjt_dS)a Resets 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)r__dict__r__displayhook__ displayhook__excepthook__ excepthook) attributescur_attrs r^_reset_py_displayzCmd._reset_py_displaysj+** "  H L**    -+s  %%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)zy Set up interactive Python shell environment :return: Class containing saved up cmd2 environment r gnureadlinerPNz!from rlcompleter import Completerzimport readlinez4readline.set_completer(Completer(locals()).complete))-rirGr@rrrPrrnrrrrrrr.rrrrSrrrlr[orig_rl_basic_quotesrmodulesrmrrZrorig_rl_delimsr/r1rr3r4r5rrYruncoderrrorrp)r]rcmd2_envrrs r^_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) a 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 FrVNct)zNFunction callable from the interactive Python console to exit that environment)r1rgr`r^py_quitz Cmd._run_python..py_quitcs% %r`rPyBridgeTrU=Recursively entering interactive Python shells is not allowedrXquitr?r]zError reading script file 'r__main__rc__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...ra)!r py_bridgerrr#r rrrvrrrrrrrrrrr-insertrrrr BaseExceptionversionrrinteractrrrE)r]rrrrOrsaved_sys_pathpy_code_to_run local_varsexpanded_filenamefrFrcprt instructionsrsaved_cmd2_envs r^ _run_pythonzCmd._run_pythonWs! & & & &      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)zj Run an interactive Python shell :return: True if running of commands should stop )r rs r^rz 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 zt_ | |j }|t_ n#|t_ wxYw|S) zw Run a Python script file inside the console :return: True if running of commands should stop F.pyr{z' does not have a .py extensionYes Noz.Continue to try to run it as a Python script? YesNr) rrrrr endswithrrrrr r )r]rM selection orig_args py_returns r^do_run_pyscriptzCmd.do_run_pyscripts!7--d.>??((//  MMOd.OOO P P P H.^__IE!!tH  !()D,AACH(($2B(CCI!CHHyCH s 5CC$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)zn Enter an interactive IPython shell :return: True if running of commands should stop FrNr>)TerminalInteractiveShell)TerminalIPythonAppz IPython package is not installedrrrTr]zVEntering 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#rrrvrrConfigInteractiveShellbanner2rclear_instancerE) r]r_TraitletsLoaderr?rrrrrrs r^rz 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)rrrYrz --transcriptTRANSCRIPT_FILEzoutput 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)rrc  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)z View, 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)rrJrrrrXrz commandz saved to zError saving history file ')scriptexpandedr_)1rr_r edit output_filerun transcriptr.r-rhistory_parser format_usagernrrrFileNotFoundErrorrr rGr@rrPr _get_historyrr}r-rermkstempfdopenrrrr| run_editor do_run_scriptrrrrrrrr_generate_transcriptrfpr)r]rMrFrnrEfdfnamefobjr full_pathrrrhis r^ do_historyzCmd.do_historyys! < 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/) rrrrnrrspanr-rr regex_search str_search)r]rMint_argrns r^r6zCmd._get_historys$ 8 7 dh--"GT\-=-=g-F-F#GHHH    tx3$(??,++DHdh??$$T** Ftx/@/@/F/F F,33DHdhGG,11$(DHEEl''TX66Gst@j!krc|jD]]} tE| j#} tIj%} | d ks| tIj&| krtIj'| \dSdS)aLInitialize 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 'rrbz%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 ')(r6rnrrrrrrlr rmakedirsrrrr5ratexitregister_persist_historylzma LZMAErrorModuleNotFoundErrorbz2r decompressdecodejson from_jsonJSONDecodeErrorr start_sessionrGr@rr8rrPrrr)r]rI hist_file_dirrFr?compressed_bytesrNdecompress_libdecompress_exceptions history_jsonrWrrcur_history_lengths r^rzCmd._initialize_historysRyy  +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;;  / / / / / / / / / / / / / / /  ' ' '$ww       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 krd}nd}||d|d|dd|_dS#t@$r&}| d|d|Yd}~dSd}~wwxYw)z;Generate a transcript file from a given history of commandsFr{z3' is not a directory or you don't have write accessNrrXTrr{rrDz\/zCommand z7 triggered a stop and ended transcript generation earlyrzcommand and its outputzcommands and their outputsrz saved to transcript file 'zError saving transcript file 'r)!rrrrrrrlrW_OKr rrrr,r7r| splitlinesrrrrrrrorBrr rrrrrr)r]rnrgrOtranscript_pathtranscript_dir commands_run saved_echo saved_stdoutr2 history_itemfirstrr7stdsimrErFfoutrs r^r;zCmd._generate_transcript`s!'//"'*<*<_*M*MNN99w}}^,, BInbg4V4V  KK_N___ ` ` ` F ; 9' " "!Y #{ !  " " " " " " " " " " " " " " "J '& &  lK884#/#3L(3355IIDIdk#;4#;#;#;; %d&>#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 :&&& ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' q  15 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)z4Run a text editor and optionally open a file with itN)r9rt)r]rMs r^do_editz Cmd.do_edits '''''r`c:|jstdtjtj|j}|r7|dtjtj|zz }||dS)z Run 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)rEnvironmentErrorrrrrrr)r]rtrs r^r9zCmd.run_editors{ n"#lmm m$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.r>N)rr\s r^rzCmd._current_script_dirs"   #B' '4r`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)zRun commands in script file that is encoded as either ASCII or UTF-8 text. :return: True if running of commands should stop Frr{z' 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 'rrUrw)rrrrrr rrrgetsizer is_text_filer rrrjrrrrrr2r;rr}rr) r]rMrsrtargetscript_commandsrForig_script_dir_countrEs r^r: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)z Run commands in script file that is encoded as either ASCII or UTF-8 text :return: True if running of commands should stop rX)rtrrrrr:rr)r]rMrt relative_paths r^do__relative_run_scriptzCmd.do__relative_run_scriptOsIN  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| dt5jd|tjdgt_|} t9t:t jtj} | | } |}| !| }||z }|"rkt%j#tj| $d| d| d|dd}t j|d}%|dS| $}|&d }||d&d!}||z} ||dd_ dS)"a#Runs 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)rcrdrecmdappr\sr^ TestMyAppCasernsFFFr`r)rz%No test files found - nothing to testrrXrz cmd2 transcript test =)rjT)boldz platform z -- Python z, cmd2-z , readline-zcwd: z cmd2 app: z collected z transcript testfiles)streamrz passed in z.3fz seconds zAssertionError:zFile )'timeunittestcmd2r2rrfiles_from_glob_patternsrR_OKr rrmaprr version_inforrrr align_centerr __version__rGrrrr&rrrrTextTestRunnerr1 wasSuccessfulrrrr)r]rrrrrrtranscripts_expandedverinfonum_transcriptsrtestcaserrunner start_time test_resultsexecution_time finish_msg error_str end_of_trace file_offsetrEs` r^_run_transcript_testszCmd._run_transcript_tests]sk                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\]]]^^^ -ABBBHQK= =??fel3:6677(((77YY[[ zz(++ z1  % % ' '   "3:v{{}} = = =i_iiiiNiiiiJ+J#FFFJ MM* % % % % % I$>>*;<t2j|t2jn>t,t.jkr)t&jjj |tC|j"dStd ) ai Display 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_columnsrr7 cursor_offsetrz"another thread holds terminal_lock)#rcurrent_thread main_threadrrIrr rrneed_prompt_refreshrFshutilget_terminal_sizecolumnsrDEFAULT_TERMINAL_WIDTHrasync_alert_strrBrPrrCrGr@r.rrrrr1r3r4rrQr)r]rrupdate_terminalrr terminal_strs r^ async_alertzCmd.async_alerts(  # % %)>)@)@ @ @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)a Update 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` rXNr)r]rs r^async_update_promptzCmd.async_update_prompts $ Z(((((r`c0|ddS)a Refresh 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` rXNrr\s r^async_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)rIrrErrrDr\s r^rzCmd.need_prompt_refresh sJ $"3 5%&&&nt/K+KnPTP[_l_n_nPnnr`r+ctsdS tjt j|tjdS#t$rYdSwxYw)a5 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)rIrrrr set_titlerrr*s r^set_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)zp Enable a command by restoring its functions :param command: the command being enabled N) r rr(r*r)rrsrtrdru)r]rrlrormdcs r^rzCmd.enable_command%s $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)zh Enable an entire category of commands :param category: the category to enable N)r-r rsrrr^r)r]rrrs r^enable_categoryzCmd.enable_categoryFsg 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)a Disable 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" Nr{z' does not refer to a commandrr)rcgSrkrg)rMrs r^rLz%Cmd.disable_command..xs2r`)r rrrr(r*r)rqrrr_report_disabled_command_usager  COMMAND_NAMEr)r]rrrsrlrormnew_funcs r^disable_commandzCmd.disable_commandQs/ d, , , F ==11  # !KW!K!K!KLL L!5? "3g='=G+:-!$==&t-@$GG+ + + w'$  /BRBZBZ[d[qszB{B{    mX...nh/// )+E+EFFFFFr`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)rrrrr^r)r]rr all_commandsrrs r^disable_categoryzCmd.disable_categoryzsu,,.. $ A AH==**DtY=tDDPP$$X/?@@@ A Ar`_args_kwargsc4||ddS)z Report 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 )r]rrrs r^rz"Cmd._report_disabled_command_usages! $% 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)aThis is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2. _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|"Srg)rrr)r-tfs r^r/zCmd.cmdloop..s('`'`'`2(:(:2(>(>'`'`'`r`)rrrrr getsignalrr:rrrSIGHUPr@SIGTERMr r_preloop_hooksrIrrrrr_postloop_hooksrKrr)r]rroriginal_sigint_handleroriginal_sighup_handleroriginal_sigterm_handlerrs r^cmdloopz Cmd.cmdloopsC  # % %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 systemN)rrrYr^rartr\s r^rzCmd._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.rrXrz has z positional argument , expected N)r;r<rr=rvrc)clsrrr<nparamrs r^_validate_callable_param_countz"Cmd._validate_callable_param_countst%d++ Y)** U??!Q;;RRCFt}ii6iiviibgiijj j ?r`c||dtj|}|jt |jddS)z@Check parameter and return types for preloop and postloop hooks.rNz, must declare return a return type of 'None')rr;r<return_annotationrvrc)rrr<s r^_validate_prepostloop_callablez"Cmd._validate_prepostloop_callablesT **4333%d++  & 2t}ZZZ[[ [ 3 2r`cd|||j|dS)zFRegister a function to be called at the beginning of the command loop.N)rrrr]rs r^register_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 r^register_postloop_hookzCmd.register_postloop_hooks3 ++D111 ##D)))))r`c|ttdtf|dt j|}t |jd\}}|j tj krt|j d|jtj krt|j ddS)z6Check parameter and return types for postparsing hooks.rrzI must have one parameter declared with type 'cmd2.plugin.PostparsingData'zC must declare return a return type of 'cmd2.plugin.PostparsingData'N)rrr r r;r<r-r=rf annotationrrXrvrcrrrr<r_rs r^_validate_postparsing_callablez"Cmd._validate_postparsing_callables **4c0BD+I+I1MMM%d++  ,224455a85  v5 5 5t}wwwxx x  &&*@ @ @t}qqqrr r A @r`cd|||j|dS)zXRegister a function to be called after parsing user input but before running the commandN)rrYrrs r^register_postparsing_hookzCmd.register_postparsing_hooks3 ++D111 &&t,,,,,r`CommandDataType data_typectj|}|ttdt f|dt |jd}|j|}|j |kr"td|j d|j d||j |j krt|j d||j |kr!t|j d|j d|d S) z@Check parameter and return types for pre and post command hooks..rrzargument 1 of z has incompatible type rz0 does not have a declared return type, expected z has incompatible return type N)r;r<rrr r r-r=rXrrvrcrempty)rrrr< paramnamers r^_validate_prepostcmd_hookzCmd._validate_prepostcmd_hooks %d++  **4c0BD+I+I1MMM-224455a8 $Y/  y ( ({T]{{SXSc{{py{{|| |  &)/ 9 9t}ii^giijj j  &) 3 3=ss @[sshqss  4 3r`cz||tj|j|dS)z9Register a hook to be called before the command function.N)rrr]r^rrs r^register_precmd_hookzCmd.register_precmd_hook-s8 &&tV-BCCC !!$'''''r`cz||tj|j|dS)z8Register a hook to be called after the command function.N)rrr`rarrs r^register_postcmd_hookzCmd.register_postcmd_hook2s8 &&tV-CDDD ""4(((((r`cp||dtj|}t|jd\}}|jtjkr#t|j dtj|j tjkrtddS)z@Check parameter and return types for command finalization hooks.rrz, must have one parameter declared with type zU{func.__name__} must declare return a return type of {plugin.CommandFinalizationData}N) rr;r<r-r=rfrrrsrvrcrrs r^"_validate_cmdfinalization_callablez&Cmd._validate_cmdfinalization_callable7s **4333%d++  ,224455a85  v= = =t}zzZ`Zxzz{{ {  &&*H H Hstt t I Hr`cd|||j|dS)zdRegister a hook to be called after a command is completed, whether it completes successfully or not.N)rrtrrs r^register_cmdfinalization_hookz!Cmd.register_cmdfinalization_hookDs5 //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' 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)rM issubclassr&r,rr+rr)r]rr func_class func_selfcandidate_setsinstalled_cmd_sets r^_resolve_func_selfzCmd._resolve_func_selfKs+==M*N*N   !jZ&H&H !(J// 2$ ! 35)-)EAA%-..*<<$5 ""3Z@@A&--.?@@@$^)<)<)A)A .q 1I Kr`)rNNra)rXrk)r)F)r(rcrdrerfr find_editorrINTERNAL_COMMAND_EPILOG norm_foldr  natural_keysNATURAL_SORT_KEYrrrrrrr rr&r_rr0rrrr+rrrr StaticArgParseBuilderClassArgParseBuilderrr%r[r!r\r]rrrrpropertyrUsetterrrLrTrrrrrrrrr r rrr rrrrr,r6rrIrOrYrbrfrrrrrr0r2rrrrrrr$r#r~r rrrKrJrr"r!r#r$r*r+rr6rr:r@r;r;rDrGrIrKrNrorfr7r}rrWrrr[rbrr_rrrrr rrrUr r ralias_description alias_epilogrr alias_parseradd_subparsersr- Namespaceralias_create_descriptionalias_create_epilogalias_create_parserr REMAINDERr,rr&alias_delete_helpalias_delete_descriptionalias_delete_parser ZERO_OR_MORErr0alias_list_helpalias_list_descriptionalias_list_parserr8macro_description macro_epilog macro_parserr:macro_create_helpmacro_create_descriptionmacro_create_epilogmacro_create_parserrNmacro_delete_helpmacro_delete_descriptionmacro_delete_parserrPmacro_list_helpmacro_list_descriptionmacro_list_parserrRrVr[ help_parserOPTIONALrryrvrdrbrprnr`rrshortcuts_parserr eof_parserr quit_parserrrrset_descriptionr set_parserr shell_parserrrrrirrr  py_parserrrun_pyscript_parserripython_parserrhistory_descriptionr3add_mutually_exclusive_grouphistory_action_groupadd_argument_grouphistory_format_grouphistory_arg_helprBr6rrPr;edit_description edit_parserrvr9rrun_script_descriptionrun_script_parserr:relative_run_script_descriptionrelative_run_script_epilogrelative_run_script_parserrrrrrrrrrrrrrrrtrrrrrrXrrrrrr]rr`rrsrrobjectr  __classcell__)r&s@r^rvrv(s,'U&((N p "O)!"&#' H9 (*)- ', !#04"&26+/.27;#' $(-+H9H9H9H9H9 H9 "% H9$'H9H9!%H9H9H9H9#49-H9 H9%T#Y/H9 d3i(!H9"DcN+#H9$x 34%H9&!'H9()H9*"&+H9, -H9H9H9H9H9H9T ]b    Z0@  UY  fjkufv     ;;@T;;;;55550K:K$KKKKZ! 'X445%$&   () *.)9)93)9P[)9fi)9sw)9)9)9)9V:C: :Z^::::0s0hy>Q0VZ0000*8Z*8D*8*8*8*8X?:?$????8kE*e2C,DkkkkkZ.eJ4E.F.4....`----X-#22$222$#2 73=1X 2X 2$ 2 2 2 2 BC BD B B B B(T(T(T(TX T_   X #4?#t####WtWWWW----X-04 ;;;g;;  ; #,- ; ;;;;81411131S1D1111a$Daaa#aCaTaUYaaaa#D###C#c#T####5D555C5c5T5555/3;;;3;;;QU;;;;615 = = =S =# = = = = =.22'2'2'#2's2'2'$2'2'2'2'lUUUU&>"#>"s>"C>"ERVWZR[]abe]fRfLg>">">">"@XXX X  X  } X cXXXX*BBB B  B  } BB cBBBBX?C/#/#/#/#/# /#  /# U8C=-#?@@A /#hsm]:;/# c/#/#/#/#rCG22222 2  2 Cx}m'C!DDE 25# !=>?2 c2222jquMMMM"M,/M9<MNVW_ad`egk`kWlNmM cMMMM^lqs#sCdhuyz}u~2N4sN4#N4sN4CN4[hN4mqrumvN4N4N4N4`WDIW%S SVBWWWW\W*<!<!*.s)<!KN<! <!<!<!<!|!<49!<!<!<!<!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]YYYYQT YajYYYYv^b444S4XVY]4fo4444l'1 '1hsm'1'1'1'1Rq!)q!8Sq!q!q!q!f@@uGb@gk@@@@<CC(=CCCC$RV!3!3!3in 5!3$!3Z^!3!3!3!3Fx~&EE EEEE(,050D0I %+/:>-148^#^#^#^#$s)$ ^# - ^#  ^#(3-(^###67^#M*^#01^# ^#^#^#^#@)))))),'!'='!'!'!'!RP3IPdPPPP"'D'D'D'D\x'L:?:GXamnnnL tDDD^L$777X/D87 > DB/A,5H$$V2F$GGG$$4Gv%$$h07Uan%gx)B7CB7tCyB74B7DB7B7B7B7H?>Kefff^$%% h0 T   &% 983+=>->>>>@#O-#OD#O#O#O#OJ8<rrrx}rrrrrh87DefffI^I"x)"htn""""B/AN{|||$$]9R^k$lll$$("4;Xdq%^'(( H$6 8D>   )( D=_EUVVV^N##[x1[htn[[[$#[z!38W0[`+aaa^.// EH,> E8D> E E E0/ E<d3i<D<<<<|FEFESFEhsmFEtFEFEFEFEP)c)d))))($oToooo\&,c,d,,,,B . . . . . .'Gs'Gc'Gd'G'G'G'GRAAAAAAA 9S 9C 9\_ 9dh 9 9 9 9DDXc]DcDDDDV{{{{k(382DkSkUYkkk[k\(2t82D\\\\[\)(2t8*<))))) *8BH+=*$**** s(F?LPQ`La [((63H2I6K`2`)a(fj(((( )(F4J3KVMc3c*d)im))))  uV;\\] u  u u u[ u1f<=v?]]^1 11111"38,1 E4/01 &  11111111r`)rfrryrvrrr;rrcr>rrrrdr collectionsrr contextlibrtypesrrtypingr r r r r rrrrrrrrrrrrXrrrrrrr r!r" clipboardr#r$command_definitionr%r&r'r(r)r*rr+r,r- exceptionsr.r/r0r1r2r3r4r5rnr6r7r8parsingr9r:r;r<r=rr?r!rl_utilsr@rArBrCrDrErFrGrHrI table_creatorrJrKrLrMrNrOrrrrrPrQrrr1r3r4r5rr.rrRrin_dllrSrrrrrUrirqrrrrtrrxrvrgr`r^rVs,<   &                        %%%%%%%   D                          fkJ'T' 334444 3X244N&###"*+"2"G FJ         %+O$:$:'?XE\'\](&H0H0H0H0H0H0H0H0VTUTUTUTUTU#'TUTUTUTUTUs C''C/.C/