
    ُkh~                        d dl Z d dlZd dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZmZmZmZmZmZmZ d dlmZ dd	lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd
l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ee6e7e8ee9e:f   Z;e G d d             Z<e G d de<             Z= G d de      Z> G d de>      Z? G d de?      Z@ G d de      ZA G d de?      ZBy)    N)ABCabstractmethod)defaultdict)	dataclassfield)Enum)	AnyDictIteratorListOptionalSetTupleTypeUnion)ParserRuleContext   )_DEFAULT_MARKER_NoneType	ValueKind
_get_value_is_interpolation_is_missing_value_is_specialformat_and_raiseget_value_kindis_union_annotationis_valid_value_annotation	split_keytype_str)	ConfigKeyErrorConfigTypeErrorInterpolationKeyErrorInterpolationResolutionError InterpolationToMissingValueErrorInterpolationValidationErrorMissingMandatoryValueUnsupportedInterpolationTypeValidationError)OmegaConfGrammarParser)parse)GrammarVisitorc                       e Zd ZU eee   ef   ed<   eee   ef   ed<   eed<   eed<   dZe	e
eef      ed<   dZeed<    ed	 
      Ze
eef   ed<   ddZedeee   ef   fd       Zy)Metadataref_typeobject_typeoptionalkeyNflagsF
flags_rootc                       t        t              S N)r   dict     J/var/www/teggl/fontify/venv/lib/python3.12/site-packages/omegaconf/base.py<lambda>zMetadata.<lambda>A   s    ;tCT r9   )default_factoryresolver_cachereturnc                 ,    | j                   i | _         y y r6   )r3   selfs    r:   __post_init__zMetadata.__post_init__C   s    ::DJ r9   c                 X    | j                   rt        | j                     S | j                  S )z<Compute `type_hint` from `self.optional` and `self.ref_type`)r1   r   r/   r@   s    r:   	type_hintzMetadata.type_hintG   s$     ==DMM**== r9   r>   N)__name__
__module____qualname__r   r   r	   __annotations__boolr3   r   r
   strr4   r   r=   rB   propertyrD   r8   r9   r:   r.   r.   ,   s     DIsN##tCy#~&&N	H (,E8DdO$+ J%*;T%UNDcNU !5cC0 ! !r9   r.   c                   2    e Zd ZU dZeed<   dZeed<   ddZy)ContainerMetadataNkey_typeelement_typec                 @   | j                   t        | _         | j                  t        u st        | j                  t              sJ | j
                  9t        | j
                        s$t        dt        | j
                  d       d      | j                  i | _	        y y )NzUnsupported value type: 'T)include_module_name')
