
    Mi '                        S SK Jr  S SKrS SKrS SKJr  S SKJrJrJ	r	J
r
Jr  \R                  S:  a  S SKJr  OS SKJr  SSKJrJr  SS	KJrJr  SS
KJrJr   " S S\5      rS rSS jrSS.       SS jjrg)    )annotationsN)Path)AnyDictListOptionalUnion)      )Self   )ConfectionErrorConfigValidationError)parse_configserialize_config)ValidationErrorensure_schemac                  ,   \ rS rSr% SrS\S'    SSSS.       SS jjjrSS jrSS	 jr S     SS
 jjr	SS jr
SS jrS0 SS.       SS jjrSS.SS jjrSS.SS jjrS0 S.       SS jjrSS.S S jjrS0 S.       S!S jjrSrg)"Config   zUDict subclass to save TOML-style configuration format from/to string, file
or bytes.
boolis_interpolatedNr   section_orderc                  [         R                  U 5        Uc  0 n[        U[         [        45      (       d  [	        S[        U5       35      eUb  X l        O.[        U[        5      (       a  UR                  U l        OSU l        Ub  X0l        O.[        U[        5      (       a  UR                  U l        O/ U l        U R                  U5        g)z2Initialize a new Config object with optional data.NzDCan't initialize Config with data. Expected dict or Config but got: T)	dict__init__
isinstancer   r   typer   r   update)selfdatar   r   s       l/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/confection/_config.pyr   Config.__init__   s     	d<D$v//!##':,0  &#2 f%%#'#7#7D #'D $!.f%%!%!3!3D!#DD    c                \    [        U 5      " 5       R                  U R                  5       5      $ )zNInterpolate (resolve var references) a config.

Returns a copy of the object.
)r   from_strto_str)r!   s    r#   interpolateConfig.interpolate<   s!     Dz|$$T[[]33r%   c                x    [         R                  " U 5      n[        U 5      " UU R                  U R                  S9$ )zDeepcopy the config.r   )copydeepcopyr   r   r   )r!   configs     r#   r,   Config.copyG   s6    t$Dz 00,,
 	
r%   c                    U R                  5       n[        U5      R                  5       n[        XUS9n[        U 5      " UUR                  =(       a    UR                  UR
                  S9$ )z>Deep merge the config with updates, using current as defaults.remove_extrar   )r,   r   deep_merge_configsr   r   r   )r!   updatesr2   defaultsmergeds        r#   mergeConfig.mergeP   s^     99;/&&(#GLQDz$44P9P9P"00
 	
r%   c                F    [        U5      n[        [        U 5      X5        U $ )zXValidate the config against a schema. Raises ConfigValidationError
if validation fails.
)r   _validate_recursiver   )r!   schemas     r#   validateConfig.validate]   s!     v&DJ5r%   c                p   [        U5      nUR                  R                  SS5      nUR                  R	                  5        H  u  p4X0;  a%  UR                  5       (       d  UR                  X'   M/  X0;   d  M6  [        X   [        5      (       d  MO  UR                  n[        U[        5      (       d  Mr  [        US5      (       d  M  [        U5      n[        X   U5        M     US:X  aL  [        UR                  R                  5       5      n[        U R                  5       5       H  nX;  d  M
  X	 M     U $ )zFill in missing values from schema defaults and remove extra
fields if the schema forbids them. Modifies in place and returns self.
extraallowmodel_fieldsforbid)r   model_configgetrA   itemsis_requireddefaultr   r   
annotationr   hasattr_fill_defaults_recursivesetkeyslist)	r!   r;   r?   namefieldfield_schema
sub_schemaknownkeys	            r#   fill_defaultsConfig.fill_defaultse   s     v&##''9!..446KD(9(9(;(;"]]
*TZ">">$//lD11g .7 7 "/|!<J,TZD 7 H++0023EDIIK(#	 ) r%   T)r)   	overridesr;   c                   U R                  5         U R                  [        XUS95        U(       a  U(       a  U R                  5       n X l        Ub"  U R                  U5        U R                  U5        U $ )zLoad the config from a string.r)   rV   )clearr    r   r)   r   rT   r<   )r!   textr)   rV   r;   s        r#   r'   Config.from_str~   s`     	

L)TU ##%D*v&MM&!r%   r)   c                   [        XS9$ )zWrite the config to a string.r\   )r   r!   r)   s     r#   r(   Config.to_str   s    >>r%   c               >    U R                  US9R                  S5      $ )z&Serialize the config to a byte string.r\   utf8)r(   encoder^   s     r#   to_bytesConfig.to_bytes   s    {{{{3::6BBr%   rX   c               @    U R                  UR                  S5      X#S9$ )z#Load the config from a byte string.ra   rX   )r'   decode)r!   
bytes_datar)   rV   s       r#   
from_bytesConfig.from_bytes   s*     }}f%;  
 	
r%   c                   [        U[        5      (       a  [        U5      OUnUR                  SSS9 nUR	                  U R                  US95        SSS5        g! , (       d  f       g= f)zSerialize the config to a file.wra   encodingr\   N)r   strr   openwriter(   )r!   pathr)   file_s       r#   to_diskConfig.to_disk   sN    'c22tDzYYsVY,KK<= -,,s   A
A)c                   [        U[        5      (       a  [        U5      OUnUR                  SSS9 nUR	                  5       nSSS5        U R                  WX#S9$ ! , (       d  f       N= f)zLoad config from a file.rra   rl   NrX   )r   rn   r   ro   readr'   )r!   rq   r)   rV   rr   rZ   s         r#   	from_diskConfig.from_disk   sY     (c22tDzYYsVY,::<D -}}T{}PP -,s   A
A*)N)r"   z)Optional[Union[Dict[str, Any], 'Config']]r   zOptional[bool]r   zOptional[List[str]]returnNone)rz   r   )F)r4   zUnion[Dict[str, Any], 'Config']r2   r   rz   r   )rZ   rn   r)   r   rV   Dict[str, Any]rz   r   )r)   r   rz   rn   )r)   r   rz   bytes)rg   r}   r)   r   rV   r|   rz   r   )rq   Union[str, Path]r)   r   rz   r{   )rq   r~   r)   r   rV   r|   rz   r   )__name__
__module____qualname____firstlineno____doc____annotations__r   r)   r,   r7   r<   rT   r'   r(   rc   rh   rs   rx   __static_attributes__ r%   r#   r   r      sM     ;?  +/-1 7  (	 
 +  
 D	4
 NS
6
FJ
	
: !$& 	
 " 
* -1 ? /3 C !$&



 	


 "

 


 FJ > !$&QQ 	Q
 "Q 
Q Qr%   r   c                V   UR                   R                  SS5      nUR                  R                  5        H  u  p4X0;  a%  UR	                  5       (       d  UR
                  X'   M/  X0;   d  M6  [        X   [        5      (       d  MO  UR                  n[        U[        5      (       d  Mr  [        US5      (       d  M  [        X   [        U5      5        M     US:X  aM  [        UR                  R                  5       5      n[        U R                  5       5       H  nXv;  d  M
  X	 M     gg)z>Fill defaults and strip extras recursively for nested schemas.r?   r@   rA   rB   N)rC   rD   rA   rE   rF   rG   r   r   rH   r   rI   rJ   r   rK   rL   rM   )r"   r;   r?   rN   rO   rP   rR   rS   s           r#   rJ   rJ      s    ##GW5E**002E$5$5$7$7DJ\jT:: ++L,--',2W2W(]<5PQ 3 F'',,./		$CI % r%   c                    UR                  U 5        UR                  R                  5        Hx  u  pgUR                  n[        U[        5      (       d  M(  [        US5      (       d  M;  X`;   d  MB  [        X   [        5      (       d  M[  U(       a  U SU 3OUn	[        X   XU	S	9  Mz     g! [         a1  nU(       a  SU S3OSn[        UUR                  5       SU 3S9SeSnAff = f)
z>Validate data against a schema, recursing into nested schemas.z in [] zConfig validation error)r.   errorstitleNmodel_validate.)parent)r   r   r   r   rA   rE   rH   r   r   rI   r   r:   )
r"   r;   r.   r   esectionrN   rO   rH   child_parents
             r#   r:   r:      s    d# **002%%
