o
    $6d-                     @  s  U d Z ddlm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mZ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mZ ejrhdZde d< dZ!de d< ddl"m#Z# e$e%e&e'e(e)e*ej+eeeej,eee-j.e/j.hZ0de d< e1e2e3e4e5ee	e
hZ6de d< dOddZ7dPdd Z8dQd"d#Z9dRd%d&Z:dSd)d*Z;ed+Z<dTd/d0Z=dUd4d5Z>ed6Z?e'd7dVd=d>Z@G d?d@ d@ejAZBejrdWdCdDZCnG dEdD dDZCedFZDdXdHdIZEeF ZGdYdMdNZHdS )ZzBucket 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TypeVar)	TypeAlias	TypeGuard   )_repr_typing_extraz3typing.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vr   returnboolc                 C  s   t | ttttttfS N)
isinstancelisttupleset	frozensetr   r   r    r&   pC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/_internal/_utils.pysequence_like>   s   r(   oclass_or_tuple(type[Any] | tuple[type[Any], ...] | Nonec                 C  s"   zt | |W S  ty   Y dS w NF)r    	TypeError)r)   r*   r&   r&   r'   lenient_isinstanceB   s
   r.   clsc                 C  s:   zt | to
t| |W S  ty   t | tjrY dS  w r,   )r    type
issubclassr-   r   ZWithArgsTypes)r/   r*   r&   r&   r'   lenient_issubclassI   s   r2   TypeGuard[type[BaseModel]]c                 C  s   ddl m} 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   r   )mainr   r2   )r/   r   r&   r&   r'   is_model_classR   s   r5   
identifierstrc                 C  s   |   o	t|  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)r6   r&   r&   r'   is_valid_identifier[   s   r;   KeyTypemappingdict[KeyType, Any]updating_mappingsc                 G  sd   |   }|D ])}| D ]"\}}||v r*t|| tr*t|tr*t|| |||< q|||< qq|S r   )copyitemsr    dictdeep_update)r=   r?   Zupdated_mappingZupdating_mappingkr   r&   r&   r'   rC   f   s    
rC   dict[Any, Any]updateNonec                 K  s   |  dd | D  d S )Nc                 S  s   i | ]\}}|d ur||qS r   r&   ).0rD   r   r&   r&   r'   
<dictcomp>r   s    z#update_not_none.<locals>.<dictcomp>)rF   rA   )r=   rF   r&   r&   r'   update_not_noneq   s   rJ   T)name_factory
input_listlist[T] | tuple[T, ...]rL   typing.Callable[[T], str]list[T]c                C  sJ   g }g }| D ]}||}||vr| | | | q||||< q|S )zMake a list unique while maintaining order.
    We update the list if another one with the same name is set
    (e.g. root validator overridden in subclass).
    )appendindex)rM   rL   resultZresult_namesr   Zv_namer&   r&   r'   unique_listx   s   	
rT   c                   @  s   e Zd ZdZdZd-d	d
Zd.ddZd.ddZd/ddZd0ddZ	e
d1d2d d!Zed3d"d#Ze
d4d$d%Zed5d'd(Zd6d*d+Zd,S )7
ValueItemszOClass for more convenient calculation of excluded or included fields on values.)_items_typevaluer   rA   $AbstractSetIntStr | MappingIntStrAnyr   rG   c                 C  s2   |  |}t|ttfr| |t|}|| _d S r   )_coerce_itemsr    r!   r"   _normalize_indexeslenrV   )selfrX   rA   r&   r&   r'   __init__   s   

zValueItems.__init__itemr   c                 C  s   |  | j|S )zWCheck if item is fully excluded.

        :param item: key or index of a value
        )is_truerV   getr]   r_   r&   r&   r'   is_excluded   s   zValueItems.is_excludedc                 C  s
   || j v S )z`Check if value is contained in self._items.

        :param item: key or index of value
        rV   rb   r&   r&   r'   is_included   s   
zValueItems.is_includede	int | str+AbstractSetIntStr | MappingIntStrAny | Nonec                 C  s   | 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)rV   ra   r`   )r]   rf   r_   r&   r&   r'   for_element   s   zValueItems.for_elementr   v_lengthintdict[int | str, Any]c           	      C  s
  i }d}|  D ]H\}}t|tjs(t|tjs(| |s(td| d|j |dkr2| |}qt|t	s;td|dk rC|| n|}| 
|||||< q|sU|S | |rit|D ]}||d q^|S t|D ]}||i }| |s| 
||||< qm|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   .)rA   r    typingMappingAbstractSetr`   r-   	__class___coerce_valuerk   mergera   range
setdefault)	r]   rA   rj   Znormalized_itemsZ	all_itemsir   Znormalized_inormalized_itemr&   r&   r'   r[      s4   	"



zValueItems._normalize_indexesFbaseoverride	intersectc                   s   |  |    du r S |  s du rS | r&|r$ S S |r;fdd D  fddD  }nt  fddD  }i }|D ]}| j |||d}|durd|||< qL|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 r|qS r&   r&   rH   rD   )ry   r&   r'   
<listcomp>       z$ValueItems.merge.<locals>.<listcomp>c                   r{   r&   r&   r|   rx   r&   r'   r}      r~   c                   s   g | ]}| vr|qS r&   r&   r|   r   r&   r'   r}      r~   )rz   )rr   r`   r!   rs   ra   )r/   rx   ry   rz   Z
merge_keysmergedrD   Zmerged_itemr&   )rx   ry   r'   rs      s$   