r/   r	   rO   
isinstancetyperP   r   r)   r    r3   r@   s    r:   rB   zContainerMetadata.__post_init__X   s    == DM}}#z$--'FFF(,T->->?%/9J9J`d0e/ffgh  ::DJ r9   rE   )rF   rG   rH   rO   r	   rI   rP   rB   r8   r9   r:   rN   rN   S   s    HcL#r9   rN   c                   &   e Zd ZU eed<   ed   ed<   eeeee   f      ed<   ded   defdZ	deee
f   fd	Zd
eee
f   ddfdZded   ddfdZd6dZded   fdZded   fdZdeee   ef   deeee      ee   f   dd fdZdedee   fdZdedee   fdZdedee   fdZ	 	 d7de
de
dedee   de
ddfdZedeeeef      defd       Zd8d Z	 	 d9d!ed"eee      ded    fd#Z	 d:d!ed"eee      ded    fd$Z d;d%Z!defd&Z"defd'Z#ed(e
defd)       Z$ed(e
defd*       Z%edefd+       Z&ede
fd,       Z'ed:de
deeeef      ddfd-       Z(edefd.       Z)edefd/       Z*de
fd0Z+de
ddfd1Z,defd2Z-d3eddfd4Z.defd5Z/y)<Node	_metadataBox_parent_flags_cacheparentmetadatac                 ^    || j                   d<   || j                   d<   d | j                   d<   y )NrX   rZ   r[   __dict__)rA   r\   r]   s      r:   __init__zNode.__init__l   s,    %-k"#)i (,n%r9   r>   c                 J    t        j                   | j                        }|d= |S Nr[   )copyr`   rA   
state_dicts     r:   __getstate__zNode.__getstate__q   s"    YYt}}-
~&r9   rf   Nc                 X    | j                   j                  |       d | j                   d<   y rc   )r`   updatere   s     r:   __setstate__zNode.__setstate__w   s"    Z((,n%r9   c                 j    |t        |t              sJ || j                  d<   | j                          y NrZ   )rT   rY   r`   _invalidate_flags_cacherA   r\   s     r:   _set_parentzNode._set_parent{   s0    ~FC!888#)i $$&r9   c                 "    d | j                   d<   y rc   r_   r@   s    r:   rm   zNode._invalidate_flags_cache   s    (,n%r9   c                 L    | j                   d   }|t        |t              sJ |S rl   )r`   rT   rY   rn   s     r:   _get_parentzNode._get_parent   s)    y)~FC!888r9   	Containerc                     | j                   d   }|t        |t              sJ t        |t              r%|j                   d   }|t        |t              sJ |S |t        |t              sJ |S )z{
        Like _get_parent, but returns the grandparent
        in the case where `self` is wrapped by a UnionNode.
        rZ   )r`   rT   rY   	UnionNoders   )rA   r\   grandparents      r:   _get_parent_containerzNode._get_parent_container   sr    
 y)~FC!888fi( //)4K&*[)*LLL>Z	%BBBMr9   r3   valuesc                    t        |t              r|g}|t        |t              r|g}t        |      dk(  rt        |      |z  }t        |      t        |      k7  rt	        d      t        |      D ]  \  }}||   }|I| j                  j                  J || j                  j                  v s>| j                  j                  |= V| j                  j                  J || j                  j                  |<    | j                          | S )Nr   z3Inconsistent lengths of input flag names and values)	rT   rK   rJ   len
ValueError	enumeraterX   r3   rm   )rA   r3   rx   idxflagvalues         r:   	_set_flagzNode._set_flag   s    
 eS!GE>Z5XFv;!Z&(Fu:V$RSS"5) 	3IC3KE}~~++7774>>///,,T2~~++777-2$$T*	3 	$$&r9   r~   c                 |    | j                   j                  J | j                   j                  j                  |      S )zc
        :param flag: flag to inspect
        :return: the state of the flag on this node.
        )rX   r3   get)rA   r~   s     r:   _get_node_flagzNode._get_node_flag   s5    
 ~~##///~~##''--r9   c                     | j                   d   }|i x}| j                   d<   |j                  |t              }|t        u r| j                  |      }|||<   |t	        |t
              sJ |S rc   )r`   r   r   _get_flag_no_cacherT   rJ   )rA   r~   cacherets       r:   	_get_flagzNode._get_flag   st    n-=466EDMM.1ii./""))$/CE$K{jd333
r9   c                     | j                   j                  }|J ||v r
||   ||   S | j                         ry| j                         }|y|j	                  |      S )z
        Returns True if this config node flag is set
        A flag is set if node.set_flag(True) was called
        or one if it's parents is flag is set
        :return:
        N)rX   r3   _is_flags_rootrr   r   )rA   r~   r3   r\   s       r:   r   zNode._get_flag_no_cache   sq     $$   5=U4[4; !!#> ##D))r9   r2   r   causemsgtype_overridec                 B    t        | |||t        |      n|||       J )N)noder2   r   r   r   r   )r   rK   )rA   r2   r   r   r   r   s         r:   _format_and_raisezNode._format_and_raise   s/     	!kE
s'	
 	ur9   c                      y r6   r8   rA   r2   s     r:   _get_full_keyzNode._get_full_key       r9   c                 2    | j                  d      }|J |S )NT)throw_on_resolution_failure_dereference_node_impl)rA   r   s     r:   _dereference_nodezNode._dereference_node   s&    **t*Lr9   r   memoc                 (    | j                  ||      S )Nr   r   r   )rA   r   r   s      r:   _maybe_dereference_nodezNode._maybe_dereference_node   s"    
 **(C + 
 	
r9   c           
          | j                         s| S | j                         }||rt        d      y |J | j                         }|j	                  ||| t        t        |             ||      S )Nz8Cannot resolve interpolation for a node without a parent)r\   r2   r   