z4((
$4554:t,,17fXQtf-TL
J|T 3  '-E&#2#88:+G95
 		s   B* *
C%4,C  C%Fr1   c                  U(       a+  [        U R                  5       5      nU H  nXA;  d  M
  X	 M     UR                  5        GH  u  pE[        U[        5      (       a  U R                  U0 5      n[        U[        5      (       d  MD  U Vs/ s H  owR                  S5      (       d  M  UPM     nnU(       a  US   OSn	U(       a*  U Vs/ s H  owR                  S5      (       d  M  UPM     snO/ n
U
(       a  U
S   OSnU	(       a  U(       a  X;   a  Xi   XY   :w  a  M  U(       a  X;  d
  Xk   X[   :w  a  M  [        XeUS9nM  X@;  d  GM  XPU'   GM     U $ s  snf s  snf )zDeep merge two configs.@r   Nr1   )rM   rL   rE   r   r   
setdefault
startswithr3   )r.   r5   r2   rL   rS   valuenodekvalue_promisesvalue_promisenode_promisesnode_promises               r#   r3   r3      s.    FKKM"C"K  nn&
eT""$$S"-DdD))).DA,,s2CaND1?N1-TMFJB1S0AQBPRM/<=+$L  !)+u/CC )T-?5CV-V)$LQH3K5 '6 M- EBs   E(E	E&E)r   )r.   Union[Dict[str, Any], Config]r5   r   r2   r   rz   r   )
__future__r   r,   syspathlibr   typingr   r   r   r   r	   version_infor   typing_extensions_errorsr   r   _parserr   r   
validationr   r   r   r   rJ   r:   r3   r   r%   r#   <module>r      s~    "  
  3 3w& ; 3 6fQT fQR"U8 	()(+( 	(
 #(r%   