
    g4                    (   % 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J	r	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JrJrJrJr  SS
KJrJrJrJr  SSKJ r J!r!  SSK"J#r#J$r$  SSK%J&r&  \RN                  (       a  Sr(S\)S'   Sr*S\)S'   SSK+J,r,  \-\.\/\0\1\2\3\$Rh                  \\\\Rj                  \\\6Rn                  \8Rn                  1r9S\)S'   \:\;\<\=\>\	\
\1r?S\)S'   S1S jr@S2S jrAS3S jrBS4S jrCS5S jrDS6S jrE\" S5      rFS7S  jrGS8S! jrH\" S"5      rI\0S#.     S9S$ jjrJ " S% S&\#R                  5      rL\RN                  (       a  S:S' jrMO
 " S( S)5      rM\" S*5      rNS;S+ jrO\P" 5       rQS<S, jrR\R                  " S-S.9 " S/ S05      5       rTg)=zBucket of reusable internal utilities.

This should be reduced as much as possible with functions only used in one place, moved to that place.
    )annotationsN)OrderedDictdefaultdictdeque)deepcopy)cached_property)	Parameter)zip_longest)BuiltinFunctionTypeCodeTypeFunctionTypeGeneratorType
LambdaType
ModuleType)AnyCallableMappingTypeVar)	TypeAlias	TypeGuard   )_repr_typing_extra)import_cached_base_modelz3typing.Mapping[int, Any] | typing.Mapping[str, Any]r   MappingIntStrAnyz1typing.AbstractSet[int] | typing.AbstractSet[str]AbstractSetIntStr   )	BaseModelzset[type[Any]]IMMUTABLE_NON_COLLECTIONS_TYPESBUILTIN_COLLECTIONSc                \    U R                   [        R                  [        R                  4;   $ )a*  Return whether the parameter accepts a positional argument.

```python {test="skip" lint="skip"}
def func(a, /, b, *, c):
    pass

params = inspect.signature(func).parameters
can_be_positional(params['a'])
#> True
can_be_positional(params['b'])
#> True
can_be_positional(params['c'])
#> False
```
)kindr	   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)params    R/home/matz/Project1/venv/lib/python3.13/site-packages/pydantic/_internal/_utils.pycan_be_positionalr'   C   s$      ::)33Y5T5TUUU    c           	     V    [        U [        [        [        [        [
        [        45      $ N)