parse_treer   r   )r   rw   r$   _key&_resolve_interpolation_from_parse_treer+   r   )rA   r   r   r\   r2   s        r:   r   zNode._dereference_node_impl  s    
 %%'K++->*2N  !!!iik<<Z-.(C = 
 	
r9   c                 ,   | j                         }|t        | t              sJ | S |t        |t              sJ |j                         5|j                         }|t        |t              sJ |j                         5|t        |t              sJ |S r6   )rr   rT   rs   rY   )rA   roots     r:   	_get_rootzNode._get_root  s    "..0<dI...KJtS$999 ,##%D#
4(===  , JtY$???r9   c                     t        |       S )zY
        Check if the node's value is `???` (does *not* resolve interpolations).
        )r   r@   s    r:   _is_missingzNode._is_missing*  s     !&&r9   c                 &    | j                         du S )zZ
        Check if the node's value is `None` (does *not* resolve interpolations).
        N)_valuer@   s    r:   _is_nonezNode._is_none0  s     {{}$$r9   otherc                      y r6   r8   rA   r   s     r:   __eq__zNode.__eq__6  r   r9   c                      y r6   r8   r   s     r:   __ne__zNode.__ne__:  r   r9   c                      y r6   r8   r@   s    r:   __hash__zNode.__hash__>  r   r9   c                      y r6   r8   r@   s    r:   r   zNode._valueB  r   r9   c                      y r6   r8   )rA   r   r3   s      r:   
_set_valuezNode._set_valueF  r   r9   c                      y r6   r8   r@   s    r:   _is_optionalzNode._is_optionalJ  r   r9   c                      y r6   r8   r@   s    r:   r   zNode._is_interpolationN  r   r9   c                 .    | j                   j                  S r6   rX   r2   r@   s    r:   r   z	Node._keyR  s    ~~!!!r9   c                 &    || j                   _        y r6   r   r   s     r:   _set_keyzNode._set_keyU  s     r9   c                 .    | j                   j                  S r6   )rX   r4   r@   s    r:   r   zNode._is_flags_rootX  s    ~~(((r9   r4   c                 z    | j                   j                  |k7  r"|| j                   _        | j                          y y r6   )rX   r4   rm   )rA   r4   s     r:   _set_flags_rootzNode._set_flags_root[  s1    >>$$
2(2DNN%((* 3r9   c                 :    | j                   j                  t        uS r6   )rX   r/   r	   r@   s    r:   _has_ref_typezNode._has_ref_type`  s    ~~&&c11r9   rE   NN)r>   rW   )FNr6   )r>   rs   )0rF   rG   rH   r.   rI   r   r
   rK   rJ   ra   r	   rg   rj   ro   rm   rr   rw   r   r   r   r   r   r   	Exceptionr   r   DictKeyTypeintr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r9   r:   rW   rW   f   sr   e_4Xd^ 3455-x -( -
d38n -tCH~ -$ -'(5/ 'd '
-Xe_ 
x'<  T#Y^$ d8D>*HTN:; 
	:.3 .8D> .
c 
htn 
*s *x~ *6 "!  	
 c]  
$ %S0@*A!B s   -2#'
%)
 s3x 
 
&		
 $(
%)
 s3x 
 
&		
4
'T '%$ % C D   C D   #       HT#t)_,E QU   d   4  "c "!C !D !) )+$ +4 +
2t 2r9   rW   c                   R     e Zd ZU dZeed<   ded    def fdZdefdZ	d	dZ
 xZS )
rY   z
    Base class for nodes that can contain other nodes.
    Concrete subclasses include DictConfig, ListConfig, and UnionNode.
    _contentr\   r]   c                 F    t         |   ||       d | j                  d<   y )Nr\   r]   r   )superra   r`   )rA   r\   r]   	__class__s      r:   ra   zBox.__init__l  s#    :$(j!r9   r>   c                 ,    t        j                  |       S r6   )rd   deepcopyr@   s    r:   __copy__zBox.__copy__p  s    }}T""r9   c                    ddl m} ddlm} t	        | |      rz| j
                  d   }t	        |t              rZ| j
                  d   j                         D ]9  \  }}||j                  |        t	        |t              s*|j                          ; y y t	        | |      ri| j
                  d   }t	        |t              rI| j
                  d   D ]6  }||j                  |        t	        |t              s'|j                          8 y y t	        | t              rS| j
                  d   }t	        |t              r3|j                  |        t	        |t              r|j                          y y y y )Nr   
