
    h	                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
rSSKJrJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJrJr  SS
KJrJrJrJrJrJ r J!r!  SSK"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2J3r3  SSK4J5r5  SSK6J7r7  SRq                  5       r9SRq                  5       r:\;" \	S5      (       d  S/\	l<        Sr=\R|                  R                  SS5      r@\@R                  5       S;   a  SrBO"\@R                  5       S;   a  SrBO\C" S\@-  5      e\	R                  =(       a    \	R                  R                  S5      rF\R                  " S\R                  S\R                  4   S 9rJ\R                  \R                  S!4   rM\RH                  \N\R                  4   rO\R                  \RN                  \N      rQ\RN                  \R                  \      rSS,S" jrT " S# S$\U5      rV " S% S&\R                  5      rX " S' S(\5      rY\YR                  r[\YR                  r]S-S.S) jjr^S/S* jr_\`S+:X  a  \YR                  5         gg)0z,A base class for a configurable application.    )annotationsN)OrderedDictdefaultdict)suppress)deepcopy)
dictConfig)dedent)ConfigurableSingletonConfigurable)ArgumentErrorConfigConfigFileNotFoundDeferredConfigStringJSONFileConfigLoaderKVArgParseConfigLoaderPyFileConfigLoader)
BoolDictEnumInstanceList
TraitErrorUnicodedefaultobserveobserve_compat)Bunch)nested_update)indentwrap_paragraphs   )cast_unicode)import_itemz
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:
    <cmd> --help-all
z
The command-line option below sets the respective configurable class-parameter:
    --Class.parameter=value
This line is evaluated in Python, so simple expressions are allowed.
For instance, to set `C.a=[0,1,2]`, you may type this:
    --C.a='range(3)'
argv zp
Subcommands are launched as `{app} cmd [args]`. For information on using
subcommand 'cmd', do: `{app} cmd -h`.
-TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR>   1trueT>   r%   0falseFzUnsupported value for environment variable: 'TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR' is set to '%s' which is none of  {'0', '1', 'false', 'true', ''}.zpythonw.exeT.)boundzlogging.LoggerAdapter[t.Any]c                |   ^  [         R                  " T 5      SU 4S jj5       n[        R                  " [        U5      $ )a  Method decorator for catching invalid config (Trait/ArgumentErrors) during init.

On a TraitError (generally caused by bad config), this will print the trait's
message, and exit the app.

For use on init methods, to prevent invoking excepthook on invalid input.
c                   >  T" U /UQ70 UD6$ ! [         [        4 a]  nU R                  R                  SU5        U R                  R	                  SU R
                  5        U R                  S5         S nAg S nAff = f)Nz0Bad config encountered during initialization: %szConfig at the time: %s   )r   r   logfataldebugconfigexit)appargskwargsemethods       oC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\traitlets/config/application.pyinner!catch_config_error.<locals>.inners   si    	#////M* 	GGMMLaPGGMM2CJJ?HHQKK	s    A<AA77A<)r5   Applicationr6   t.Anyr7   r>   returnr>   )	functoolswrapstcastr+   )r9   r;   s   ` r:   catch_config_errorrD   j   s3     __V  66!U    c                      \ rS rSrSrg)ApplicationError    N)__name__
__module____qualname____firstlineno____static_attributes__rI   rE   r:   rG   rG      s    rE   rG   c                  L   ^  \ rS rSrSr\R                  rSrSU 4S jjr	Sr
U =r$ )LevelFormatter   zFormatter with additional `highlevel` record

This field is empty if log level is less than highlevel_limit,
otherwise it is formatted with self.highlevel_format.

Useful for adding 'WARNING' to warning messages,
without adding 'INFO' to info, etc.
z %(levelname)s |c                   > UR                   U R                  :  a  U R                  UR                  -  Ul        OSUl        [
        TU ]  U5      $ )Nr%   )levelnohighlevel_limithighlevel_format__dict__	highlevelsuperformat)selfrecord	__class__s     r:   rY   LevelFormatter.format   sC    >>T111#44vFF!Fw~f%%rE   rI   )r[   zlogging.LogRecordr?   str)rJ   rK   rL   rM   __doc__loggingWARNrT   rU   rY   rN   __classcell__r\   s   @r:   rP   rP      s#     llO)& &rE   rP   c                  $  ^  \ rS rSr% Sr\" S5      rS\S'   \" S5      rS\S'   \" \	5      r	S\S'   \" \