&zValueItems.mergec                 C  sH   t | tjr		 | S t | tjrt| d} | S t| dd}td| )N.rq   z???z!Unexpected type of exclude value )r    rn   ro   rp   rB   fromkeysgetattrr-   )rA   
class_namer&   r&   r'   rZ      s   zValueItems._coerce_itemsc                 C  s    |d u s	|  |r|S | |S r   )r`   rZ   )r/   rX   r&   r&   r'   rr     s   
zValueItems._coerce_valuer   c                 C  s   | du p| du S )NT.r&   r%   r&   r&   r'   r`     s   zValueItems.is_true_repr.ReprArgsc                 C  s   d | j fgS r   rd   )r]   r&   r&   r'   __repr_args__  s   zValueItems.__repr_args__N)rX   r   rA   rY   r   rG   )r_   r   r   r   )rf   rg   r   rh   )rA   r   rj   rk   r   rl   )F)rx   r   ry   r   rz   r   r   r   )rA   rY   r   r   )rX   r   r   r   r   r   r   r   )r   r   )__name__
__module____qualname____doc__	__slots__r^   rc   re   ri   r[   classmethodrs   staticmethodrZ   rr   r`   r   r&   r&   r&   r'   rU      s"    




%%
rU   namerX   c                 C  s   d S r   r&   r   rX   r&   r&   r'   ClassAttribute  s   r   c                   @  s(   e Zd ZdZdZdd	d
ZdddZdS )r   z(Hide class attribute from its instances.r   r   r7   rX   r   r   rG   c                 C  s   || _ || _d S r   r   )r]   r   rX   r&   r&   r'   r^      s   
zClassAttribute.__init__instanceowner	type[Any]c                 C  s&   |d u r| j S t| jd|jd)Nz attribute of z is class-only)rX   AttributeErrorr   r   )r]   r   r   r&   r&   r'   __get__$  s   zClassAttribute.__get__N)r   r7   rX   r   r   rG   )r   r   r   r   r   rG   )r   r   r   r   r   r^   r   r&   r&   r&   r'   r     s
    
Objobjc              
   C  sj   | j }|tv r	| S z| s|tv r!|tu r| W S |  W S W t| S W t| S  tttfy4   Y t| S 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.
    )	rq   r   r   r"   r@   r-   
ValueErrorRuntimeErrorr   )r   obj_typer&   r&   r'   smart_deepcopy-  s   r   lefttyping.Iterable[Any]rightc                 C  s*   t | |tdD ]\}}||ur dS q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   _EMPTY)r   r   Z	left_itemZ
right_itemr&   r&   r'   all_identicalC  s
   	r   r   )r)   r   r*   r+   r   r   )r/   r   r*   r   r   r   )r/   r   r   r3   )r6   r7   r   r   )r=   r>   r?   r>   r   r>   )r=   rE   rF   r   r   rG   )rM   rN   rL   rO   r   rP   )r   r7   rX   rK   r   rK   )r   r   r   r   )r   r   r   r   r   r   )Ir   
__future__r   Z_annotationsr9   rn   weakrefcollectionsr   r   r   r@   r   	itertoolsr   typesr   r	   r
   r   r   r   r   r   Ztyping_extensionsr   r    r   r   TYPE_CHECKINGr   __annotations__r   r4   r   rk   floatcomplexr7   r   bytesr0   NoneTyperefNotImplementedrq   Ellipsisr   r!   r#   r"   r$   rB   r   r(   r.   r2   r5   r;   r<   rC   rJ   rK   rT   ZRepresentationrU   r   r   r   objectr   r   r&   r&   r&   r'   <module>   s|     



	
	

 
