K iWdZddlmZddlZddlZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZmZddlmZddlmZdd lmZmZd d lmZmZmZm Z ejBr3ejDejFejHejfZ%n ejZ%Gd d e&Z'Gdde'Z(GddeZ)Gdde)Z*ejVddZ,Gdde*Z-y)z/A base class for objects that are configurable.) annotationsN)deepcopy)dedent) Any ContainerDict HasTraitsInstance TraitTypedefaultobserveobserve_compatvalidate)warnings)Bunch)indentwrap_paragraphs)ConfigDeferredConfigLazyConfigValue_is_section_keyc eZdZy)ConfigurableErrorN__name__ __module__ __qualname__c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/traitlets/config/configurable.pyrr(r rc eZdZy)MultipleInstanceErrorNrrr r!r$r$,r"r r$c@eZdZeediZeddZdfd ZeddZ ddZ d ddZ e d e dd Zdd Zeddd Ze d dd ZedddZe ddZedddZeddZxZS) Configurablerz*traitlets.config.configurable.ConfigurableT) allow_nonec jdd}|(jdd|jd<||_jdd}t |dit dfd }|j||||_n|j|j|j|D]}t|||y)aCreate 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. parentNconfigcZ|jvrj|jyy)zRecord traits set by both config and kwargs. They will need to be overridden again after loading config. N)nameadd)changeconfig_override_nameskwargss r!notice_config_overridez5Configurable.__init__..notice_config_overrideas( {{f$%))&++6%r rr.rreturnNone) popgetr*r)super__init__setr _load_config unobservesetattr)selfr0r)r*r1r,r/ __class__s ` @r!r8zConfigurable.__init__9s2Hd+  zz(D)1#)==x  DKHd+ "6"!$ 7 +,  !DK   dkk * -.) .D D$t - .r ct|jDcgc]*}t|trt||r |j,c}Scc}w)zreturn section names as a list)reversed__mro__ issubclassr&r)clscs r! section_nameszConfigurable.section_namessD ckk* !\*z#q/A JJ   s/A c|g}|jr*|j|jj|t}|D]=}|j D](}|j |s|j ||*?|S)aextract 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_configrrE _has_sectionmerge)r=cfgcfgs my_configrDsnames r!rHzConfigurable._find_my_configsu ;; KK 33C8 9H  .A++- .>>%(OOAeH-  . . r c ||jd}||j}|j|}|j5|j D]S\}}||vrit |t rt||}|j|}n$t |tr|j||}t||t|tt|rt |trddlm}t |t r%|j"J|j"j$} ndd} |||} d|d|j&j(d } t+| d k(r | d | dd z } n;t+| d k\r-| d j-dj/t1| z } | | V dddy#1swYyxYw)z load traits from a Config objectNTr*r)get_close_matchesc:tj|tdS)N  stacklevel)rwarn UserWarning)msgs r!rVz'Configurable._load_config..warns#+==ka#PPr zConfig option `z` not recognized by `z`.rz Did you mean `z`?z# Did you mean one of: `{matches}`?, )matches)rXt.Anyr3r4)traitsrErHhold_trait_notificationsitems isinstancergetattr get_valuerr<rrrdifflibrQLoggingConfigurablelogwarningr>rlenformatjoinsorted) r=rKrEr\rMr, config_valueinitialrQrVrZrXs r!r:zConfigurable._load_configs >[[[-F   ..0M((-  * * ,# &/oo&7" "l6>!,@#*$"5'3'='=g'F #L.A'3'='=fTl'K D$(>?(.z,PV7W9!$(;<#xx333#xx//Q0f=G+D61Ft~~G^G^F__abC7|q(!1'!*R@@W*DKK$(IIfWo$> L IE" # # # sBF:F:*CF::Gr*c|jd}|j}|j|j||y)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. TrP)r\rEN)r\rEr:new)r=r.r\rEs r!_config_changedzConfigurable._config_changeds=D) **,  &**V=Qr ct|j|_|j||jj|y)z%Update config and load the new valuesN)rr*r:rJ)r=r*s r! update_configzConfigurable.update_configs4t{{+  &! &!r c|t||sJg}djd|jD}|j|jd|d|jt |ddzt |jdjD](\}}|j||}|j|*d j|S) 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. rYc34K|]}|jywN)r.0ps r! z.Configurable.class_get_help..s C Cs(z ) optionsr-TrP ) r_rh __bases__rGrrfri class_traitsr^class_get_trait_help)rCinst final_help base_classes_vhelps r!class_get_helpzConfigurable.class_get_helps|z$444 yy CS]] CC S\\N!L>CD#jm,s233++4+8>>@A $DAq++At4D   d # $yy$$r c |t||sJg}d|jd|j}t|ttfrm|j j dd}t|trd}n'd|jjjz}|dk(r |d|d }n%|d |d }n|d |jjd }|j|| |j}|d k7r5djt|d}|jt|d|jjvr+|jtd|jz|6|jtdt||jxsd nF |j!}|3t%|dkDr|ddd z}|jtd|zdj|S#t"$rd}YSwxYw)aGet 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--. multiplicityrGz=z <%s-item-1>=... z=<>rzLEnumz Choices: %sz Current: @=z Default: %s)r_rr,rrmetadatar6r>lowerrGrrhrrinfor`default_value_repr Exceptionrf) rCtraitr~helptextlinesheaderr sample_valuedvrs r!r}z!Configurable.class_get_trait_help s|z$444cll^1UZZL1 ei. / >>--nhGL%&2 ,u/G/G/M/M/OO x'"81\N#6"81\N#6xr%//":":!;1=F V  zzH r>yy2!>?H LL) * U__-- - LL  <= >   LL)GD%**:J,K+N OP Q ..0s8b=cr(U*C VMC$789yy  s#G99 HHc8t|j|y)z4Get the help string for a single trait and print it.N)printr)rCr~s r!class_print_helpzConfigurable.class_print_helpDs c  &'r c|}|jJ|jD]I}t|ts||vs|j dj |jd|usH|}K|S)a7Get 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`. NTrP)r,mrorBr&class_own_traitsr6)rCrclasses defining_clsr)s r!_defining_classzConfigurable._defining_classIsu( zz%%%ggi &F6<0g%++4+8<.css- OAr23A199T733 3r zO#------------------------------------------------------------------------------rYc3VK|]!}t|ts|j#ywrs)rBr&rrts r!rwz4Configurable.class_config_section..{s"d! STVbHc1::"ds))z# rxz) configuration description__doc__rTrPrz# Choices: %sz# Default: %srzrrz # See also: rz# c.z = )rstrr3r)rhr{rr|r6 default_valuer`rGrir^rrrtypersplit) rCrrDbreakerparent_classesrrdescr,r default_reprdefining_classs r!class_config_sectionz!Configurable.class_config_sectionhs 4!"ds}}"dda/ ?!W%!%%m4 %%D3 2.D  LL4 ! LL !#"2"2$"2"?"E"E"GH KD% 335L!$!4!4UG!D!$$::LL5::/T%[111LL!1EJJL!@A - <=::LL5::#3#3D!#r,info_rstrGrrrfrrrrrh) rCr classnamerrttypetermlinerrs r!class_config_rst_docz!Configurable.class_config_rst_docsh LL s//t/<BBDE HAuOO,,E:: 33HEENN$444EEM) LL " ..0s8b=cr(U*Ckk%1 V$5$;<= R ::1!1D LLt - . LL A Dyy!  s)E)) E76E7)r0r[r3r4)r3z list[str])rKrr3r[)NN)rKrrEzlist[str] | Noner\z)dict[str, TraitType[t.Any, t.Any]] | Noner3r4r2)r*rr3r4rs)r~HasTraits | Noner3r)rTraitType[t.Any, t.Any]r~rrz str | Noner3r)r~rr3r4)rrrzt.Sequence[type[HasTraits]]r3ztype[Configurable])rz"t.Sequence[type[HasTraits]] | Noner3r)r3r)rrrr rr*r)r8 classmethodrErHr:r rrnrprr}rrrr __classcell__)r>s@r!r&r&5sZ fb" %F Bt TFB.P  8+/<@ 3 3(3: 3  3j XRR " %% "&# 6 &6 6  6 6 6 p((+6Q <9 9 v) ) r r&cheZdZdZeddZedd dZedd dZ d dZ y ) rczA 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)rr'rdc2t|jtjtjfs@t j |jjd|jdtdtjt|jS)Nz..log should be a Logger or LoggerAdapter, got rrT) r_valueloggingLogger LoggerAdapterrrVr>rrWtcast LoggerType)r=proposals r! _validate_logz!LoggingConfigurable._validate_logsn(..7>>7;P;P*QR MM>>**+, 'q*   vvj(..11r ct|jtrF|jJtjt j |jjSddlm}|jS)Nr)rd) r_r)rcrrrrrd traitlets get_logger)r=rds r! _log_defaultz LoggingConfigurable._log_defaultsN dkk#6 7;;* **66'..$++//: :!~~r c|jsyt|jtjr |jn|jj}t |ddsy|j dS)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. Nhandlersr)rdr_rrloggerr`r)r=rs r!_get_log_handlerz$LoggingConfigurable._get_log_handlersUxx"488W^^? 55  s AA AAc|jsy|jD] }t|j|sd|_"y)z5unset _instance for this class and singleton parents.N) initializedrr_ _instancers r!clear_instancez$SingletonConfigurable.clear_instances@   *H(,,c2&*"  *r c|j$||i|}|jD] }||_ t|j|r |jStd|jdt |jj)aReturns 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 zAn incompatible sibling of 'z(' is already instantiated as singleton: )rrr_r$rr)rCargsr0r~rs r!instancezSingletonConfigurable.instance)s: == ''D MMO *%)" * cmmS )== '.s||n=""&s}}"5">">!?A r c:t|dxr|jduS)zHas an instance been created?rN)hasattrr)rCs r!rz!SingletonConfigurable.initializedUssK(FS]]$-FFr )r3z4t.Generator[type[SingletonConfigurable], None, None])r3r4)rCztype[CT]rr[r0r[r3r)r3bool) rrrrrrrrrrrr r!rrs_I  **))VGGr ).r __future__rrtypingrcopyrtextwraprtraitlets.traitletsrrrr r r r r rrtraitlets.utilsrtraitlets.utils.bunchrtraitlets.utils.textrrloaderrrrr TYPE_CHECKINGUnionrrrrrr$r&rcTypeVarrrrr r!rs5#   %'8LL ??)>)>quu)EEFJJ   - Y 9Y x .",."bQYYt23SG/SGr