Viewing File: /opt/hc_python/lib/python3.12/site-packages/pydantic/_internal/__pycache__/_utils.cpython-312.pyc

�

e��gu1����UdZddlmZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZmZmZmZmZddlmZmZmZdd	lmZmZd
dlmZmZej@rdZ!d
e"d<dZ#d
e"d<ddl$m%Z%e&e'e(e)e*e+e,ejZeeeej\eee/j`e1j`hZ2de"d<e3e4e5e6e7e	e
ehZ8de"d<d-d�Z9d.d�Z:d/d�Z;d0d�Z<d1d�Z=ed�Z>d2d�Z?d3d�Z@ed�ZAe)d�					d4d �ZBGd!�d"ej��ZDej@rd5d#�ZEn
Gd$�d%�ZEed&�ZFd6d'�ZGeH�ZId7d(�ZJej�d)�*�Gd+�d,��ZLy)8z�Bucket 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)�zip_longest)�BuiltinFunctionType�CodeType�FunctionType�
GeneratorType�
LambdaType�
ModuleType)�Any�Mapping�TypeVar)�	TypeAlias�	TypeGuard�)�_repr�
_typing_extraz3typing.Mapping[int, Any] | typing.Mapping[str, Any]r�MappingIntStrAnyz1typing.AbstractSet[int] | typing.AbstractSet[str]�AbstractSetIntStr���	BaseModelzset[type[Any]]�IMMUTABLE_NON_COLLECTIONS_TYPES�BUILTIN_COLLECTIONSc	�V�t|ttttt
tf�S�N)�
isinstance�list�tuple�set�	frozensetrr��vs �H/opt/hc_python/lib/python3.12/site-packages/pydantic/_internal/_utils.py�
sequence_liker(@s���a�$��s�I�}�e�L�M�M�c�:�	t||�S#t$rYywxYw�NF)r �	TypeError)�o�class_or_tuples  r'�lenient_isinstancer/Ds&����!�^�,�,������s��	�c��	t|t�xrt||�S#t$rt|tj
�rYy�wxYwr+)r �type�
issubclassr,r�
WithArgsTypes)�clsr.s  r'�lenient_issubclassr5KsE����#�t�$�H��C��)H�H�����c�=�6�6�7��
��s� �#A�Ac�2�ddlm}t||�xr||uS)z�Returns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
    unlike raw calls to lenient_issubclass.
    rr)�mainrr5)r4rs  r'�is_model_classr8Ts��!��c�9�-�F�#�Y�2F�Fr)c�R�|j�xrtj|�S)z�Checks 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_identifierr>]s&��
�"�"�$�J�W�->�->�z�-J�)J�Jr)�KeyTypec���|j�}|D]Y}|j�D]D\}}||vr6t||t�r#t|t�rt	|||�||<�@|||<�F�[|Sr)�copy�itemsr �dict�deep_update)�mapping�updating_mappings�updated_mapping�updating_mapping�kr&s      r'rDrDhsy���l�l�n�O�-��$�*�*�,�D�A�q��O�#�
�?�1�3E�t�(L�Q[�\]�_c�Qd�%0���1C�Q�%G���"�%&���"�	-�.��r)c�|�|j|j�D��cic]\}}|��	||��
c}}�ycc}}wr)�updaterB)rErKrIr&s    r'�update_not_nonerLss2���N�N�V�\�\�^�E�^�T�Q��q�}�A�q�D�^�E�F��Es�
8
�8
�T)�name_factoryc��g}g}|D]E}||�}||vr#|j|�|j|��2|||j|�<�G|S)z�Make 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_listrN�result�result_namesr&�v_names      r'�unique_listrVzs_���F� �L�
���a�����%�����'��M�M�!��12�F�<�%�%�f�-�.�
��Mr)c��eZdZdZdZdd�Zdd�Zdd�Zdd�Zdd�Z	e
ddd��Zedd	��Z
e
dd
��Zedd��Zdd�Zy
)�
ValueItemszOClass for more convenient calculation of excluded or included fields on values.)�_items�_typec��|j|�}t|ttf�r|j	|t|��}||_yr)�
_coerce_itemsr r!r"�_normalize_indexes�lenrY)�self�valuerBs   r'�__init__zValueItems.__init__�s=���"�"�5�)���e�d�E�]�+��+�+�E�3�u�:�>�E�(-��r)c�V�|j|jj|��S)zWCheck if item is fully excluded.

        :param item: key or index of a value
        )�is_truerY�get�r_�items  r'�is_excludedzValueItems.is_excluded�s ��
