
    KiW>                       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Zddl	m
Z
mZm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 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&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 e#r*ee6e$f   ee7e$f   z  Z8de9d<   ee6   ee7   z  Z:de9d<   ddl;m<Z< e6e=e>e7e?e@eAe3j                  eee ej                  ee!eDj                  eFj                  hZGde9d<   eHeIeJeKeLe
eehZMde9d<   d:dZNd;dZOd<dZPd=dZQd>dZRd?d ZS e&d!      ZTd@d"ZUdAd#ZV e&d$      ZWe7d%	 	 	 	 	 dBd&ZX G d' d(e2j                        ZZe#rdCd)Z[n
 G d* d+      Z[ e&d,      Z\dDd-Z] e^       Z_dEd.Z`dFd/Za ej                  d01       G d2 d3             Zc e&d4d56      Zd e&d7      Ze G d8 d9e%edeef         Zfy)GzBucket 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)CallableIterableMapping)Set)deepcopy)cached_property)	Parameter)zip_longest)BuiltinFunctionTypeCodeTypeFunctionTypeGeneratorType
LambdaType
ModuleType)TYPE_CHECKINGAnyGenericTypeVaroverload)MISSINGPydanticUndefined)	TypeAlias	TypeGuard
deprecated)PydanticDeprecatedSince211   )_repr_typing_extra)import_cached_base_modelr   MappingIntStrAnyAbstractSetIntStr   )	BaseModelzset[type[Any]]IMMUTABLE_NON_COLLECTIONS_TYPESBUILTIN_COLLECTIONSc                Z    | 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)params    e/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/pydantic/_internal/_utils.pycan_be_positionalr0   J   s$      ::)33Y5T5TUUU    c           	     V    t        | t        t        t        t        t
        t        f      S N)
isinstancelisttupleset	frozensetr   r   vs    r/   sequence_liker;   ]   s    a$sI}eLMMr1   c                :    	 t        | |      S # t        $ r Y yw xY wNF)r4   	TypeError)oclass_or_tuples     r/   lenient_isinstancerA   a   s&    !^,, s    	c                    	 t        | t              xr t        | |      S # t        $ r t        | t        j
                        rY y w xY wr=   )r4   type
issubclassr>   r"   WithArgsTypes)clsr@   s     r/   lenient_issubclassrG   h   sE    #t$HC)HH c=667s     #AAc                :    t               }t        | |      xr | |uS )zReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
    unlike raw calls to lenient_issubclass.
    )r#   rG   )rF   r'   s     r/   is_model_classrI   q   s#     )*Ic9-F#Y2FFr1   c                R    | j                         xr 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)
identifiers    r/   is_valid_identifierrO   z   s&    
 ""$JW->->z-J)JJr1   KeyTypec                    | j                         }|D ]Y  }|j                         D ]D  \  }}||v r6t        ||   t              r#t        |t              rt	        ||   |      ||<   @|||<   F [ |S r3   )copyitemsr4   dictdeep_update)mappingupdating_mappingsupdated_mappingupdating_mappingkr:   s         r/   rU   rU      s    llnO- '$**, 	'DAqO#
?13Et(LQ[\]_cQd%01CQ%G"%&"		'' r1   c                |    | j                  |j                         D ci c]  \  }}|	|| c}}       y c c}}w r3   )updaterS   )rV   r\   rZ   r:   s       r/   update_not_noner]      s.    NNV\\^ETQq}AqDEFEs   
8
8
T)name_factoryc                   g }g }| D ]E  } ||      }||vr#|j                  |       |j                  |       2|||j                  |      <   G |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)
input_listr_   resultresult_namesr:   v_names         r/   unique_listrg      sd     F L 3a%'MM!12F<%%f-.3 Mr1   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y)
ValueItemszOClass for more convenient calculation of excluded or included fields on values.)_items_typec                    | j                  |      }t        |t        t        f      r| j	                  |t        |            }|| _        y r3   )_coerce_itemsr4   r5   r6   _normalize_indexeslenrj   )selfvaluerS   s      r/   __init__zValueItems.__init__   s=    ""5)edE]+++E3u:>E(-r1   c                V    | j                  | j                  j                  |            S )zWCheck if item is fully excluded.

        :param item: key or index of a value
        )is_truerj   getrp   items     r/   is_excludedzValueItems.is_excluded   s     
 ||DKKOOD122r1   c                    || j                   v S )z`Check if value is contained in self._items.

        :param item: key or index of value
        rj   rv   s     r/   is_includedzValueItems.is_included   s    
 t{{""r1   c                b    | j                   j                  |      }| j                  |      s|S 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)rj   ru   rt   )rp   erw   s      r/   for_elementzValueItems.for_element   s,     {{q!<<-t747r1   c                   i }d}|j                         D ]  \  }}t        |t              s<t        |t              s,| j	                  |      st        d| d|j                         |dk(  r| j                  |      }it        |t              st        d      |dk  r||z   n|}| j                  ||j                  |            ||<    |s|S | j	                  |      r$t        |      D ]  }|j                  |d        |S t        |      D ];  }|j                  |i       }| j	                  |      r'| j                  ||      ||<   = |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   .)rS   r4   r	   AbstractSetrt   r>   	__class___coerce_valueintmergeru   range
