
    Tg4                       U d Z ddlmZ ddlZddlZddlZddlZddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZ dd
lmZmZmZmZ ddlm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ej'        rdZ(de)d<   dZ*de)d<   ddl+m,Z, e-e.e/e0e1e2e3e$j4        eeeej5        eee6j7        e8j7        hZ9de)d<   e:e;e<e=e>e	e
ehZ?de)d<   dPdZ@dQd ZAdRd$ZBdSd&ZCdTd(ZDdUd+ZE ed,          ZFdVd0ZGdWd4ZH ed5          ZIe0d6dXd<ZJ G d= d>e#jK                  ZLej'        rdYdBZMn G dC dD          ZM edE          ZNdZdGZO eP            ZQd[dKZR ejS        dLM           G dN dO                      ZTdS )\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_COLLECTIONSparamr	   returnboolc                @    | j         t          j        t          j        fv S )aZ  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)r!   s    N/var/www/sysmax/venv/lib/python3.11/site-packages/pydantic/_internal/_utils.pycan_be_positionalr)   C   s      :)3Y5TUUU    vr   c           	     j    t          | t          t          t          t          t
          t          f          S N)
isinstancelisttupleset	frozensetr   r   r+   s    r(   sequence_liker4   V   s    a$sI}eLMMMr*   oclass_or_tuple(type[Any] | tuple[type[Any], ...] | Nonec                F    	 t          | |          S # t          $ r Y dS w xY wNF)r.   	TypeError)r5   r6   s     r(   lenient_isinstancer;   Z   s9    !^,,,   uus    
  clsc                    	 t          | t                    ot          | |          S # t          $ r t          | t          j                  rY dS  w xY wr9   )r.   type
issubclassr:   r   WithArgsTypes)r<   r6   s     r(   lenient_issubclassrA   a   s`    #t$$HC)H)HH   c=677 	55s   $' $AATypeGuard[type[BaseModel]]c                F    t                      }t          | |          o| |uS )zReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
    unlike raw calls to lenient_issubclass.
    )r   rA   )r<   r   s     r(   is_model_classrD   j   s)     )**Ic9--F#Y2FFr*   
identifierstrc                T    |                                  ot          j        |            S )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)rE   s    r(   is_valid_identifierrK   s   s)    
 ""$$JW->z-J-J)JJr*   KeyTypemappingdict[KeyType, Any]updating_mappingsc                   |                                  }|D ]o}|                                D ]X\  }}||v rJt          ||         t                    r/t          |t                    rt	          ||         |          ||<   S|||<   Yp|S r-   )copyitemsr.   dictdeep_update)rM   rO   updated_mappingupdating_mappingkr+   s         r(   rT   rT   ~   s    llnnO- ' '$**,, 	' 	'DAqO##
?13Et(L(L#Q[\]_cQdQd#%01CQ%G%G""%&""		'
 r*   dict[Any, Any]updateNonec                h    |                      d |                                D                        d S )Nc                    i | ]
\  }}|||S r-    ).0rW   r+   s      r(   
<dictcomp>z#update_not_none.<locals>.<dictcomp>   s    EEETQq}Aq}}}r*   )rY   rR   )rM   rY   s     r(   update_not_noner`      s1    NNEEV\\^^EEEFFFFFr*   T)name_factory
input_listlist[T] | tuple[T, ...]rb   typing.Callable[[T], str]list[T]c                   g }g }| D ]T} ||          }||vr+|                     |           |                     |           <|||                    |          <   U|S )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)rc   rb   resultresult_namesr+   v_names         r(   unique_listrm      s~     F L 3 3a%%'''MM!12F<%%f--..Mr*   c                      e Zd ZdZdZd#d	Zd$dZd$dZd%dZd&dZ	e
d'd(d            Zed)d            Ze
d*d            Zed+d            Zd,d!Zd"S )-
ValueItemszOClass for more convenient calculation of excluded or included fields on values.)_items_typevaluer   rR   $AbstractSetIntStr | MappingIntStrAnyr"   rZ   c                    |                      |          }t          |t          t          f          r#|                     |t          |                    }|| _        d S r-   )_coerce_itemsr.   r/   r0   _normalize_indexeslenrp   )selfrr   rR   s      r(   __init__zValueItems.__init__   sQ    ""5))edE]++ 	?++E3u::>>E(-r*   itemr#   c                \    |                      | j                            |                    S )zWCheck if item is fully excluded.

        :param item: key or index of a value
        )is_truerp   getrx   rz   s     r(   is_excludedzValueItems.is_excluded   s$    
 ||DKOOD11222r*   c                    || j         v S )z`Check if value is contained in self._items.

        :param item: key or index of value
        rp   r~   s     r(   is_includedzValueItems.is_included   s    
 t{""r*   e	int | str+AbstractSetIntStr | MappingIntStrAny | Nonec                h    | j                             |          }|                     |          s|nd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)rp   r}   r|   )rx   r   rz   s      r(   for_elementzValueItems.for_element   s2     {q!!<<--7tt47r*   r   v_lengthintdict[int | str, Any]c                ,   i }d}|                                 D ]\  }}t          |t          j                  sIt          |t          j                  s/|                     |          st          d| d|j                   |dk    r|                     |          }t          |t                    st          d          |dk     r||z   n|}| 
                    ||                    |                    ||<   |s|S |                     |          r*t          |          D ]}|                    |d           |S t          |          D ]F}|                    |i           }|                     |          s| 
                    ||          ||<   G|S )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   .)rR   r.   typingr   AbstractSetr|   r:   	__class___coerce_valuer   merger}   range
setdefault)	rx   rR   r   normalized_items	all_itemsir+   normalized_inormalized_items	            r(   rv   zValueItems._normalize_indexes   s    24	KKMM 	_ 	_DAqq&.11 cZ6CU5V5V cZ^ZfZfghZiZi c aq a aTUT_ a abbbI~~ ..q11	a%% A   ,-q558a<<aL-1ZZ;K;O;OP\;];]-^-^\** 	$##<<	"" 	$8__ 4 4 ++As3333##x 	M 	MA.99!R@@O<<00 M&*jjO&L&L #r*   Fbaseoverride	intersectc                   |                                |                                S |                               sS |                               r|rnS |rfdD             fdD             z   }nt                    fdD             z   }i }|D ]G}|                                         |                              |          |          }||||<   H|S )aH  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`.
        Nc                    g | ]}|v |	S r]   r]   )r^   rW   r   s     r(   
<listcomp>z$ValueItems.merge.<locals>.<listcomp>  s    ;;;Q(]]!]]]r*   c                    g | ]}|v |	S r]   r]   r^   rW   r   s     r(   r   z$ValueItems.merge.<locals>.<listcomp>  s%    >`>`>`QVW[_V_V_qV_V_V_r*   c                    g | ]}|v|	S r]   r]   r   s     r(   r   z$ValueItems.merge.<locals>.<listcomp>	  s    &L&L&LQatmmqmmmr*   )r   )r   r|   r/   r   r}   )r<   r   r   r   
merge_keysmergedrW   merged_items    ``     r(   r   zValueItems.merge   s0    $$X..  &&K;;t 	O;;x   	3$244(2  	M;;;;T;;;>`>`>`>`(>`>`>``JJd&L&L&L&L(&L&L&LLJ') 	( 	(A))DHHQKKaI)VVK&'q	r*   c                    t          | t          j                  rnYt          | t          j                  rt                              | d          } n#t          | dd          }t          d|           | S )N.r   z???z!Unexpected type of exclude value )r.   r   r   r   rS   fromkeysgetattrr:   )rR   
class_names     r(   ru   zValueItems._coerce_items  sr    eV^,, 	Nv122 	NMM%--EE U;;JL
LLMMMr*   c                ^    ||                      |          r|S |                     |          S r-   )r|   ru   )r<   rr   s     r(   r   zValueItems._coerce_value  s0    =CKK..=L  '''r*   r+   c                    | du p| du S )NT.r]   r3   s    r(   r|   zValueItems.is_true$  s    Dy$AH$r*   _repr.ReprArgsc                    d | j         fgS r-   r   rx   s    r(   __repr_args__zValueItems.__repr_args__(  s    t{#$$r*   N)rr   r   rR   rs   r"   rZ   )rz   r   r"   r#   )r   r   r"   r   )rR   r   r   r   r"   r   )F)r   r   r   r   r   r#   r"   r   )rR   rs   r"   r   )rr   r   r"   r   r+   r   r"   r#   )r"   r   )__name__
__module____qualname____doc__	__slots__ry   r   r   r   rv   classmethodr   staticmethodru   r   r|   r   r]   r*   r(   ro   ro      s       YY#I. . . .3 3 3 3# # # #8 8 8 8#  #  #  # J # # # # [#J    \ ( ( ( [(
 % % % \%% % % % % %r*   ro   name	get_valueCallable[[], T]c                    d S r-   r]   r   r   s     r(   LazyClassAttributer   .  s      r*   c                  :    e Zd ZdZddZedd
            ZddZdS )r   zA descriptor exposing an attribute only accessible on a class (hidden from instances).

        The attribute is lazily computed and cached during the first access.
        r   rF   r   Callable[[], Any]r"   rZ   c                "    || _         || _        d S r-   r   )rx   r   r   s      r(   ry   zLazyClassAttribute.__init__8  s    DI&DNNNr*   r   c                *    |                                  S r-   )r   r   s    r(   rr   zLazyClassAttribute.value<  s    >>###r*   instanceowner	type[Any]c                R    || j         S t          | j        d|j        d          )Nz attribute of z is class-only)rr   AttributeErrorr   r   )rx   r   r   s      r(   __get__zLazyClassAttribute.__get__@  s3    z! DI!_!_u~!_!_!_```r*   N)r   rF   r   r   r"   rZ   )r"   r   )r   r   r   r   r"   rZ   )r   r   r   r   ry   r   rr   r   r]   r*   r(   r   r   2  sl        	 	
	' 	' 	' 	' 
	$ 	$ 	$ 
	$	a 	a 	a 	a 	a 	ar*   r   Objobjc                    | j         }|t          v r| S 	 | s(|t          v r|t          u r| n|                                 S n# t
          t          t          f$ r Y nw xY wt          |           S )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    r0   rQ   r:   
ValueErrorRuntimeErrorr   )r   obj_types     r(   smart_deepcopyr   I  s    
 }H222
 	<x#666"e++33;z<0    C==s   )? AAlefttyping.Iterable[Any]rightc                N    t          | |t                    D ]\  }}||ur dS dS )a  Check 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)r   r   	left_item
right_items       r(   all_identicalr   _  sC     "-T5I!N!N!N  	:J&&55 '4r*   T)frozenc                  D    e Zd ZU dZdZded<   dd	Zej        rddZ	dS dS )SafeGetItemProxyzWrapper 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   keyrF   r"   r   c               B    | j                             |t                    S r-   )r   r}   r   rx   r   s     r(   __getitem__zSafeGetItemProxy.__getitem__{  s    |Y///r*   r#   c               6    | j                             |          S r-   )r   __contains__r   s     r(   r   zSafeGetItemProxy.__contains__  s    <,,S111r*   N)r   rF   r"   r   )r   rF   r"   r#   )
r   r   r   r   r   __annotations__r   r   TYPE_CHECKINGr   r]   r*   r(   r   r   n  sr           I0 0 0 0  2	2 	2 	2 	2 	2 	22 2r*   r   )r!   r	   r"   r#   r   )r5   r   r6   r7   r"   r#   )r<   r   r6   r   r"   r#   )r<   r   r"   rB   )rE   rF   r"   r#   )rM   rN   rO   rN   r"   rN   )rM   rX   rY   r   r"   rZ   )rc   rd   rb   re   r"   rf   )r   rF   r   r   r"   ra   )r   r   r"   r   )r   r   r   r   r"   r#   )Ur   
__future__r   _annotationsdataclassesrI   r   weakrefcollectionsr   r   r   rQ   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complexrF   r#   bytesr>   NoneTyperefNotImplementedr   Ellipsisr   r/   r1   r0   r2   rS   r    r)   r4   r;   rA   rD   rK   rL   rT   r`   ra   rm   Representationro   r   r   r   objectr   r   	dataclassr   r]   r*   r(   <module>r      s*    
 3 2 2 2 2 2        7 7 7 7 7 7 7 7 7 7       % % % % % %       ! ! ! ! ! ! d d d d d d d d d d d d d d d d 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " " " " " " " " 3 3 3 3 3 3	 !"WWWWW#VVVVV      
 		K '3     0 				'  	 	 	 	V V V V&N N N N      G G G GK K K K ')

   G G G G GCLL /2     ,C% C% C% C% C%% C% C% C%L 
 aKKKKKa a a a a a a a( genn   & FHH	    d###2 2 2 2 2 2 2 $#2 2 2r*   