
    hW                       S r SSKJr  SSKrSSKrSSKJr  SSK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Jr  SS	KJrJr  S
SKJrJrJrJ r   \RB                  (       a3  \RD                  \RF                  \RH                  \R                     4   r%O\R                  r% " S S\&5      r' " S S\'5      r( " S S\5      r) " S S\)5      r*\RV                  " SSS9r, " S S\*5      r-g)z/A base class for objects that are configurable.    )annotationsN)deepcopy)dedent)
Any	ContainerDict	HasTraitsInstance	TraitTypedefaultobserveobserve_compatvalidate)warnings)Bunch)indentwrap_paragraphs   )ConfigDeferredConfigLazyConfigValue_is_section_keyc                      \ rS rSrSrg)ConfigurableError(    N__name__
__module____qualname____firstlineno____static_attributes__r       pC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\traitlets/config/configurable.pyr   r   (       r#   r   c                      \ rS rSrSrg)MultipleInstanceError,   r   Nr   r   r#   r$   r'   r'   ,   r%   r#   r'   c                  f  ^  \ rS rSr\" \S0 5      r\" SSS9rSU 4S jjr\	SS j5       r
SS jr  S       SS	 jjr\" S
5      \SS j5       5       rSS jr\	SSS jj5       r\	  S       SS jj5       r\	SSS jj5       r\	      SS j5       r\	SS S jj5       r\	S!S j5       rSrU =r$ )"Configurable5   r   z*traitlets.config.configurable.ConfigurableT)
allow_nonec                  >^^ TR                  SS5      nUb(  TR                  SS5      c  UR                  TS'   X l        TR                  SS5      n[        TU ]  " S0 TD6  [        5       mSUU4S jjnU R                  U5        Ub  X0l        OU R                  U R                  5        U R                  U5        T H  n[        XTU   5        M     g)a  Create a configurable given a config config.

Parameters
----------
config : Config
    If this is empty, default values are used. If config is a
    :class:`Config` instance, it will be used to configure the
    instance.
parent : Configurable instance, optional
    The parent Configurable instance of this object.

Notes
-----
Subclasses of Configurable must call the :meth:`__init__` method of
:class:`Configurable` *before* doing anything else and using
:func:`super`::

    class MyConfigurable(Configurable):
        def __init__(self, config=None):
            super(MyConfigurable, self).__init__(config=config)
            # Then any other code you need to finish initialization.

This ensures that instances will be configured properly.
parentNconfigc                ^   > U R                   T;   a  TR                  U R                   5        gg)zjRecord traits set by both config and kwargs.

They will need to be overridden again after loading config.
N)nameadd)changeconfig_override_nameskwargss    r$   notice_config_override5Configurable.__init__.<locals>.notice_config_overridea   s(    
 {{f$%))&++6 %r#   r   r3   r   returnNone)popgetr/   r.   super__init__setr   _load_config	unobservesetattr)selfr5   r.   r/   r6   r1   r4   	__class__s    `    @r$   r>   Configurable.__init__9   s    2 Hd+zz(D)1#)==x  KHd+ 	"6" !$	7 	7 	+,  !K dkk*-.)DDt- *r#   c                    [        U R                  5       Vs/ s H8  n[        U[        5      (       d  M  [        X5      (       d  M,  UR                  PM:     sn$ s  snf )zreturn section names as a list)reversed__mro__
issubclassr*   r   )clscs     r$   section_namesConfigurable.section_names   sO    
 ckk*