5      r
S\S	'   \" \5      rS\S
'   \r\r\" 5       rS\S'   / rS\S'    Si   SjS jjr\" S5      rS\S'   \" 5       rS\S'   \" \5      r\" S\R6                  SS9R9                  SS9r\r\" SSS9R9                  SS9r \" SSS9R9                  SS9r!SkS jr"\#" SS S!S"5      SlS# j5       r$\#" S$S%S&9SlS' j5       r%SmS( jr&\'" S$5      SnS) j5       r(\)" S*S9R9                  SS9r*S+S,0r+S\S-'   S S!\RX                  00S.4S S/S00S04S S1S00S24S3.r-S\S4'   \)" 5       r.S5\S6'   \/" S7SS89r0\" \" 5       5      r1\/" \2S90 S:S9r3\" 5       r4S;\S<'   \" S=S9R9                  SS9r5\" S>S9R9                  SS9r6\#" S15      SlS? j5       r7\#" S/5      SlS@ j5       r8SoSA jr9\#" SB5      \:SlU 4SC jj5       5       r;\<SiSpSD jj5       r=SmSE jr>SmSF jr?SmSG jr@SqSH jrASmSI jrBSqSJ jrCSmSK jrDSqSL jrESmSM jrFSqSN jrGSrSO jrHSsStSP jjrISsSrSQ jjrJSuSR jrKSmSS jrLSqST jrMSmSU jrNSqSV jrOSmSW jrP\<SiSvSX jj5       rQSwSY jrR          SxSZ jrS\TSsSyS[ jj5       rU\TSmS\ j5       rV\<SiSpS] jj5       rW\T  Sz         S{S^ jj5       rX\YS|S_ j5       rZ\< Si     S}S` jj5       r[\<SmSa j5       r\ Si   SjSb jjr]SiS~Sc jjr^SmSd jr_SSSe jjr`SmSf jra\TSiSSg jj5       rbShrcU =rd$ )r=      z8A singleton application with full configuration support.applicationzstr | Unicode[str, str | bytes]namezThis is an application.descriptionoption_descriptionkeyvalue_descriptionsubcommand_descriptionexamplesClassesTypeclassesc              #     #    Uc  U R                   n[        5       nU HV  n[        UR                  5       5       H6  n[	        U[
        5      (       d  M  XB;  d  M!  UR                  U5        Uv   M8     MX     g7f)zIterate through configurable classes, including configurable parents

:param classes:
    The list of classes to iterate; if not set, uses :attr:`classes`.

Children should always be after parents, and each class should only be
yielded once.
N)rn   setreversedmro
issubclassr
   add)rZ   rn   seencparents        r:   _classes_inc_parents Application._classes_inc_parents   s^      ?llGuA"1557+fl339KHHV$ L , s   AA9A9A9z0.0versionzlist[str] | List[str]r$   )r   
         (   2   DEBUGINFOra   ERRORCRITICALz#Set the log level by value or name.)default_valuehelpTr3   z%Y-%m-%d %H:%M:%Sz:The date format used by logging formatters for %(asctime)s)r   z#[%(name)s]%(highlevel)s %(message)szThe Logging format templateStrDictc                D   SSSS[         R                  " U R                  5      SS.0SU R                  R                   SU R                  R
                   3U R                  U R                  S.0U R                  R
                  SS/S	.0S
S.n[        (       a  US	 US	 U$ )aO  Return the base logging configuration.

The default is to log to stderr using a StreamHandler, if no default
handler already exists.

The log handler level starts at logging.WARN, but this can be adjusted
by setting the ``log_level`` attribute.

The ``logging_config`` trait is merged into this allowing for finer
control of logging.

r/   consolezlogging.StreamHandlerzext://sys.stderr)class	formatterlevelstream.)r   rY   datefmtr   )r   handlersF)rz   r   
formattersloggersdisable_existing_loggersr   r   )
r`   getLevelName	log_level_log_formatter_clsrK   rJ   
log_formatlog_datefmtr\   
IS_PYTHONWrZ   r3   s     r:   get_default_logging_config&Application.get_default_logging_config   s     4!*$11$..A0	 22==>D33<<=? #oo#//	 ''$!** ).5
: : z"y!rE   r   r   r   logging_configc                    U R                   n[        U[        5      (       a.  [        R                  " [
        [        [        U5      5      U l         U R                  5         g N)	r   
isinstancer^   rB   rC   intgetattrr`   _configure_logging)rZ   changer   s      r:   _observe_logging_change#Application._observe_logging_change  s?     NN	i%%VVC))DEDN!rE   r0   r   )typec                $    U R                  5         g r   )r   rZ   r   s     r:   _observe_logging_default$Application._observe_logging_default  s    !rE   c                    U R                  5       n[        XR                  =(       d    0 5        [        U5        SU l        g )NT)r   r   r   r   _logging_configuredr   s     r:   r   Application._configure_logging!  s3    002f117R86#' rE   c                    [         R                  " U R                  R                  5      nSUl        UnUb8  UR
                  (       a  U$ UR                  (       d   U$ UR                  nUb  M8  U$ )z#Start logging for this application.F)r`   	getLoggerr\   rJ   	propagater   rw   )rZ   r0   _logs      r:   _log_defaultApplication._log_default(  se      7 78}}
>>
 ;;D  
rE   a!  
            Configure additional log handlers.

            The default stderr logs handler is configured by the
            log_level, log_datefmt and log_format settings.

            This configuration can be used to configure additional handlers
            (e.g. to output the log to a file) or for finer control over the
            default handlers.

            If provided this should be a logging configuration dictionary, for
            more information see:
            https://docs.python.org/3/library/logging.config.html#logging-config-dictschema

            This dictionary is merged with the base logging configuration which
            defines the following:

            * A logging formatter intended for interactive use called
              ``console``.
            * A logging handler that writes to stderr called
              ``console`` which uses the formatter ``console``.
            * A logger with the name of this application set to ``DEBUG``
              level.

            This example adds a new handler that writes to a file:

            .. code-block:: python

               c.Application.logging_config = {
                   "handlers": {
                       "file": {
                           "class": "logging.FileHandler",
                           "level": "DEBUG",
                           "filename": "<path/to/file>",
                       }
                   },
                   "loggers": {
                       "<application-name>": {
                           "level": "DEBUG",
                           # NOTE: if you don't list the default "console"
                           # handler here then it will be disabled
                           "handlers": ["console", "file"],
                       },
                   },
               }

        z	log-levelzApplication.log_levelaliasesz5Set log-level to debug, for the most verbose logging.show_configz<Show the application's configuration (human-readable format)show_config_jsonz2Show the application's configuration (json format))r2   zshow-configzshow-config-jsonflagsz#dict[str, t.Any] | Dict[str, t.Any]subcommandsz(traitlets.config.application.Application)