DictConfig
ListConfigr   )
dictconfigr   
listconfigr   rT   r`   r7   itemsro   rY   
_re_parentlistru   rW   )rA   r   r   contentr   r   items          r:   r   zBox._re_parentt  sB   ** dJ'mmJ/G'4(#'==#<#B#B#D +KD%())$/!%-((*	+ ) j)mmJ/G'4( MM*5 *D'((.!$,)	* ) i(mmJ/G'4(##D)gs+ &&( , ) )r9   rE   )rF   rG   rH   __doc__r	   rI   r   r.   ra   r   r   __classcell__r   s   @r:   rY   rY   d  s7    
 M)x )( )## #)r9   rY   c                      e Zd ZU dZeed<   e	 	 	 	 d*dededededede	e
e   ee
e      f   fd	       Ze	 	 	 	 d*dededededede	e
e   ee
e      f   fd
       Zededdfd       Zedededdfd       Zedee   fd       Zededefd       Zdeded ef   fdZ	 d+dededede
ee      dee
d    e
e   e
e   f   f
dZde
d    dddedej6                  dede
ee      de
d   fdZde
d    dddededede
d   fdZdededdfdZd ede
ee      ddfd!Zdeded"ed#eed$f   d%eed$f   defd&Z 	 d+de
d    dededede
ee      de
e   fd'Z!	 	 d,de"dede
ee      de
e   def
d(Z#d-d)Z$y).rs   z%
    Container tagging interface
    rX   r2   validate_accessvalidate_keythrow_on_missing_valuethrow_on_missing_keyr>   c                      y r6   r8   rA   r2   r   r   r   r   s         r:   
_get_childzContainer._get_child       	r9   c                      y r6   r8   r   s         r:   	_get_nodezContainer._get_node  r   r9   Nc                      y r6   r8   r   s     r:   __delitem__zContainer.__delitem__  r   r9   r   c                      y r6   r8   )rA   r2   r   s      r:   __setitem__zContainer.__setitem__  r   r9   c                      y r6   r8   r@   s    r:   __iter__zContainer.__iter__  r   r9   key_or_indexc                      y r6   r8   )rA   r   s     r:   __getitem__zContainer.__getitem__  r   r9   c                     |}|j                  d      s| j                         |fS | }|j                  d      sJ 	 |J |dd  }|j                  d      s	 ||fS |j                         }|t        d| d      A)N.r   zError resolving key 'rS   )
startswithr   rw   r!   )rA   r2   origr   s       r:   _resolve_key_and_rootzContainer._resolve_key_and_root  s    ~~c">>#S(((,D>>#&&&'''!"g~~c*
 9	 113<(+@a)HII r9   throw_on_missingr   r   c           
         ddl m} |dk(  r| d| fS t        |      }| }t        t	        |      dz
        D ]  }| n||   }	 |||	||      \  }
}t        |
t              r|
j                  ||      }
|
Dt        |
t              s4dj                  |d|dz          }||dz      }t        d	| d
| d| d      |
} |y|d   } |||||      \  }}|||dfS |+t        |      }||v rt        d      |j                  |       	 |j                  |||||      }||j                         	 |||fS # ||j                         w w xY w)zA
        Select a value using dot separated key sequence
        r   )_select_one N)cr2   r   throw_on_type_errorr   r   r   zError trying to access z: node `z.` is not a container and thus cannot contain ``)NNNz Recursive interpolation detected)r\   r2   r   r   r   )	omegaconfr   r   rangerz   rT   rW   r   rs   joinr"   idr$   add_maybe_resolve_interpolationremove)rA   r2   r   r   r   r   splitr   ikr   _
parent_key	child_keylast_keyr   vids                    r:   _select_implzContainer._select_impl  s    	+"9T>!#$(s5zA~& 	A|aA !1$?	FC #t$110K 2 
 z#y'A XXeAA&67
!!a%L	%-cU(:, GCCL+QP  D1	4 <#9- ;	
q =4''U)Cd{23UVVHHSM	!55,G 6 E C Xu$$	 C   s   	D8 8Er\   rW   r   c                 ~    	 | j                  ||||      }| j                  |||||      S # t        $ r |r Y yw xY w)a  
        Resolve an interpolation.

        This happens in two steps:
            1. The parse tree is visited, which outputs either a `Node` (e.g.,
               for node interpolations "${foo}"), a string (e.g., for string
               interpolations "hello ${name}", or any other arbitrary value
               (e.g., or custom interpolations "${foo:bar}").
            2. This output is potentially validated and converted when the node
               being resolved (`value`) is typed.

        If an error occurs in one of the above steps, an `InterpolationResolutionError`
        (or a subclass of it) is raised, *unless* `throw_on_resolution_failure` is set
        to `False` (in which case the return value is `None`).

        :param parent: Parent of the node being resolved.
        :param value: Node being resolved.
        :param key: The associated key in the parent.
        :param parse_tree: The parse tree as obtained from `grammar_parser.parse()`.
        :param throw_on_resolution_failure: If `False`, then exceptions raised during
            the resolution of the interpolation are silenced, and instead `None` is
            returned.

        :return: A `Node` that contains the interpolation result. This may be an existing
            node in the config (in the case of a node interpolation "${foo}"), or a new
            node that is created to wrap the interpolated value. It is `None` if and only if
            `throw_on_resolution_failure` is `False` and an error occurs during resolution.
        )r   r   r2   r   N)r\   r   r2   resolvedr   )resolve_parse_treer$   *_validate_and_convert_interpolation_result)rA   r\   r   r2   r   r   r   r  s           r:   r   z0Container._resolve_interpolation_from_parse_tree!  si    L	..%Es / H >>(C ? 
 	
 , 	*	s   - <<r  c           
         ddl m}m}m} t	        |t
               }	t	        ||      rDt	        ||      s8t        |      }
	 |j                  |
      }t        |      t        |
      k7  rd}	|}|	r ||||      S t	        |t
              sJ |S # t        $ r,}|r | j                  ||
|d| d| t               Y d }~y d }~ww xY w)Nr   )AnyNodeInterpolationResultNode	ValueNodez#While dereferencing interpolation 'z': )r2   r   r   r   r   T)r   r2   r\   )nodesr  r  r  rT   rW   r   validate_and_convertr)   r   r&   rU   )rA   r\   r   r2   r  r   r  r  r  	must_wrap	res_value
conv_valuees                r:   r  z4Container._validate_and_convert_interpolation_resultX  s     	GF #8T22	 eY'
5'0J"8,I"77	B
 J4	?2 	%*s6RRh---O- # 	.**'A%A3O&B +  	s    B 	C"B==Cr   targetc                 R    |}|#||u rt        d      |j                         }|"y y )Nz%Interpolation to parent node detected)r$   rr   )rA   r   r  r\   s       r:   %_validate_not_dereferencing_to_parentz/Container._validate_not_dereferencing_to_parent  s=    !% 2;  '')F  r9   	inter_keyc                    	 | j                  |      \  }}	 |j                  |dd|      \  }}}||t        d| d      | j                  | |	       |S # t        $ r7}t        d|       j                  t	        j
                         d         d}~ww xY w# t        $ r7}t        d|       j                  t	        j
                         d         d}~ww xY w)
z0A node interpolation is of the form `${foo.bar}`z.ConfigKeyError while resolving interpolation:    NT)r   r   r   z5MissingMandatoryValue while resolving interpolation: zInterpolation key 'z' not found)r   r  )
r   r!   r#   with_tracebacksysexc_infor  r'   r%   r  )rA   r  r   	root_nodeexcr\   r  r   s           r:   _resolve_node_interpolationz%Container._resolve_node_interpolation  s    	0#'#=#=i#H Iy
	0&/&<&<!%,0	 '= '#FHe >U]'*=i[(TUU66D6OL+  	0'@FnS\\^A./0	0 % 	02GuMnS\\^A./0	0s.   A B 	B!2BB	C$2CC
inter_type
inter_args.inter_args_strc                     ddl m} |j                  |      }|| j                         } ||| |||      S t	        d|       )Nr   )	OmegaConfzUnsupported interpolation type )r   r,  _get_resolverr   r(   )	rA   r2   r   r(  r)  r*  r,  resolverr%  s	            r:   _evaluate_custom_resolverz#Container._evaluate_custom_resolver  s^     	(**:6(I  /1*> r9   c           	          t        |      }|t        j                  k7  r|S t        t	        |            }| j                  |||||||      S t                     S )N)r\   r   r2   r   r   r   )r   r   INTERPOLATIONr+   r   r   set)rA   r\   r2   r   r   r   
value_kindr   s           r:   r  z&Container._maybe_resolve_interpolation  su     $E*
000L:e,-
::!(C) ; 
 	
 03u ; 
 	
r9   c                     dt         dt        t        t              dt        d   f fd}dt         dt        t
        df   d	t        t         df   dt
        f fd
}t        |||      }	 |j                  |      S # t        $ r  t        $ rL}t        t        |      j                   d|       j                  t        j                         d         d}~ww xY w)z
        Resolve a given parse tree into its value.

        We make no assumption here on the type of the tree's root, so that the
        return value may be of any type.
        r  r   r>   rW   c                 *    j                  | |      S )N)r  r   )r'  )r  r   rA   s     r:   node_interpolation_callbackzAContainer.resolve_parse_tree.<locals>.node_interpolation_callback  s     33id3SSr9   nameargs.args_strc                 0    j                  | ||      S )N)r2   r   r(  r)  r*  )r/  )r7  r8  r9  r2   r   rA   s      r:   resolver_interpolation_callbackzEContainer.resolve_parse_tree.<locals>.resolver_interpolation_callback  s,     11' 2  r9   )r6  r;  r   z' raised while resolving interpolation: r!  N)rK   r   r   r   r   r	   r,   visitr$   r   rU   rF   r"  r#  r$  )	rA   r   r   r   r2   r6  r;  visitorr&  s	   ` ` `    r:   r  zContainer.resolve_parse_tree  s    	T	T"*3s8"4	Tf	T
				"38_		8=c3h				 !(C,K

	0==,,+ 	 	0.9%%&&McUSnS\\^A./0	0s   .A? ?CACCc                    ddl m} ddlm} | j                  d   d | j                  d<   t        | |      rS| j                  d   }t        |t              r3| j                  d   j                         D ]  }|j                           y y t        | |      rE| j                  d   }t        |t              r%| j                  d   D ]  }|j                           y y y y )Nr   r   r   r[   r   )