�|�|�D�K�K�O�O�D�1�2�2r)c��||jvS)z`Check if value is contained in self._items.

        :param item: key or index of value
        �rYres  r'�is_includedzValueItems.is_included�s��
�t�{�{�"�"r)c�b�|jj|�}|j|�s|SdS)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)rYrdrc)r_�erfs   r'�for_elementzValueItems.for_element�s,���{�{���q�!���<�<��-�t�7�4�7r)c���i}d}|j�D]�\}}t|tj�sFt|tj�s,|j|�st
d|�d|j����|dk(r|j|�}�}t|t�st
d��|dkr||zn|}|j||j|��||<��|s|S|j|�r$t|�D]}|j|d��|St|�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__z�Excluding fields from a sequence of sub-models or dicts must be performed index-wise: expected integer keys or keyword "__all__"r.)rBr �typingr�AbstractSetrcr,�	__class__�
_coerce_value�int�mergerd�range�
setdefault)	r_rB�v_length�normalized_items�	all_items�ir&�normalized_i�normalized_items	         r'r]zValueItems._normalize_indexes�sc��24���	��K�K�M�D�A�q��q�&�.�.�1�Z��6�CU�CU�5V�Z^�Zf�Zf�gh�Zi��"N�q�c�QS�TU�T_�T_�S`� a�b�b��I�~� �.�.�q�1�	���a��%��A���,-�q�5�8�a�<�a�L�-1�Z�Z��;K�;O�;O�P\�;]�-^��\�*�"��#�#��<�<�	�"��8�_�� �+�+�A�s�3�%�#�#��x��A�.�9�9�!�R�@�O��<�<��0�&*�j�j��O�&L� ��#�!� �r)c���|j|�}|j|�}|�|S|j|�s|�|S|j|�r|r|S|S|r,|D�cgc]	}||vs�|��c}|D�cgc]	}||vs�|��c}z}n!t|�|D�cgc]	}||vs�|��c}z}i}|D]<}|j|j	|�|j	|�|��}|��8|||<�>|Scc}wcc}wcc}w)aHMerge 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)rsrcr!rurd)r4�base�overriderrI�
merge_keys�merged�merged_items        r'ruzValueItems.merge�s���$�$�X�.��� � ��&�����K��;�;�t�����O��;�;�x� �$�4�2�(�2��%)�;�T��Q�(�]�!�T�;�(�>`�(�Q�VW�[_�V_�q�(�>`�`�J��d��(�&L�(�Q�a�t�m�q�(�&L�L�J�')���A��)�)�D�H�H�Q�K����a��I�)�V�K��&�'��q�	��
�
��<��>`��&Ls$�	C'�#C'�-	C,�7C,�	C1�C1c���t|tj�r	|St|tj�rtj|d�}|St
|dd�}td|����)N.rrz???z!Unexpected type of exclude value )r rprrqrC�fromkeys�getattrr,)rB�
class_names  r'r\zValueItems._coerce_items�sf���e�V�^�^�,������v�1�1�
2��M�M�%��-�E���!���U�;�J��?�
�|�L�M�Mr)c�N�|�|j|�r|S|j|�Sr)rcr\)r4r`s  r'rszValueItems._coerce_values(���=�C�K�K��.��L�� � ��'�'r)c��|duxs|duS)NT.�r%s r'rczValueItems.is_trues���D�y�$�A��H�$r)c� �d|jfgSrri)r_s r'�
__repr_args__zValueItems.__repr_args__s���t�{�{�#�$�$r)N)r`rrB�$AbstractSetIntStr | MappingIntStrAny�return�None)rfrr��bool)rlz	int | strr�z+AbstractSetIntStr | MappingIntStrAny | None)rBrrxrtr�zdict[int | str, Any])F)r�rr�rrr�r�r)rBr�r�r)r`rr�r�r&rr�r�)r�z_repr.ReprArgs)�__name__�
__module__�__qualname__�__doc__�	__slots__rargrjrmr]�classmethodru�staticmethodr\rsrcr�r�r)r'rXrX�sz��Y�#�I�.�3�#�8�# �J�#��#�J�����(��(�
�%��%�%r)rXc��yrr���namer`s  r'�ClassAttributer�s��#r)c�$�eZdZdZdZdd�Zdd�Zy)r�z(Hide class attribute from its instances.r�c� �||_||_yrr�)r_r�r`s   r'razClassAttribute.__init__!s���D�I��D�Jr)c�h�|�|jSt|j�d|j�d���)Nz attribute of z is class-only)r`�AttributeErrorr�r�)r_�instance�owners   r'�__get__zClassAttribute.__get__%s4�����z�z�!� �D�I�I�=��u�~�~�>P�P^�!_�`�`r)N)r��strr`rr�r�)r�rr�z	type[Any]r�r�)r�r�r�r�r�rar�r�r)r'r�r�s��6�#�	�	�	ar)r��Objc���|j}|tvr|S	|s"|tvr|tur|S|j	�St|�S#t
ttf$r
Yt|�SwxYw)z�Return 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.
    )	rrrrr"rAr,�
ValueError�RuntimeErrorr)�obj�obj_types  r'�smart_deepcopyr�.st��
�}�}�H��2�2��
�
��x�#6�6�"�e�+�3�;�����;�
�C�=���	
�z�<�0�
���C�=��	
�s�A�A�A(�'A(c�D�t||t��D]\}}||us�yy)aCheck 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�Ds-��"-�T�5�I�!N��	�:��J�&��"O�r)T)�frozenc�J�eZdZUdZdZded<dd�Zejrd	d�Z	yy)
�SafeGetItemProxyz�Wrapper 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
    )�wrappedzMapping[str, Any]r�c�B�|jj|t�Sr)r�rdr��r_�keys  r'�__getitem__zSafeGetItemProxy.__getitem__`s���|�|����Y�/�/r)c�8�|jj|�Sr)r��__contains__r�s  r'r�zSafeGetItemProxy.__contains__is���<�<�,�,�S�1�1r)N)r�r�r�r)r�r�r�r�)