*!\* /9#/A AJJ*
 	
 
s   AAAc                ,   U/nU R                   (       a*  UR                  U R                   R                  U5      5        [        5       nU HE  nU R	                  5        H.  nUR                  U5      (       d  M  UR                  XE   5        M0     MG     U$ )a  extract my config from a global Config object

will construct a Config object of only the config values that apply to me
based on my mro(), as well as those of my parent(s) if they exist.

If I am Bar and my parent is Foo, and their parent is Tim,
this will return merge following config sections, in this order::

    [Bar, Foo.Bar, Tim.Foo.Bar]

With the last item being the highest priority.
)r.   append_find_my_configr   rL   _has_sectionmerge)rC   cfgcfgs	my_configrK   snames         r$   rP   Configurable._find_my_config   sx     u;;KK33C89H	A++- >>%((OOAH-	 .  r#   c           
        Uc  U R                  SS9nUc  U R                  5       nU R                  U5      nU R                  5          UR	                  5        GHm  u  pVXS;   aq  [        U[        5      (       a  [        X5      nUR                  U5      nO([        U[        5      (       a  UR                  X5   5      n[        X[        U5      5        M|  [        U5      (       a  M  [        U[        5      (       a  M  SSKJn  [        U [         5      (       a&  U R"                  c   eU R"                  R$                  n	OSS jn	U" XS5      n
SU SU R&                  R(                   S	3n[+        U
5      S
:X  a  USU
S    S3-  nO9[+        U
5      S
:  a*  USR-                  SR/                  [1        U
5      5      S9-  nU	" U5        GMp     SSS5        g! , (       d  f       g= f)z load traits from a Config objectNTr/   r   )get_close_matchesc                6    [         R                  " U [        SS9$ )N	   
stacklevel)r   warnUserWarning)msgs    r$   r_   'Configurable._load_config.<locals>.warn   s    #+==ka#PPr#   zConfig option `z` not recognized by `z`.r   z  Did you mean `z`?z#  Did you mean one of: `{matches}`?, )matches)ra   t.Anyr9   r:   )traitsrL   rP   hold_trait_notificationsitems
isinstancer   getattr	get_valuer   rB   r   r   r   difflibrZ   LoggingConfigurablelogwarningrD   r   lenformatjoinsorted)rC   rS   rL   rf   rU   r1   config_valueinitialrZ   r_   rd   ra   s               r$   r@   Configurable._load_config   s    >[[[-F  ..0M((-	 **,&/oo&7">!,@@ #*$"5'3'='=g'F#L.AA'3'='=fl'K D(>?(..z,PV7W7W9!$(;<<#xx333#xx//Q 0=G+D61Ft~~G^G^F__abC7|q(!1'!*R@@W*DKK$(IIfWo$>  L    IE '8 -,,s   BG&G=CG
G!r/   c                v    U R                  SS9nU R                  5       nU R                  UR                  X#S9  g)zUpdate all the class traits having ``config=True`` in metadata.

For any class trait with a ``config`` metadata attribute that is
``True``, we update the trait with the value of the corresponding
config entry.
TrY   )rf   rL   N)rf   rL   r@   new)rC   r3   rf   rL   s       r$   _config_changedConfigurable._config_changed   s;     D)
 **,&**VQr#   c                    [        U R                  5      U l        U R                  U5        U R                  R                  U5        g)z%Update config and load the new valuesN)r   r/   r@   rR   )rC   r/   s     r$   update_configConfigurable.update_config   s4     t{{+&!&!r#   c                   Ub  [        X5      (       d   e/ nSR                  S U R                   5       5      nUR                  U R                   SU S35        UR                  [        US   5      S-  5        [        U R                  SS9R                  5       5       H'  u  pEU R                  XQ5      nUR                  U5        M)     S	R                  U5      $ )
zGet the help string for this class in ReST format.

If `inst` is given, its current trait values will be used in place of
class defaults.
rc   c              3  8   #    U  H  oR                   v   M     g 7fN)r   .0ps     r$   	<genexpr>.Configurable.class_get_help.<locals>.<genexpr>  s      C]]s   (z	) optionsr   -TrY   
)
ri   rr   	__bases__rO   r   rp   rs   class_traitsrh   class_get_trait_help)rJ   inst
final_helpbase_classes_vhelps          r$   class_get_helpConfigurable.class_get_help   s     |z$4444
yy CS]] CCS\\N!L>CD#jm,s233++4+8>>@ADA++A4Dd# B yy$$r#   c           
     N   Ub  [        X 5      (       d   e/ nSU R                   SUR                   3n[        U[        [        45      (       as  UR
                  R                  SS5      n[        U[        5      (       a  SnO'SUR                  R                  R                  5       -  nUS:X  a	  U SU S	3nO%U S
U S	3nOU SUR                  R                   S3nUR                  U5        Uc  UR                  nUS:w  a5  SR                  [        US5      5      nUR                  [        U5      5        SUR                  R                  ;   a+  UR                  [        SUR                  5       -  5      5        Ub;  UR                  [        S[        X!R                  =(       d    S5      < 35      5        OH UR!                  5       nUb4  [%        U5      S:  a  USS S	-   nUR                  [        SU-  5      5        SR                  U5      $ ! ["         a    Sn NVf = f)zGet the helptext string for a single trait.

:param inst:
    If given, its current trait values will be used in place of
    the class default.
:param helptext:
    If not given, uses the `help` attribute of the current trait.
Nz--.multiplicityrO   z<key-1>=<value-1>z<%s-item-1>=... z=<> r   L   EnumzChoices: %sz	Current: @   =   zDefault: %s)ri   r   r1   r   r   metadatar<   rD   lowerrO   r   rr   r   r   inforj   default_value_repr	Exceptionrp   )	rJ   traitr   helptextlinesheaderr   sample_valuedvrs	            r$   r   !Configurable.class_get_trait_help  s    |z$4444cll^1UZZL1ei.// >>--nhGL%&&2,u/G/G/M/M/OOx'"81\N#6"81\N#6xr%//":":!;1=FVzzHr>yy2!>?HLL)*U__---LL

 <=>LL)GD**:J,K+N OPQ..0 s8b=cr(U*CVMC$789yy  s   =H H$#H$c                8    [        U R                  U5      5        g)z4Get the help string for a single trait and print it.N)printr   )rJ   r   s     r$   class_print_helpConfigurable.class_print_helpD  s     	c  &'r#   c                    U nUR                   c   eU R                  5        HQ  n[        U[        5      (       d  M  XB;   d  M!  UR	                  SS9R                  UR                   S5      UL d  MO  UnMS     U$ )a  Get the class that defines a trait

For reducing redundant help output in config files.
Returns the current class if:
- the trait is defined on this class, or
- the class where it is defined would not be in the config file

Parameters
----------
trait : Trait
    The trait to look for
classes : list
    The list of other classes to consider for redundancy.
    Will return `cls` even if it is not defined on `cls`
    if the defining class is not in `classes`.
NTrY   )r1   mrorI   r*   class_own_traitsr<   )rJ   r   classesdefining_clsr.   s        r$   _defining_classConfigurable._defining_classI  sq    ( zz%%%ggiF6<00%++4+8<<UZZNRWW%   r#   c           	        SS jnSnSR                  S U R                   5       5      nSU R                   SU S3nX5U/nU R                  5       R	                  S5      nU(       a  UR
                  nU(       d  [        U S	S
5      nU(       a(  UR                  U" U5      5        UR                  S
5        [        U R                  SS9R                  5       5       GHR  u  pU	R                  5       n
U(       a  U R                  X5      nOU nXL a  U	R                  (       a!  UR                  U" U	R                  5      5        S[        U	5      R                  ;   a"  UR                  SU	R                  5       -  5        UR                  SU
-  5        OfU	R                  (       a4  UR                  U" U	R                  R                  SS5      S   5      5        UR                  SUR                   SU 35        UR                  SU R                   SU SU
 35        UR                  S
5        GMU     SR                  U5      $ )zGet the config section for this class.

Parameters
----------
classes : list, optional
    The list of other classes in the config file.
    Used to reduce redundant information.
c                b    SR                  [        U S5      5      n SU R                  SS5      -   $ )z"return a commented, wrapped block.z

N   z## r   z
#  )rr   r   replace)ss    r$   rK   ,Configurable.class_config_section.<locals>.cs  s-    OAr23A199T7333r#   zO#------------------------------------------------------------------------------rc   c              3  h   #    U  H(  n[        U[        5      (       d  M  UR                  v   M*     g 7fr   )rI   r*   r   r   s     r$   r   4Configurable.class_config_section.<locals>.<genexpr>{  s!     "d}!
STVbHc:1::}s   22z# r   z) configurationdescription__doc__r   TrY   r   z#  Choices: %sz#  Default: %sr   r   r   z#  See also: r   z# c.z = )r   strr9   r   )rr   r   r   r   r<   default_valuerj   rO   rs   rh   r   r   r   typer   split)rJ   r   rK   breakerparent_classesr   r   descr1   r   default_reprdefining_classs               r$   class_config_section!Configurable.class_config_sectionh  s   	4 !"ds}}"dda/?W%!%%m4%%D3	2.DLL4!LL!#"2"2$"2"?"E"E"GHKD 335L!$!4!4U!D!$$::LL5::/T%[111LL!1EJJL!@A-<= ::LL5::#3#3D!#<Q#?!@A}^-D-D,EQtfMNLL4~QtfC~FGLL/ I0 yyr#   c                   / nU R                   n[        U R                  SS9R                  5       5       GH+  u  p4UR                  R                   nUR
                  (       d  M/  US-   UR
                  -   nSU;   a  USUR                  5       -   -  nOUSU-   -  nUR                  U5         UR                  5       nUbW  [        U5      S:  a  USS S	-   nUR                  S
S5      nUR                  [        SU-  5      5        UR                  S5        UR                  =(       d    SnUR                  [        [        U5      5      5        UR                  S5        GM.     SR                  U5      $ ! [         a    Sn Nf = f)zgGenerate rST documentation for this class' config options.

Excludes traits defined on parent classes.
TrY   r   r   z : Nr   r   r   z\nz\\nzDefault: ``%s``r   zNo descriptionr   )r   rs   r   rh   rD   r1   info_rstrO   r   r   rp   r   r   r   r   rr   )	rJ   r   	classnamer   r   ttypetermliner   r   s	            r$   class_config_rst_doc!Configurable.class_config_rst_doc  sb    LL	s//t/<BBDEHAOO,,E:: 33H EENN$444EEM)LL"..0 s8b=cr(U*Ckk%1V$5$;<=R ::1!1DLLt-. LLA FD yy!  s   -E66FF)r/   r.   )r5   re   r9   r:   )r9   z	list[str])rS   r   r9   re   )NN)rS   r   rL   zlist[str] | Nonerf   z)dict[str, TraitType[t.Any, t.Any]] | Noner9   r:   r8   )r/   r   r9   r:   r   )r   HasTraits | Noner9   r   )r   TraitType[t.Any, t.Any]r   r   r   z
str | Noner9   r   )r   r   r9   r:   )r   r   r   zt.Sequence[type[HasTraits]]r9   ztype[Configurable])r   z"t.Sequence[type[HasTraits]] | Noner9   r   )r9   r   )r   r   r    r!   r
   r   r/   r.   r>   classmethodrL   rP   r@   r   r   ry   r|   r   r   r   r   r   r   r"   __classcell__)rD   s   @r$   r*   r*   5   sZ   fb"%FBtTFB.P 
 
8 +/<@	33 (3 :	3
 
3j XR  R "  % %   "&#	6 &6  6  	6 
 
6  6 p ( ( +6Q	 < 9  9 v )  ) r#   r*   c                  p    \ rS rSrSr\" SSS9r\" S5      SS j5       r\	" S5      SS j5       r
SS	 jrS
rg)rm   i  zA parent class for Configurables that log.

Subclasses have a log trait, and the default behavior
is to get the logger from the currently running Application.
z Logger or LoggerAdapter instanceF)r   r,   rn   c                :   [        UR                  [        R                  [        R                  45      (       d>  [
        R                  " U R                  R                   SUR                   S3[        SS9  [        R                  " [        UR                  5      $ )Nz..log should be a Logger or LoggerAdapter, got r      r]   )ri   valueloggingLoggerLoggerAdapterr   r_   rD   r   r`   tcast
LoggerType)rC   proposals     r$   _validate_log!LoggingConfigurable._validate_log  sq    (..7>>7;P;P*QRRMM>>**+ , 'q*	 vvj(..11r#   c                    [        U R                  [        5      (       aH  U R                  c   e[        R                  " [
        R                  U R                  R                  5      $ SSKJn  UR                  5       $ )Nr   )rn   )
ri   r.   rm   r   r   r   r   rn   	traitlets
get_logger)rC   rn   s     r$   _log_default LoggingConfigurable._log_default  sQ    dkk#677;;***66'..$++//::!~~r#   c                    U R                   (       d  g[        U R                   [        R                  5      (       a  U R                   OU R                   R                  n[        USS5      (       d  gUR                  S   $ )zReturn the default Handler

Returns None if none can be found

Deprecated, this now returns the first log handler which may or may
not be the default one.
Nhandlersr   )rn   ri   r   r   loggerrj   r   )rC   r   s     r$   _get_log_handler$LoggingConfigurable._get_log_handler  s[     xx"488W^^<<DHH$((// 	 vz400q!!r#   r   N)r   r   r9   r   )r9   r   )r9   zlogging.Handler | None)r   r   r    r!   r   r   rn   r   r   r   r   r   r"   r   r#   r$   rm   rm     sI     5%
HCe_	2 	2 U^   "r#   rm   CTSingletonConfigurable)boundc                  l    \ rS rSrSrSr\S	S j5       r\S
S j5       r\SS j5       r	\SS j5       r
Srg)r   i  zA configurable that only allows one instance.

This class is for classes that should only have one instance of itself
or *any* subclass. To create and retrieve such a class use the
:meth:`SingletonConfigurable.instance` method.
Nc              #     #    U R                  5        H<  n[        X5      (       d  M  [        U[        5      (       d  M,  U[        :w  d  M8  Uv   M>     g7f)zVWalk the cls.mro() for parent classes that are also singletons

For use in instance()
N)r   rI   r   rJ   subclasss     r$   	_walk_mroSingletonConfigurable._walk_mro  s>      	H3))x)>?? 55 "s   "AAA	Ac                    U R                  5       (       d  gU R                  5        H'  n[        UR                  U 5      (       d  M   SUl        M)     g)z5unset _instance for this class and singleton parents.N)initializedr   ri   	_instancer   s     r$   clear_instance$SingletonConfigurable.clear_instance  sA       H(,,c22 &*"	 (r#   c                $   U R                   c%  U " U0 UD6nU R                  5        H	  nX4l         M     [        U R                   U 5      (       a  U R                   $ [        SU R                   S[        U R                   5      R                   35      e)a  Returns a global instance of this class.

This method create a new instance if none have previously been created
and returns a previously created instance is one already exists.

The arguments and keyword arguments passed to this method are passed
on to the :meth:`__init__` method of the class upon instantiation.

Examples
--------
Create a singleton class using instance, and retrieve it::

    >>> from traitlets.config.configurable import SingletonConfigurable
    >>> class Foo(SingletonConfigurable): pass
    >>> foo = Foo.instance()
    >>> foo == Foo.instance()
    True

Create a subclass that is retrieved using the base class instance::

    >>> class Bar(SingletonConfigurable): pass
    >>> class Bam(Bar): pass
    >>> bam = Bam.instance()
    >>> bam == Bar.instance()
    True
zAn incompatible sibling of 'z(' is already instantiated as singleton: )r   r   ri   r'   r   r   )rJ   argsr5   r   r   s        r$   instanceSingletonConfigurable.instance)  s    : == ''D  MMO%)" , cmmS))== '.s||n =""&s}}"5">">!?A r#   c                D    [        U S5      =(       a    U R                  SL$ )zHas an instance been created?r   N)hasattrr   )rJ   s    r$   r   !SingletonConfigurable.initializedU  s     sK(FS]]$-FFr#   r   )r9   z4t.Generator[type[SingletonConfigurable], None, None])r9   r:   )rJ   ztype[CT]r   re   r5   re   r9   r   )r9   bool)r   r   r    r!   r   r   r   r   r   r   r   r"   r   r#   r$   r   r     s_     I  * * ) )V G Gr#   ).r   
__future__r   r   typingr   copyr   textwrapr   traitlets.traitletsr   r   r   r	   r
   r   r   r   r   r   traitlets.utilsr   traitlets.utils.bunchr   traitlets.utils.textr   r   loaderr   r   r   r   TYPE_CHECKINGUnionr   r   r   r   r   r'   r*   rm   TypeVarr   r   r   r#   r$   <module>r     s    5 #       % ' 8 L L ??)>)>quu)EEFJJ		 		- 	Y 9 Y x.", ."b YYt23SG/ SGr#   