r   r   r   r   r`   rT   r7   rx   rm   r   )rA   r   r   r   r   r   s         r:   rm   z!Container._invalidate_flags_cache  s    ** ==(4,0DMM.)$
+--
3gt,!%z!:!A!A!C 85578 - D*---
3gt, $j 9 74467 - . 5r9   )TTFFr6   r   rE   )%rF   rG   rH   r   rN   rI   r   r	   rJ   r   r   rW   r   r   r   r   r   r   r   r   rK   r   r   r   r   r  r*   ConfigValueContextr   r  r  r'  r/  r  r   r  rm   r8   r9   r:   rs   rs     s    !  !%!',%*  	
 !% # 
x~tHTN33	4   !%!',%*  	
 !% # 
x~tHTN33	4  s t   s 3 4   (3-       {C7G1H . $(L%L% L% &*	L%
 s3x L% 
x$hsmXd^C	DL%\5
%5
 5
 	5

 +==5
 &*5
 s3x 5
 
&	5
n)%) ) 	)
 ) &*) 
&	)V*$ * *QU *$,SX$6	:  	
 #s(O c3h 
> $(
%
 
 	

 &*
 s3x 
 
$
4 $(!+0%+0 +0 s3x 	+0
 c]+0 
+0Z7r9   rs   c                       e Zd ZdZdZdZy)SCModer   r!     N)rF   rG   rH   DICTDICT_CONFIGINSTANTIATEr8   r9   r:   rA  rA    s    DKKr9   rA  c                   n    e Zd ZU dZee   ed<   eede	f   ed<   	 	 	 dde
de
dede
d	ee   d
df fdZdeeeef      d
e	fdZde
d
efdZde
d
efdZd
efdZd
eede	f   fdZdde
deee	ef      d
dfdZ	 dde
deee	ef      d
dfdZd
efdZd
efdZd
e	fdZd
e	fdZdeee
f   d
d fdZ xZS )ru   a  
    This class handles Union type hints. The `_content` attribute is either a
    child node that is compatible with the given Union ref_type, or it is a
    special value (None or MISSING or interpolation).

    Much of the logic for e.g. value assignment and type validation is
    delegated to the child node. As such, UnionNode functions as a
    "pass-through" node. User apps and downstream libraries should not need to
    know about UnionNode (assuming they only use OmegaConf's public API).
    rZ   Nr   r   r/   is_optionalr2   r\   r>   c                 J   	 t        |      sd| ddz   }t        |      t        |t        t        f      st        d      t        |   |t        |d ||ddi             | j                  |       y # t        $ r#}t        d ||t        |      |	       Y d }~y d }~ww xY w)
Nz"UnionNode got unexpected ref_type z. Please file a bugz3 report at https://github.com/omry/omegaconf/issuesz&Parent type is not omegaconf.ContainerconvertF)r/   r0   r1   r2   r3   r   )r   r2   r   r   r   )r   AssertionErrorrT   rs   r   r"   r   ra   r.   r   r   r   rK   )	rA   r   r/   rG  r2   r\   r   exr   s	           r:   ra   zUnionNode.__init__.  s    	W&x08
BUVKL  %S))fy(&;<%&NOOG!% $($e,  	 OOG$ 	W$CwCGSUVV	Ws   A2A6 6	B"?BB"c                     | j                         }|6| j                  j                  yt        | j                  j                        S |j	                  | j                  j                        S )Nr   )rr   rX   r2   rK   r   )rA   r2   r\   s      r:   r   zUnionNode._get_full_keyM  sX    !!#>~~!!)4>>--..''(:(:;;r9   r   c                    | j                   d   }t        |t              r|j                  |      }n3t        |t              r|j                  |      }n|j                  |      }t        |t        t        t              f      sJ |S Nr   )r`   rT   rW   r   rJ   rU   NotImplemented)rA   r   r   r   s       r:   r   zUnionNode.__eq__W  sm    --
+gt$..'Ct$,,w'C..'C#d>&:;<<<
r9   c                 F    | j                  |      }|t        u rt        S | S r6   )r   rO  )rA   r   xs      r:   r   zUnionNode.__ne__b  s%    KK!!ur9   c                 2    t        | j                  d         S rN  )hashr`   r@   s    r:   r   zUnionNode.__hash__h      DMM*-..r9   c                 ^    | j                   d   }t        |t        t        t        f      sJ |S rN  )r`   rT   rW   r   rK   )rA   r   s     r:   r   zUnionNode._valuek  s,    --
+'D(C#8999r9   r   r3   c                     | j                   d   }| j                   d   }	 | j                  ||       y # t        $ r%}|| j                   d<   || j                   d<   |d }~ww xY w)Nr   rX   )r`   _set_value_implr   )rA   r   r3   previous_contentprevious_metadatar  s         r:   r   zUnionNode._set_valuep  sf    ==4 MM+6	  . 	(8DMM*%):DMM+&G	s   3 	A! AA!c                 ,   ddl m} | j                  j                  }| j                  j                  }t        |      }t        |      rRt        |t        t        f      sJ |(| j                         st        dt        |       d      || j                  d<   y t        |t              rt        dt        |             |j                  D ]  }	  |||dd |       | j                  d<    y  t        d	t        |       d      # t        $ r Y Dw xY w)
Nr   )
_node_wrapz/Value '$VALUE' is incompatible with type hint 'rS   r   z:Cannot assign container '$VALUE' of type '$VALUE_TYPE' to F)r   r/   rG  r2   r\   zEValue '$VALUE' of type '$VALUE_TYPE' is incompatible with type hint ')omegaconf.omegaconfr[  rX   r/   rD   r   r   rT   rK   r   r   r)   r    r`   rs   __args__)rA   r   r3   r[  r/   rD   candidate_ref_types          r:   rW  zUnionNode._set_value_implz  s1    	3>>**NN,,	5!uec8_555}((*)I(S\J]I^^_`  ).DMM*%y)!LXV_M`Lab  '/&7&7 "
0:#!3$) #1DMM*-  &[\den\o[ppqr  ' s   D	DDc                 8    | j                   d   j                  du S )NrX   T)r`   r1   r@   s    r:   r   zUnionNode._is_optional  s    }}[)22d::r9   c                 2    t        | j                  d         S rN  )r   r`   r@   s    r:   r   zUnionNode._is_interpolation  s     z!:;;r9   c                 2    t        | j                  d         S rN  )rK   r`   r@   s    r:   __str__zUnionNode.__str__  s    4==,--r9   c                 2    t        | j                  d         S rN  )reprr`   r@   s    r:   __repr__zUnionNode.__repr__  rT  r9   r   c                 B   t         j                  t        |             }| j                  j	                         D ].  \  }}|dvst        j                  ||      |j                  |<   0 | j                  d   }t        |t              rU|j                  d   }	 d |j                  d<   t        j                  ||      }||j                  d<   ||j                  d<   n|}||j                  d<   | j                  d   |j                  d<   |S # ||j                  d<   w xY w)N)r   rZ   )r   r   rZ   )	object__new__rU   r`   r   rd   r   rT   rW   )rA   r   resr2   r   src_content
old_parentcontent_copys           r:   __deepcopy__zUnionNode.__deepcopy__  s   nnT$Z(----/ 	DJC11$(MM%d$CS!	D mmJ/k4($--i8J=26$$Y/#}}[tD36%%i02<$$Y/ 'L#/Z "&--	":Y
 3=$$Y/s   5D D)TNNr6   )rF   rG   rH   r   r   rs   rI   r   rW   rK   r	   rJ   rY   ra   r   r   r   r   r   r   r   r
   r   rW  r   r   rb  re  rm  r   r   s   @r:   ru   ru     s   	 i  D$O$$ ! $WW W 	W
 W W 
W><%S0@*A!B <s <	C 	D 	C D /# /dD#o. 
 HT#t)_,E QU  >B%%!)$sDy/!:%	%N;d ;<4 <. ./# /c3h K r9   ru   )Crd   r#  abcr   r   collectionsr   dataclassesr   r   enumr   typingr	   r
   r   r   r   r   r   r   r   antlr4r   _utilsr   r   r   r   r   r   r   r   r   r   r   r   r    errorsr!   r"   r#   r$   r%   r&   r'   r(   r)   "grammar.gen.OmegaConfGrammarParserr*   grammar_parserr+   grammar_visitorr,   rK   bytesr   floatrJ   r   r.   rN   rW   rY   rs   rA  ru   r8   r9   r:   <module>r{     s     
 # # (  O O O $   
 
 
 G ! +CT5$67 #! #! #!L   ${23 {2|-)$ -)`B7 B7JT c cr9   