r�r�r�r�r��__annotations__r�rp�
TYPE_CHECKINGr�r�r)r'r�r�Ss.����I�
��0����	2�r)r�r�)r-rr.z(type[Any] | tuple[type[Any], ...] | Noner�r�)r4rr.rr�r�)r4rr�zTypeGuard[type[BaseModel]])r=r�r�r�)rE�dict[KeyType, Any]rFr�r�r�)rEzdict[Any, Any]rKrr�r�)rRzlist[T] | tuple[T, ...]rNztyping.Callable[[T], str]r�zlist[T])r�r�r`rMr�rM)r�r�r�r�)r��typing.Iterable[Any]r�r�r�r�)Mr��
__future__r�_annotations�dataclassesr;rp�weakref�collectionsrrrrAr�	itertoolsr�typesr	r
rrr
rrrr�typing_extensionsrr�rrr�rr�rr7rrt�float�complexr�r��bytesr1�NoneType�ref�NotImplementedrr�Ellipsisrr!r#r"r$rCrr(r/r5r8r>r?rDrLrMrV�RepresentationrXr�r�r��objectr�r��	dataclassr�r�r)r'�<module>r�s����
3���
��7�7��!�d�d�(�(�2�"�	���"W��i�W�#V��y�V� �
�	����	���������K�K���������'3����0	��	�
����	�	'��^�	�N���G�K��)�
���G��C�L��/2��'��,��
�	�,C%��%�%�C%�L
���5�a�a��e�n���&
�H�	������d�#�2�2�$�2r)
Back to Directory File Manager