setdefault)	rp   rS   v_lengthnormalized_items	all_itemsir:   normalized_inormalized_items	            r/   rn   zValueItems._normalize_indexes   sh    24	KKM 	_DAqq'*jK.HDLLYZO"NqcQSTUT_T_S` abbI~ ..q1	a%A  ,-q58a<aL-1ZZ;K;O;OP\;]-^\*	_ ##<<	"8_ 4 ++As34##x 	MA.99!R@O<<0&*jjO&L #	M  r1   c                   | j                  |      }| j                  |      }||S | j                  |      s||S | j                  |      r|r|S |S |r,|D cg c]	  }||v s| c}|D cg c]	  }||v s| c}z   }n!t        |      |D cg c]	  }||vs| c}z   }i }|D ]<  }| j                  |j	                  |      |j	                  |      |      }|8|||<   > |S c c}w c c}w c c}w )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`.
        )	intersect)r   rt   r5   r   ru   )rF   baseoverrider   rZ   
merge_keysmergedmerged_items           r/   r   zValueItems.merge   s	    $$X.  &K;;tO;;x $42(2 %);Q(]!;(>`QVW[_V_q>``Jd(&LQatmq&LLJ') 	(A))DHHQKaI)VK&'q		(
  <>`&Ls$   	C'#C'-	C,7C,	C1C1c                    t        | t              r	 | S t        | t              rt        j	                  | d      } | S t        | dd      }t        d|       )N.r   z???z!Unexpected type of exclude value )r4   r	   r   rT   fromkeysgetattrr>   )rS   
class_names     r/   rm   zValueItems._coerce_items  s\    eW%  {+MM%-E  !U;J?
|LMMr1   c                N    || j                  |      r|S | j                  |      S r3   )rt   rm   )rF   rq   s     r/   r   zValueItems._coerce_value%  s(    =CKK.L  ''r1   c                    | du xs | du S )NT. r9   s    r/   rt   zValueItems.is_true+  s    Dy$AH$r1   c                     d | j                   fgS r3   rz   rp   s    r/   __repr_args__zValueItems.__repr_args__/  s    t{{#$$r1   N)rq   r   rS   $AbstractSetIntStr | MappingIntStrAnyreturnNone)rw   r   r   bool)r}   z	int | strr   z+AbstractSetIntStr | MappingIntStrAny | None)rS   r$   r   r   r   zdict[int | str, Any])F)r   r   r   r   r   r   r   r   )rS   r   r   r$   )rq   r   r   r   r:   r   r   r   )r   z_repr.ReprArgs)__name__
__module____qualname____doc__	__slots__rr   rx   r{   r~   rn   classmethodr   staticmethodrm   r   rt   r   r   r1   r/   ri   ri      sz    Y#I.3#8# J # #J   ( (
 % %%r1   ri   c                     y r3   r   name	get_values     r/   LazyClassAttributer   5  s    r1   c                  2    e Zd ZdZddZedd       ZddZy)	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.
        c                     || _         || _        y r3   r   )rp   r   r   s      r/   rr   zLazyClassAttribute.__init__?  s    DI&DNr1   c                "    | j                         S r3   )r   r   s    r/   rq   zLazyClassAttribute.valueC  s    >>##r1   c                h    || j                   S t        | j                  d|j                  d      )Nz attribute of z is class-only)rq   AttributeErrorr   r   )rp   instanceowners      r/   __get__zLazyClassAttribute.__get__G  s4    zz! DII=u~~>PP^!_``r1   N)r   strr   zCallable[[], Any]r   r   )r   r   )r   r   r   z	type[Any]r   r   )r   r   r   r   rr   r   rq   r   r   r1   r/   r   r   9  s&    	
	' 
	$ 
	$	ar1   r   Objc                    | t         u s| t        u r| S | j                  }|t        v r| S 	 | s"|t        v r|t
        u r| S | j                         S t        |       S # t        t        t        f$ r Y t        |       S w xY w)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(   r)   r6   rR   r>   