allow_nonerI   zThe subset of our configuration that came from the command-line

        We re-load this configuration after loading config files,
        to ensure that it maintains highest priority.
        z	List[str]_loaded_config_fileszAInstead of starting the Application, dump configuration to stdoutzKInstead of starting the Application, dump configuration to stdout (as JSON)c                &    UR                   U l        g r   )newr   r   s     r:   _show_config_json_changed%Application._show_config_json_changed  s    !::rE   c                l    UR                   (       a#  U R                  U l        U R                  U l        g g r   )r   start_save_startstart_show_configr   s     r:   _show_config_changed Application._show_config_changed  s'    ::#zzD//DJ rE   c                   [         R                  " U 40 UD6  U R                  nX R                  ;  aU  U R                  UR                  L a  U/U R                  QU l        g U R                  R	                  SU R                  5        g g )Nr   )r   __init__r\   rn   insert)rZ   r7   clss      r:   r   Application.__init__  sj    &&t6v6 nnll"||s{{* #3dll3##At~~6 #rE   r3   c                p   > [         TU ]  U5        U R                  R                  SUR                  5        g )NzConfig changed: %r)rX   _config_changedr0   r2   r   )rZ   r   r\   s     r:   r   Application._config_changed  s)     	'+VZZ8rE   c                &    U R                  U5        g)z=Do the basic steps to configure me.

Override in subclasses.
N)parse_command_line)rZ   r$   s     r:   
initializeApplication.initialize  s     	%rE   c                    U R                   b;  [        U R                   [        5      (       d   eU R                   R                  5       $ g)z1Start the app mainloop.

Override in subclasses.
N)subappr   r=   r   rZ   s    r:   r   Application.start  s=    
 ;;"dkk;7777;;$$&& #rE   c                &   U R                   R                  5       nU R                  R                  5        HG  nUR                  U;   d  M  XR                     nUR                  SS5        UR                  SS5        MI     U R                  (       aJ  [        R                  " U[        R                  SS[        S9  [        R                  R                  S5        gU R                  (       a6  [        S5        U R                   H  n[        S	U-   5        M     [        5         [        U5       Ha  nX   nU(       d  M  [        U5        [!        S
SS9n[        U5       H-  nXh   n	[        SU S["        R$                  " U	40 UD6 35        M/     Mc     g)z,start function used when show_config is Truer   Nr   r/   T)r   	sort_keysr   
zLoaded config files:z     )r   compactz  .z = )r3   copyr\   rr   rJ   popr   jsondumpsysstdoutreprwriter   printsorteddictpprintpformat)
rZ   r3   r   
cls_configf	classnameclass_configpformat_kwargs	traitnamevalues
             r:   r   Application.start_show_config  s5   !!#>>%%'C||v%#LL1
}d3148	 (   IIfcjjdDQJJT"$$()..dQh /GI!,L)&*!T&BN#L1	$/I;c&..*Q.*Q)RST 2 (rE   c                T    [        SR                  U R                  5       5      5        g)z"Print the alias parts of the help.r   N)r   joinemit_alias_helpr   s    r:   print_alias_helpApplication.print_alias_help  s    dii,,./0rE   c              #  h  #    U R                   (       d  g0 nU R                   HU  nUR                  5       SS  H;  n[        R                  " [        R
                  [           U5      XR                  '   M=     MW     U R                   R                  5        H  u  pE [        U[        5      (       a  Uu  pVOSnUR                  S5      SS u  pxUS-   U-   nX   nUR                  SS9U   n	UR                  XS9R                  5       n
[        U[        5      (       d  U4n[        U[         S9nS	R#                  S
 U 5       5      nU
S   R%                  SU-   U5      U
S'   U
 Sh  vN   ['        SU-  5      v   M     g N! [(         a"  nU R*                  R-                  SXK5        e SnAff = f7f)z+Yield the lines for alias part of the help.Nr   Tr   )helptextkey, c              3  N   #    U  H  n[        U5      S :  a  SOSU-  v   M     g7fr/   z--%sz-%sNlen.0ms     r:   	<genexpr>.Application.emit_alias_help.<locals>.<genexpr>  #     !WQVASVaZ6Ua"GQV   #%r   --zEquivalent to: [--%s]z7Failed collecting help-message for alias %r, due to: %s)r   rn   rr   rB   rC   Typer
   rJ   itemsr   tuplesplitclass_traitsclass_get_trait_help
splitlinesr   r   r   replacer   	Exceptionr0   error)rZ   	classdictr   rv   aliaslongnamefhelpr   r   traitfhelp_linesexs               r:   r   Application.emit_alias_help  s    ||35	<<CWWYs^()qvvl/CQ(G	**% $    $||113OEh..&.OHe E'/~~c':23'?$	$s?Y6*(((5i@!66u6MXXZ!%//"HEu#.		!WQV!WW "-Q!7!7x!OA&&&4x?@@+  4( ' XZ_ds=   BF2CF'F(F<F2F
F/F**F//F2c                T    [        SR                  U R                  5       5      5        g)z Print the flag part of the help.r   N)r   r   emit_flag_helpr   s    r:   print_flag_helpApplication.print_flag_help'  s    dii++-./rE   c              #  *  #    U R                   (       d  gU R                   R                  5        H  u  nu  p# [        U[        5      (       d  U4n[	        U[
        S9nSR                  S U 5       5      nUv   [        [        UR                  5       5      5      v   SR                  S UR                  5        5       5      nSU-  n[        [        U5      5      v   M     g! [         a"  nU R                  R                  SX5        e SnAff = f7f)	z.Yield the lines for the flag part of the help.Nr   r   c              3  N   #    U  H  n[        U5      S :  a  SOSU-  v   M     g7fr   r   r   s     r:   r  -Application.emit_flag_help.<locals>.<genexpr>5  r  r   c              3  p   #    U  H,  u  pUR                  5         H  u  p4S U SU SU 3v   M     M.     g7f)r  r   =N)r	  )r  clname
props_dictpropvals        r:   r  r   8  sE      $.9*%/%5%5%7	 $q.%7 /.9s   46zEquivalent to: [%s]z6Failed collecting help-message for flag %r, due to: %s)r   r	  r   r
  r   r   r   r   r	   stripr  r0   r  )rZ   r   cfgr  cfg_listcfg_txtr  s          r:   r  Application.emit_flag_help+  s     zz#'::#3#3#5E<C!%//"HEu#.		!WQV!WWVEKKM23388 $.1iik$ 
 0(:VG_-- $6  WY^cs)   5DB'C$D$
D.DDDc                T    [        SR                  U R                  5       5      5        g)z#Print the options part of the help.r   N)r   r   emit_options_helpr   s    r:   print_optionsApplication.print_optionsC  s    dii..012rE   c              #  6  #    U R                   (       d  U R                  (       d  gSnUv   S[        U5      -  v   [        U R                  5       H  nUv   Sv   M     U R                  5        Sh  vN   U R                  5        Sh  vN   Sv   g N! N7f)z1Yield the lines for the options part of the help.NOptionsr#  r%   )r   r   r   r    ri   r  r   )rZ   headerps      r:   r.  Application.emit_options_helpG  s     zz$,,CK !8!89AGH : &&(((''))) 	))s$   A1B3B4BB
BBc                T    [        SR                  U R                  5       5      5        g)z&Print the subcommand part of the help.r   N)r   r   emit_subcommands_helpr   s    r:   print_subcommandsApplication.print_subcommandsV  s    dii22456rE   c              #    #    U R                   (       d  gSnUv   S[        U5      -  v   [        U R                  R	                  U R
                  S95       H  nUv   Sv   M     U R                   R                  5        H9  u  nu  pEUv   U(       d  M  [        [        UR                  5       5      5      v   M;     Sv   g7f)z4Yield the lines for the subcommand part of the help.NSubcommandsr#  )r5   r%   )
r   r   r    rk   rY   rg   r	  r   r	   r(  )rZ   r3  r4  subc_r   s         r:   r7  !Application.emit_subcommands_helpZ  s     CK !<!<!C!C		!C!RSAGH T  $//557OD)1JtVDJJL122  8 s   BC-Cc              #  ,   #    U(       d	  Sv   Sv   gg7f)zjYield the very bottom lines of the help message.

If classes=False (the default), print `--help-all` msg.
z5To see all available configurables, use `--help-all`.r%   NrI   rZ   rn   s     r:   emit_help_epilogueApplication.emit_help_epiloguek  s     
 IIH s   c                R    [        SR                  U R                  US95      5        g)zPrint the help for each Configurable class in self.classes.

If classes=False (the default), only flags and aliases are printed.
r   rn   N)r   r   	emit_helpr@  s     r:   
print_helpApplication.print_helpt  s     
 	diiw789rE   c              #    #    U R                  5        Sh  vN   U R                  5        Sh  vN   U R                  5        Sh  vN   U(       a^  U R                  5       nUb,  Sv   Sv   [	        U R
                  5       H  nUv   Sv   M     U H  nUR                  5       v   Sv   M     U R                  5        Sh  vN   U R                  U5       Sh  vN   g N N N N$ N7f)zYield the help-lines for each Configurable class in self.classes.

If classes=False (the default), only flags and aliases are printed.
NzClass optionsz=============r%   )	emit_descriptionr7  r.  _classes_with_config_traitsr    rj   class_get_helpemit_examplesrA  )rZ   rn   help_classesr4  r   s        r:   rE  Application.emit_help{  s     
 ((***--///))+++;;=L'%%%%()B)BCAGH D $((** $ %%'''**7333% 	+/+ 	(3sV   C,C"C,C$C,C&A<C,C(C,C*C,$C,&C,(C,*C,c                N    SR                  S U R                  5        5       5      $ )zgGenerate rST format documentation for the config options this application

Returns a multiline string.
r   c              3  @   #    U  H  oR                  5       v   M     g 7fr   )class_config_rst_doc)r  rv   s     r:   r  6Application.document_config_options.<locals>.<genexpr>  s     W;Va//11;Vs   )r   rx   r   s    r:   document_config_options#Application.document_config_options  s"    
 yyW4;T;T;VWWWrE   c                T    [        SR                  U R                  5       5      5        g)z"Print the application description.r   N)r   r   rI  r   s    r:   print_descriptionApplication.print_description  s    dii--/01rE   c              #     #    [        U R                  =(       d    U R                  =(       d    S5       H  nUv   Sv   M     g7f)z-Yield lines with the application description.r%   N)r    rh   r_   )rZ   r4  s     r:   rI  Application.emit_description  s3      !1!1!GT\\!GRHAGH Is   AAc                T    [        SR                  U R                  5       5      5        g)z1Print usage and examples (see `emit_examples()`).r   N)r   r   rL  r   s    r:   print_examplesApplication.print_examples  s    dii**,-.rE   c              #     #    U R                   (       a?  Sv   Sv   Sv   [        [        U R                   R                  5       5      5      v   Sv   gg7f)zYield lines with the usage and examples.

This usage string goes at the end of the command line help string
and should contain examples of the application's usage.
Examplesz--------r%   N)rl   r   r	   r(  r   s    r:   rL  Application.emit_examples  sF      ==H 3 3 5677H s   AAc                .    [        U R                  5        g)zPrint the version string.N)r   rz   r   s    r:   print_versionApplication.print_version  s    dllrE   c                   U R                   R                  U5      nUc   eUu  pE[        U[        5      (       a  [	        U5      n[        U[
        5      (       aD  [        U[        5      (       a/  U R                  R                  5         UR                  U S9U l        O,[        U5      (       a  U" U 5      U l        O[        SU-  5      eU R                  R                  U5        g)z"Initialize a subcommand with argv.N)rw   z%Invalid mappings for subcommand '%s'!)r   getr   r^   r#   r   rs   r=   r\   clear_instanceinstancer   callableAssertionErrorr   )rZ   r<  r$   r'  r   r=  s         r:   initialize_subcommand!Application.initialize_subcommand  s     ""4(	fc"" (F fd##
6;(G(GNN))+ ///6DKf ,DK !H4!OPP 	t$rE   c                Z   [        [        5      nU R                   HF  nUR                  nUR	                  5       SS  H   nXR                     R                  U5        M"     MH     0 nU R                  R                  5        H  u  pg[        U[        5      (       a  Uu  pxUR                  SS5      u  p)X   n
[        U
5      S:X  a  U
S   n[        U[        5      (       d  U4nU H  nSR                  X)/5      X['   M     M     0 nU R                  R                  5        H  u  nu  p0 nUR                  5        H?  u  nnX   n
[        U
5      S:X  a  U
S   nUU;   a  UU   R                  U5        M:  UUU'   MA     [        U[        5      (       d  U4nU H
  nUU4UU'   M     M     X4$ )a  Flatten flags and aliases for loaders, so cl-args override as expected.

This prevents issues such as an alias pointing to InteractiveShell,
but a config file setting the same trait in TerminalInteraciveShell
getting inappropriate priority over the command-line arg.
Also, loaders expect ``(key: longname)`` and not ``key: (longname, help)`` items.

Only aliases with exactly one descendent in the class list
will be promoted.

r/   r   r   r   )r   listrn   rJ   rr   appendr   r	  r   r
  r  r   r   r   update)rZ   mro_treer   clsnamerw   r   r  r  r=  r  childrenalr   r   flagdictr   newflagsubdictks                      r:   flatten_flagsApplication.flatten_flags  s    t$<<CllG'')Ab/)009 *   #%#||113OE(E**&!Q/JC}H8}!qkgu--!hh|4   4 %)ZZ%5%5%7!C!(*,G ( 0W#=x=A%"1+C'>CL''0#*GCL !1 c5))f#T?a  &8" ~rE   c           	     B    [        XX4U R                  U R                  S9$ )N)rn   r0   r   )r   r0   r   )rZ   r$   r   r   rn   s        r:   _create_loaderApplication._create_loader  s$     &5txxTM]M]
 	
rE   c                    U(       a)  S[         R                  ;   a   SSKJn  U" 5       nUc   eU$ [        R                  $ ! [        [
        4 a     [        R                  $ f = f)a7  Get `sys.argv` or equivalent from `argcomplete`

`argcomplete`'s strategy is to call the python script with no arguments,
so ``len(sys.argv) == 1``, and run until the `ArgumentParser` is constructed
and determine what completions are available.

On the other hand, `traitlet`'s subcommand-handling strategy is to check
``sys.argv[1]`` and see if it matches a subcommand, and if so then dynamically
load the subcommand app and initialize it with ``sys.argv[1:]``.

This helper method helps to take the current tokens for `argcomplete` and pass
them through as `argv`.
_ARGCOMPLETEr   )get_argcomplete_cwords)osenviron#traitlets.config.argcomplete_configr~  ImportErrorModuleNotFoundErrorr   r$   )r   check_argcompleter~  cwordss       r:   _get_sys_argvApplication._get_sys_argv  sa     2::!=V/1))) xx  !45 xxs   A A#"A#c                v    S[         R                  ;  a  g SSKJn  U" 5         g! [        [
        4 a     gf = f)a  Helper for `argcomplete` to recognize `traitlets` subcommands

`argcomplete` does not know that `traitlets` has already consumed subcommands,
as it only "sees" the final `argparse.ArgumentParser` that is constructed.
(Indeed `KVArgParseConfigLoader` does not get passed subcommands at all currently.)
We explicitly manipulate the environment variables used internally by `argcomplete`
to get it to skip over the subcommand tokens.
r}  Nr   )increment_argcomplete_index)r  r  r  r  r  r  )r   r  s     r:   "_handle_argcomplete_for_subcommand.Application._handle_argcomplete_for_subcommand3  s9     +	W')01 		s   % 88c                >  ^	 [        U[        5      (       a   eUc%  U R                  [        U R                  5      S9SS nU Vs/ s H  n[        U5      PM     snU l        U(       a  US   S:X  a	  USS S/-   nU R                  (       ad  [        U5      S:  aU  US   USS pC[        R                  " SU5      (       a0  X0R                  ;   a!  U R                  5         U R                  X45      $  USUR                  S5       m	[        U	4S	 jS
 5       5      (       a%  U R                  ST	;   5        U R!                  S5        ST	;   d  ST	;   a!  U R#                  5         U R!                  S5        U R%                  5       u  pV['        U R)                  5       5      nU R+                  XXWS9n [-        UR/                  5       5      U l        U R5                  U R0                  5        UR6                  U l        gs  snf ! [         a    Um	 GNf = f! [2         a    e f = f)z!Parse the command line arguments.N)r  r/   r   r   -hz^\w(\-?\w)*$r  c              3  ,   >#    U  H	  oT;   v   M     g 7fr   rI   )r  xinterpreted_argvs     r:   r  1Application.parse_command_line.<locals>.<genexpr>d  s     M.L$$.Ls   )r  
--help-allz--helpr  z	--versionz-VrD  )r   r^   r  boolr   r"   r$   r   rematchr  ri  index
ValueErroranyrF  r4   ra  rw  rl  rJ  rz  r   load_config
cli_config
SystemExitupdate_config
extra_args)
rZ   r$   argr<  subargvr   r   rn   loaderr  s
            @r:   r   Application.parse_command_lineG  s    dC((((<%%T=M=M8N%OPQPRSD267$3\#&$7	DGv%8tf$DD	A GT!"X'xx..4;K;K3K77911$@@	$#$6djj&67 M.LMMMOOL,<<=IIaL**d6F.F IIaL ++-t779:$$TE$K	&v'9'9';<DO
 	4??+ ++W 8(  	$#	$"  	 	s$   G81G= -H =HHHc              #    #    [        U[        5      (       d  Uc  U/n[        U5       GH]  nU R                  US-   XSS9nU(       a.  UR	                  SX=(       d    [
        R                  " 5       5        U R                  US-   XSS9n/ n/ n	Xg4 H  n
Sn U
R                  5       nU(       a  UR	                  SU
R                  5        U(       d  MB  [        X5       Hg  u  pUR                  U5      nU(       d  M  U(       d  M(  UR                  S
R!                  UU
R                  ["        R$                  " USS95      5        Mi     XR                  4v   UR'                  U5        U	R'                  U
R                  5        M     GM`     g! [         a     N[         a9    U
R                  =(       d    UnU(       a  e U(       a  UR                  SUSS	9   GNf = f7f)zULoad config files (py,json) by filename and path.

yield each config object in turn.
Nz.py)pathr0   zLooking for %s in %sz.jsonzLoaded config file: %sz&Exception while loading config file %sT)exc_infozMCollisions detected in {0} and {1} config files. {1} has higher priority: {2}r!   )r   )r   r^   rq   python_config_loader_classr2   r  getcwdjson_config_loader_classr  full_filenamer   r  r  zip
collisionswarningrY   r   dumpsrm  )r   basefilenamer  r0   raise_config_file_errorscurrentpyloader
jsonloaderloaded	filenamesr  r3   filenameearlier_configr  s                  r:   _load_config_filesApplication._load_config_filesz  s     dC  DL6D~G55lU6JQX5bH		0,@V299;W55lW6LSZ5dJ"$F#%I#0R#//1F 		":F<P<PQ647	4J0%3%>%>v%F
%:##KK!@@F$,$*$8$8$(JJz!$DA" 5K "#7#788MM&)$$V%9%9:A 1 & *   e  &33C|H/		"JH_c	desI   BGF%(G&G;GBG
GG>GGGGc                     U R                   SS $ )z$Currently loaded configuration filesN)r   r   s    r:   loaded_config_filesApplication.loaded_config_files  s     ((++rE   c                   [         R                  R                  U5      u  p[        5       nU R	                  UUU R
                  U R                  S9 HB  u  pVUR                  U5        X`R                  ;  d  M'  U R                  R                  U5        MD     UR                  U R                  5        U R                  U5        g)z'Load config files by filename and path.)r  r0   r  N)r  r  splitextr   r  r0   r  merger   rm  r  r  )rZ   r  r  ext
new_configr3   fnames          r:   load_config_fileApplication.load_config_file  s    
 ((2X
!44%)%B%B	 5 
MF V$666))007
 	):&rE   c                "   U R                   R                  5       R                  SS5      n[        5       nU R                  R                  SU5        [        R                  R                  5        Hq  u  p4UR                  U5      (       d  M  U R                  R                  SX45        UR                  S5      GtpVnUnU H  n	X   nM	     [        X[        U5      5        Ms     UR                  U R                  5        U R                  U5        g)z!Load config files by environment.-r=  z1Looping through config variables with prefix "%s"zSeeing environ "%s"="%s"__N)rg   upperr  r   r0   r2   r  r  r	  
startswithr  setattrr   r  r  r  )
rZ   PREFIXr  rv  vr=  r  r   sectionr4  s
             r:   load_config_environApplication.load_config_environ  s     "**34X
JFSJJ$$&DA||F##91@ !"#$A%jG &:1&=> ' 	):&rE   c              #  F  ^^#    Uc  U R                   n[        S U R                  U5       5       5      mSU4S jjm TR                  5       n[        U4S jTR	                  5        5       5      mTU:X  a  OM<  TR	                  5        H  u  p4U(       d  M  Uv   M     g7f)a  
Yields only classes with configurable traits, and their subclasses.

:param classes:
    The list of classes to iterate; if not set, uses :attr:`classes`.

Thus, produced sample config-file will contain all classes
on which a trait-value may be overridden:

- either on the class owning the trait,
- or on its subclasses, even if those subclasses do not define
  any traits themselves.
Nc              3  V   #    U  H  nU[        UR                  S S95      4v   M!     g7f)Tr   N)r  class_own_traits)r  r   s     r:   r  :Application._classes_with_config_traits.<locals>.<genexpr>  s/      $
9 $s++4+89:9s   ')c                B   > [        U4S jU R                   5       5      $ )Nc              3  D   >#    U  H  oT;   =(       a    TU   v   M     g 7fr   rI   )r  bcls_to_configs     r:   r  ZApplication._classes_with_config_traits.<locals>.is_any_parent_included.<locals>.<genexpr>  s!     V1M)>mA.>>s    )r  	__bases__)r   r  s    r:   is_any_parent_includedGApplication._classes_with_config_traits.<locals>.is_any_parent_included  s    VVVVrE   c              3  L   >#    U  H  u  pX=(       d    T" U5      4v   M     g 7fr   rI   )r  r   inc_yesr  s      r:   r  r    s(      ($9LC <!7!<=$9s   !$)r   r>   r?   r  )rn   r   rx   r   r	  )rZ   rn   to_incl_origclr  r  r  s        @@r:   rJ  'Application._classes_with_config_traits  s       ?llG# $
009$
 

	W (--/L' ($1$7$7$9( M ,  )..0KBw 1s   BB!	B!c                R   SU R                   -  /nUR                  S5        UR                  S5        UR                  S5        Uc  U R                  OUn[        U R	                  U5      5      nU H#  nUR                  UR                  U5      5        M%     SR                  U5      $ )z/generate default config file from Configurablesz# Configuration file for %s.r%   zc = get_config()  #noqar   )rg   rm  rn   rl  rJ  class_config_sectionr   )rZ   rn   linesconfig_classesr   s        r:   generate_config_file Application.generate_config_file  s    /$));<R34R")/$,,wd>>wGH!CLL11.AB "yyrE   c                    [        U SS5      (       aM  U R                  R                   H+  n[        [        5         UR                  5         S S S 5        M-     SU l        g g ! , (       d  f       MG  = f)Nr   F)r   r0   r   r   r  closer   )rZ   handlers     r:   close_handlersApplication.close_handlers  sY    4.66  88,,i(MMO )( - (-D$ 7
 )(s   A!!
A0	c                    U R                   R                  SU R                  5        U R                  5         [        R
                  " U5        g )NzExiting application: %s)r0   r2   rg   r  r   r4   )rZ   exit_statuss     r:   r4   Application.exit#  s1    0$))<rE   c                $    U R                  5         g r   )r  r   s    r:   __del__Application.__del__(  s    rE   c                j    U R                   " S0 UD6nUR                  U5        UR                  5         g)ztLaunch a global instance of this Application

If a global instance already exists, this reinitializes and starts it
NrI   )rf  r   r   )r   r$   r7   r5   s       r:   launch_instanceApplication.launch_instance+  s*     ll$V$t		rE   )
r   r   r$   rn   r  r  r   r   r   r   r   )rn   ClassesType | Noner?   z+t.Generator[type[Configurable], None, None])r?   r   )r   r   r?   None)r?   r  )r?   	AnyLogger)r7   r>   r?   r  )r$   ArgvTyper?   r  )r?   t.Generator[str, None, None])rn   r  r?   r  )F)rn   r  r?   r  )r?   r^   )r<  r^   r$   r  r?   r  )r?   z)tuple[dict[str, t.Any], dict[str, t.Any]])
r$   zlist[str] | Noner   r   r   r   rn   r  r?   r   )r  r  r?   	list[str])NF)
r  r^   r  #str | t.Sequence[str | None] | Noner0   zAnyLogger | Noner  r  r?   zt.Generator[t.Any, None, None])r?   r  )r  r^   r  r  r?   r  )rn   r  r?   r^   )r   )r  zint | str | Noner?   r  )r$   r  r7   r>   r?   r  )erJ   rK   rL   rM   r_   r   rg   __annotations__rh   ri   rj   rk   r   r  r   r  rl   rn   rx   rz   r   r$   r   r&   r  r   r`   ra   tagr   rP   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r   r   r   r   r   r   r   rD   r   r   r   r   r   r  r  r/  r.  r8  r7  rA  rF  rE  rS  rV  rI  r[  rL  ra  ri  rw  rz  classmethodr  r  r   r  propertyr  r  r  rJ  r  r  r4   r  r  rN   rb   rc   s   @r:   r=   r=      s   B -4M,BD
)B 4;;T3UK0U:ABT:U7U<CDX<Y9Y>EF\>];]!33 18	H-9 G[ -1!)!	4!. 07u~G,= #'&D
(  $$QR Mll2 
cc	  ("^	cc  -* 
cc 
1f ]L+7GH" I" U#" $"( U^  .0` 
cca n $%<=GW=  
 D
 !4 
 K
 & 
 A
#E7 @ 8<vK4=@TRF giJ

		J '+f),P	cc  Z	cc   & !& ]0 0

7 X9  9 & &'UB1$L0037":42X2/ % %09v	
	
 	
 		

 $	
 
 	
  2  & 0, 0,d 
 !%).5;5; 25; 	5;
 #'5; 
(5; 5;n , , IM''#F'	' '* ' ', -1()(	4(T
 -
  rE   r=   c                    U=(       d    SU-  nU=(       d    SU-  nUR                  S5      u  pEXES00nXES00nXU4SU -   Xs40$ )a  Helper for building basic --trait, --no-trait flags.

Parameters
----------
name : str
    The name of the flag.
configurable : str
    The 'Class.trait' string of the trait to be set/unset with the flag
set_help : unicode
    help string for --name flag
unset_help : unicode
    help string for --no-name flag

Returns
-------
cfg : dict
    A dict with two keys: 'name', and 'no-name', for setting and unsetting
    the trait, respectively.
zset %s=Truezset %s=Falser   TFzno-)r  )rg   configurableset_help
unset_helpr   r  setterunsetters           r:   boolean_flagr  >  se    * 7=<7H<~<J##C(JC4=!FU^$H8$edlX4JKKrE   c                     [         R                  5       (       a  [         R                  5       R                  $ [	        5       $ )ztGet the config object for the global Application instance, if there is one

otherwise return an empty config object
)r=   initializedrf  r3   r   rI   rE   r:   
get_configr  ]  s/    
   ##%,,,xrE   __main__)r9   r+   r?   r+   )r%   r%   )
rg   r^   r  r^   r   r^   r  r^   r?   r   )r?   r   )br_   
__future__r   r@   r   r`   r  r   r  r   typingrB   collectionsr   r   
contextlibr   r   r   logging.configr   textwrapr	   traitlets.config.configurabler
   r   traitlets.config.loaderr   r   r   r   r   r   r   traitlets.traitletsr   r   r   r   r   r   r   r   r   r   traitlets.utils.bunchr   traitlets.utils.nested_updater   traitlets.utils.textr   r    utilsr"   utils.importstringr#   r(  ri   rj   hasattrr$   rk   r  rd  _envvarlowerr&   r  
executableendswithr   TypeVarCallableAnyr+   UnionLoggerr  r^   r   Optionalr  r  rm   rD   r  rG   	FormatterrP   r=   r   default_aliasesr   default_flagsr  r  rJ   r  rI   rE   r:   <module>r%     s   2 #    	  	 
  0   %  M     ( 7 8   ,
 
EG  
EG  sFtCH  **..H"
M
==?m#481]]_**491
 	h
	  ^^F 7 7 F
IIcCJ/0GGGNN$BBC	
&&aee
::affSk"ffQVVL)**	y 	&W&& &*[' [D %%!!L> z! rE   