isinstancelisttupleset	frozensetr   r   vs    r&   sequence_liker2   V   s    a$sI}eLMMr(   c                :     [        X5      $ ! [         a     gf = fNF)r+   	TypeError)oclass_or_tuples     r&   lenient_isinstancer8   Z   s$    !,, s   
 
c                     [        U [        5      =(       a    [        X5      $ ! [         a#    [        U [        R
                  5      (       a   ge f = fr4   )r+   type
issubclassr5   r   WithArgsTypes)clsr7   s     r&   lenient_issubclassr>   a   sF    #t$HC)HH c=6677s   !$ )AAc                @    [        5       n[        X5      =(       a    XL$ )zReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
unlike raw calls to lenient_issubclass.
)r   r>   )r=   r   s     r&   is_model_classr@   j   s     )*Ic-F#2FFr(   c                f    U R                  5       =(       a    [        R                  " U 5      (       + $ )zChecks that a string is a valid identifier and not a Python keyword.
:param identifier: The identifier to test.
:return: True if the identifier is valid.
)isidentifierkeyword	iskeyword)
identifiers    r&   is_valid_identifierrF   s   s&    
 ""$JW->->z-J)JJr(   KeyTypec                    U R                  5       nU Hc  nUR                  5        HL  u  pEXB;   a>  [        X$   [        5      (       a'  [        U[        5      (       a  [	        X$   U5      X$'   MH  XRU'   MN     Me     U$ r*   )copyitemsr+   dictdeep_update)mappingupdating_mappingsupdated_mappingupdating_mappingkr1   s         r&   rL   rL   ~   ss    llnO-$**,DA#
?3Et(L(LQ[\]_cQdQd%01CQ%G"%&"	 - . r(   c                    U R                  UR                  5        VVs0 s H  u  p#Uc  M
  X#_M     snn5        g s  snnf r*   )updaterJ   )rM   rS   rQ   r1   s       r&   update_not_nonerT      s.    NNV\\^E^TQqDAD^EFEs   	;
;
T)name_factoryc                   / n/ nU  HG  nU" U5      nXS;  a$  UR                  U5        UR                  U5        M4  XBUR                  U5      '   MI     U$ )zMake a list unique while maintaining order.
We update the list if another one with the same name is set
(e.g. model validator overridden in subclass).
)appendindex)
input_listrV   resultresult_namesr1   v_names         r&   unique_listr^      s[     F La%'MM!12<%%f-.  Mr(   c                      \ rS rSrSrSrSS jrSS jrSS jrSS jr	SS jr
\SSS	 jj5       r\SS
 j5       r\SS j5       r\SS j5       rSS jrSrg)
ValueItems   zOClass for more convenient calculation of excluded or included fields on values.)_items_typec                    U R                  U5      n[        U[        [        45      (       a  U R	                  U[        U5      5      nX l        g r*   )_coerce_itemsr+   r,   r-   _normalize_indexeslenrb   )selfvaluerJ   s      r&   __init__ValueItems.__init__   s>    ""5)edE]++++E3u:>E(-r(   c                V    U R                  U R                  R                  U5      5      $ )zGCheck if item is fully excluded.

:param item: key or index of a value
)is_truerb   getrh   items     r&   is_excludedValueItems.is_excluded   s     
 ||DKKOOD122r(   c                    XR                   ;   $ )zPCheck if value is contained in self._items.

:param item: key or index of value
rb   ro   s     r&   is_includedValueItems.is_included   s    
 {{""r(   c                l    U R                   R                  U5      nU R                  U5      (       d  U$ S$ )z}:param e: key or index of element on value
:return: raw values for element if self._items is dict and contain needed element
N)rb   rn   rm   )rh   erp   s      r&   for_elementValueItems.for_element   s/     {{q!<<--t747r(   c                   0 nSnUR                  5        H  u  pV[        U[        R                  5      (       dP  [        U[        R                  5      (       d1  U R                  U5      (       d  [        SU SUR                   35      eUS:X  a  U R                  U5      nM  [        U[        5      (       d  [        S5      eUS:  a  X%-   OUnU R                  XcR                  U5      5      X7'   M     U(       d  U$ U R                  U5      (       a&  [        U5       H  nUR                  US5        M     U$ [        U5       H@  nUR                  U0 5      nU R                  U5      (       a  M-  U R                  XH5      X5'   MB     U$ )a-  :param items: dict or set of indexes which will be normalized
:param v_length: length of sequence indexes of which will be

>>> self._normalize_indexes({0: True, -2: True, -1: True}, 4)
{0: True, 2: True, 3: True}
>>> self._normalize_indexes({'__all__': True}, 4)
{0: True, 1: True, 2: True, 3: True}
Nz,Unexpected type of exclude value for index "z" __all__zExcluding fields from a sequence of sub-models or dicts must be performed index-wise: expected integer keys or keyword "__all__"r   .)rJ   r+   typingr   AbstractSetrm   r5   	__class___coerce_valueintmergern   range
setdefault)	rh   rJ   v_lengthnormalized_items	all_itemsir1   normalized_inormalized_items	            r&   rf   ValueItems._normalize_indexes   sh    24	KKMDAq&..11Z6CUCU5V5VZ^ZfZfghZiZi"NqcQSTUT_T_S` abbI~ ..q1	a%%A  ,-q58<aL-1ZZ;O;OP\;]-^* " ##<<	""8_ ++As3 %##xA.99!R@O<<00&*jj&L # !  r(   c                6   U R                  U5      nU R                  U5      nUc  U$ U R                  U5      (       d  Uc  U$ U R                  U5      (       a  U(       a  U$ U$ U(       a6  U Vs/ s H  oDU;   d  M
  UPM     snU Vs/ s H  oDU;   d  M
  UPM     sn-   nO&[        U5      U Vs/ s H  oDU;  d  M
  UPM     sn-   n0 nU H;  nU R                  UR	                  U5      UR	                  U5      US9nUc  M7  XvU'   M=     U$ s  snf s  snf s  snf )a   Merge a `base` item with an `override` item.

Both `base` and `override` are converted to dictionaries if possible.
Sets are converted to dictionaries with the sets entries as keys and
Ellipsis as values.

Each key-value pair existing in `base` is merged with `override`,
while the rest of the key-value pairs are updated recursively with this function.

Merging takes place based on the "union" of keys if `intersect` is
set to `False` (default) and on the intersection of keys if
`intersect` is set to `True`.
)	intersect)r   rm   r,   r   rn   )r=   baseoverrider   rQ   
merge_keysmergedmerged_items           r&   r   ValueItems.merge   s    $$X.  &K;;tO;;x  $42(2 %);T(]!T;(>`(Q[_V_q(>``Jd(&L(Qtmq(&LLJ')A))DHHQKaI)VK&'q	 
  <>`&Ls$   /	D<D	DD/	D<Dc                    [        U [        R                  5      (       a   U $ [        U [        R                  5      (       a  [        R                  U S5      n U $ [        U SS5      n[        SU 35      e)N.r   z???z!Unexpected type of exclude value )r+   r}   r   r~   rK   fromkeysgetattrr5   )rJ   
class_names     r&   re   ValueItems._coerce_items  sl    eV^^,,  v1122MM%-E  !U;J?
|LMMr(   c                Z    Ub  U R                  U5      (       a  U$ U R                  U5      $ r*   )rm   re   )r=   ri   s     r&   r   ValueItems._coerce_value  s+    =CKK..L  ''r(   c                     U SL =(       d    U SL $ )NT. r0   s    r&   rm   ValueItems.is_true$  s    Dy$AH$r(   c                     S U R                   4/$ r*   rt   rh   s    r&   __repr_args__ValueItems.__repr_args__(  s    t{{#$$r(   rt   N)ri   r   rJ   $AbstractSetIntStr | MappingIntStrAnyreturnNone)rp   r   r   bool)rx   z	int | strr   z+AbstractSetIntStr | MappingIntStrAny | None)rJ   r   r   r   r   zdict[int | str, Any])F)r   r   r   r   r   r   r   r   )rJ   r   r   r   )ri   r   r   r   r1   r   r   r   )r   z_repr.ReprArgs)__name__
__module____qualname____firstlineno____doc__	__slots__rj   rq   ru   ry   rf   classmethodr   staticmethodre   r   rm   r   __static_attributes__r   r(   r&   r`   r`      sz    Y#I.3#8# J # #J   ( (
 % %%r(   r`   c                    g r*   r   name	get_values     r&   LazyClassAttributer   .  s    r(   c                  @    \ rS rSrSrSS jr\S	S j5       rS
S jrSr	g)r   i2  zA descriptor exposing an attribute only accessible on a class (hidden from instances).

The attribute is lazily computed and cached during the first access.
c                    Xl         X l        g r*   r   )rh   r   r   s      r&   rj   LazyClassAttribute.__init__8  s    I&Nr(   c                "    U R                  5       $ r*   )r   r   s    r&   ri   LazyClassAttribute.value<  s    >>##r(   c                n    Uc  U R                   $ [        U R                  < SUR                  < S35      e)Nz attribute of z is class-only)ri   AttributeErrorr   r   )rh   instanceowners      r&   __get__LazyClassAttribute.__get__@  s4    zz! DII=u~~>PP^!_``r(   )r   r   N)r   strr   zCallable[[], Any]r   r   )r   r   )r   r   r   z	type[Any]r   r   )
r   r   r   r   r   rj   r   ri   r   r   r   r(   r&   r   r   2  s&    	
	' 
	$ 
	$	ar(   r   Objc                    U R                   nU[        ;   a  U $  U (       d%  U[        ;   a  U[        L a  U $ U R	                  5       $ [        U 5      $ ! [
        [        [        4 a     N"f = f)zReturn type as is for immutable built-in types
Use obj.copy() for built-in empty collections
Use copy.deepcopy() for non-empty collections and unknown objects.
)	r   r   r    r-   rI   r5   
ValueErrorRuntimeErrorr   )objobj_types     r&   smart_deepcopyr   I  sj    
 }}H22
x#66"e+3;;
 C=	 z<0 s   A A A)(A)c                >    [        X[        S9 H  u  p#X#Ld  M    g   g)zCheck that the items of `left` are the same objects as those in `right`.

>>> a, b = object(), object()
>>> all_identical([a, b, a], [a, b, a])
True
>>> all_identical([a, b, [a]], [a, b, [a]])  # new list object, while "equal" is not "identical"
False
)	fillvalueFT)r
   	_SENTINEL)leftright	left_item
right_items       r&   all_identicalr   _  s'     "-TI!N	& "O r(   T)frozenc                  d    \ rS rSr% SrSrS\S'   S
S jr\R                  (       a  SS jr
Srg	Srg	)SafeGetItemProxyin  zWrapper redirecting `__getitem__` to `get` with a sentinel value as default

This makes is safe to use in `operator.itemgetter` when some keys may be missing
)wrappedzMapping[str, Any]r   c               B    U R                   R                  U[        5      $ r*   )r   rn   r   rh   keys     r&   __getitem__SafeGetItemProxy.__getitem__{  s    ||Y//r(   c               8    U R                   R                  U5      $ r*   )r   __contains__r   s     r&   r   SafeGetItemProxy.__contains__  s    <<,,S11r(   r   N)r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   __annotations__r   r}   TYPE_CHECKINGr   r   r   r(   r&   r   r   n  s.     I0 	2 r(   r   )r%   r	   r   r   r   )r6   r   r7   z(type[Any] | tuple[type[Any], ...] | Noner   r   )r=   r   r7   r   r   r   )r=   r   r   zTypeGuard[type[BaseModel]])rE   r   r   r   )rM   dict[KeyType, Any]rN   r   r   r   )rM   zdict[Any, Any]rS   r   r   r   )rZ   zlist[T] | tuple[T, ...]rV   ztyping.Callable[[T], str]r   zlist[T])r   r   r   zCallable[[], T]r   rU   )r   r   r   r   )r   typing.Iterable[Any]r   r   r   r   )Ur   
__future__r   _annotationsdataclassesrC   r}   weakrefcollectionsr   r   r   rI   r   	functoolsr   inspectr	   	itertoolsr
   typesr   r   r   r   r   r   r   r   r   r   typing_extensionsr   r    r   r   _import_utilsr   r   r   r   r   mainr   r   floatcomplexr   r   bytesr:   NoneTyperefNotImplementedr   Ellipsisr   r,   r.   r-   r/   rK   r    r'   r2   r8   r>   r@   rF   rG   rL   rT   rU   r^   Representationr`   r   r   r   objectr   r   	dataclassr   r   r(   r&   <module>r      s  
 3     7 7  %  ! d d 2 2 2 " 3	"WiW#VyV 
 		KK '3  0 				' ^ 	V&NGK )
G CL /2' , 	,C%%% C%L 
Ka a( en& H	 d#2 2 $2r(   