ValueErrorRuntimeErrorr   )objobj_types     r/   smart_deepcopyr   P  s    
 g~ 11
}}H22
x#66"e+3;;
 C=	 z<0 C=	s   A A A:9A:c                D    t        | |t              D ]  \  }}||us y y)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)leftright	left_item
right_items       r/   all_identicalr   h  s1     "-T5I!N 	:J& r1   c                    | | S |S )zTReturn the first argument if it is not `None`, otherwise return the second argument.r   )abs     r/   get_first_not_noner   w  s    1$1$r1   T)frozenc                  6    e Zd ZU dZdZded<   ddZerd	dZyy)
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   c               B    | j                   j                  |t              S r3   )r   ru   r   rp   keys     r/   __getitem__zSafeGetItemProxy.__getitem__  s    ||Y//r1   c               8    | j                   j                  |      S r3   )r   __contains__r   s     r/   r   zSafeGetItemProxy.__contains__  s    <<,,S11r1   N)r   r   r   r   )r   r   r   r   )	r   r   r   r   r   __annotations__r   r   r   r   r1   r/   r   r   |  s(     I0 	2 r1   r   _ModelTr'   )bound_RTc                  ^    e Zd ZdZd	dZed
d       Ze edd      dd              ZddZy)deprecated_instance_propertya  A decorator exposing the decorated class method as a property, with a warning on instance access.

    This decorator takes a class method defined on the `BaseModel` class and transforms it into
    an attribute. The attribute can be accessed on both the class and instances of the class. If accessed
    via an instance, a deprecation warning is emitted stating that instance access will be removed in V3.
    c                   || _         y r3   )fget)rp   r   s     r/   rr   z%deprecated_instance_property.__init__  s	    	r1   c                     y r3   r   rp   r   objtypes      r/   r   z$deprecated_instance_property.__get__  s    FIr1   zAccessing this attribute on the instance is deprecated, and will be removed in Pydantic V3. Instead, you should access this attribute from the model class.N)categoryc                     y r3   r   r   s      r/   r   z$deprecated_instance_property.__get__  s	     JMr1   c                   |it         j                  dk\  r| j                  j                  n| j                  j                  j                  }t        j                  d|dt        d        | j                  j                  ||             S )N)   
   zAccessing the zi attribute on the instance is deprecated. Instead, you should access this attribute from the model class.r&   )r   
stacklevel)	sysversion_infor   r   __func__warningswarnr   r   )rp   r   r   	attr_names       r/   r   z$deprecated_instance_property.__get__  s     ##w. 		""YY''00  MM  .R R3	 4tyy  7355r1   )r   zCallable[[type[_ModelT]], _RT]r   r   )r   r   r   type[_ModelT]r   r   )r   r   r   r   r   r   )r   z_ModelT | Noner   r   r   r   )r   r   r   r   rr   r   r   r   r   r1   r/   r   r     sK     I I	J
 M  M6r1   r   )r.   r   r   r   r   )r?   r   r@   z(type[Any] | tuple[type[Any], ...] | Noner   r   )rF   r   r@   r   r   r   )rF   r   r   zTypeGuard[type[BaseModel]])rN   r   r   r   )rV   dict[KeyType, Any]rW   r   r   r   )rV   zdict[Any, Any]r\   r   r   r   )rc   zlist[T] | tuple[T, ...]r_   zCallable[[T], str]r   zlist[T])r   r   r   zCallable[[], T]r   r^   )r   r   r   r   )r   Iterable[Any]r   r   r   r   )r   r   r   r   r   r   )gr   
__future__r   _annotationsdataclassesrL   r   r   weakrefcollectionsr   r   r   collections.abcr   r   r	   r
   r   rR   r   	functoolsr   inspectr   	itertoolsr   typesr   r   r   r   r   r   typingr   r   r   r   r   pydantic_corer   r   typing_extensionsr   r   r   pydanticr    r!   r"   _import_utilsr#   r   r   r$   r   r%   mainr'   floatcomplexr   bytesrC   NoneTyperefNotImplementedr   Ellipsisr(   r5   r7   r6   r8   rT   r)   r0   r;   rA   rG   rI   rO   rP   rU   r]   r^   rg   Representationri   r   r   r   objectr   r   r   	dataclassr   r   r   r   r   r1   r/   <module>r     s#  
 3   
   7 7 7 7 .  %  ! d d A A 4 > > / " 3")#s("3gc3h6G"GiG#.s#3k#6F#FyF 
 		KK '3  0 				' ^ 	V&NGK )
G CL (+' % 	,C%%% C%L Ka a( en* H	%
 d#2 2 $22 );
/en$677C<#8 $6r1   