
    8'h1                       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mZmZmZmZmZ ddl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jD                  rd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e1jd                  e3jd                  hZ4de$d<   e5e6e7e8e9e	e
ehZ:de$d<   d.dZ;d/dZ<d0dZ=d1dZ>d2dZ? ed      Z@d3dZAd4dZB ed      ZCe+d 	 	 	 	 	 d5d!ZD G d" d#ej                        ZFejD                  rd6d$ZGn
 G d% d&      ZG ed'      ZHd7d(ZI eJ       ZKd8d)ZL ej                  d*+       G d, d-             ZNy)9zBucket 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_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           	     V    t        | t        t        t        t        t
        t        f      S N)
isinstancelisttupleset	frozensetr   r   vs    U/var/www/html/trade_iq/venv/lib/python3.12/site-packages/pydantic/_internal/_utils.pysequence_liker(   A   s    a$sI}eLMM    c                :    	 t        | |      S # t        $ r Y yw xY wNF)r    	TypeError)oclass_or_tuples     r'   lenient_isinstancer/   E   s&    !^,, s    	c                    	 t        | t              xr t        | |      S # t        $ r t        | t        j
                        rY y w xY wr+   )r    type
issubclassr,   r   WithArgsTypes)clsr.   s     r'   lenient_issubclassr5   L   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   r5   )r4   r   s     r'   is_model_classr7   U   s#     )*Ic9-F#Y2FFr)   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_identifierr=   ^   s&    
 ""$JW->->z-J)JJr)   KeyTypec                    | j                         }|D ]Y  }|j                         D ]D  \  }}||v r6t        ||   t              r#t        |t              rt	        ||   |      ||<   @|||<   F [ |S r   )copyitemsr    dictdeep_update)mappingupdating_mappingsupdated_mappingupdating_mappingkr&   s         r'   rC   rC   i   s    llnO- '$**, 	'DAqO#
?13Et(LQ[\]_cQd%01CQ%G"%&"		'' r)   c                |    | j                  |j                         D ci c]  \  }}|	|| c}}       y c c}}w r   )updaterA   )rD   rJ   rH   r&   s       r'   update_not_nonerK   t   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_listrM   resultresult_namesr&   v_names         r'   unique_listrU   {   sd     F L 3a%'MM!12F<%%f-.3 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y)
ValueItemszOClass for more convenient calculation of excluded or included fields on values.)_items_typec                    | j                  |      }t        |t        t        f      r| j	                  |t        |            }|| _        y r   )_coerce_itemsr    r!   r"   _normalize_indexeslenrX   )selfvaluerA   s      r'   __init__zValueItems.__init__   s=    ""5)edE]+++E3u:>E(-r)   c                V    | j                  | j                  j                  |            S )zWCheck if item is fully excluded.

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

        :param item: key or index of value
        rX   rd   s     r'   is_includedzValueItems.is_included   s    
 t{{""r)   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)rX   rc   rb   )r^   ere   s      r'   for_elementzValueItems.for_element   s,     {{q!<<-t747r)   c                   i }d}|j                         D ]  \  }}t        |t        j                        sFt        |t        j                        s,| j                  |      st        d| d|j                         |dk(  r| j                  |      }}t        |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   .)rA   r    typingr   AbstractSetrb   r,   	__class___coerce_valueintmergerc   range
setdefault)	r^   rA   v_lengthnormalized_items	all_itemsir&   normalized_inormalized_items	            r'   r\   zValueItems._normalize_indexes   sv    24	KKM 	_DAqq&..1Z6CUCU5VZ^ZfZfghZi"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  r)   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)rr   rb   r!   rt   rc   )r4   baseoverrider~   rH   
merge_keysmergedmerged_items           r'   rt   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        j                        r	 | S t        | t        j                        rt        j                  | d      } | S t        | dd      }t        d|       )N.rq   z???z!Unexpected type of exclude value )r    ro   r   rp   rB   fromkeysgetattrr,   )rA   
class_names     r'   r[   zValueItems._coerce_items   sf    eV^^,  v112MM%-E  !U;J?
|LMMr)   c                N    || j                  |      r|S | j                  |      S r   )rb   r[   )r4   r_   s     r'   rr   zValueItems._coerce_value	  s(    =CKK.L  ''r)   c                    | du xs | du S )NT. r%   s    r'   rb   zValueItems.is_true  s    Dy$AH$r)   c                     d | j                   fgS r   rh   )r^   s    r'   __repr_args__zValueItems.__repr_args__  s    t{{#$$r)   N)r_   r   rA   $AbstractSetIntStr | MappingIntStrAnyreturnNone)re   r   r   bool)rk   z	int | strr   z+AbstractSetIntStr | MappingIntStrAny | None)rA   r   rw   rs   r   zdict[int | str, Any])F)r   r   r   r   r~   r   r   r   )rA   r   r   r   )r_   r   r   r   r&   r   r   r   )r   z_repr.ReprArgs)__name__
__module____qualname____doc__	__slots__r`   rf   ri   rl   r\   classmethodrt   staticmethodr[   rr   rb   r   r   r)   r'   rW   rW      sz    Y#I.3#8# J # #J   ( (
 % %%r)   rW   c                     y r   r   namer_   s     r'   ClassAttributer     s    r)   c                  $    e Zd ZdZdZddZddZy)r   z(Hide class attribute from its instances.r   c                     || _         || _        y r   r   )r^   r   r_   s      r'   r`   zClassAttribute.__init__"  s    DIDJr)   c                h    || j                   S t        | j                  d|j                  d      )Nz attribute of z is class-only)r_   AttributeErrorr   r   )r^   instanceowners      r'   __get__zClassAttribute.__get__&  s4    zz! DII=u~~>PP^!_``r)   N)r   strr_   r   r   r   )r   r   r   z	type[Any]r   r   )r   r   r   r   r   r`   r   r   r)   r'   r   r     s    6#			ar)   r   Objc                    | 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.
    )	rq   r   r   r"   r@   r,   
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 ]  \  }}||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   E  s1     "-T5I!N 	:J& r)   T)frozenc                  J    e Zd ZU dZdZded<   ddZej                  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 r   )r   rc   r   r^   keys     r'   __getitem__zSafeGetItemProxy.__getitem__a  s    ||Y//r)   c               8    | j                   j                  |      S r   )r   __contains__r   s     r'   r   zSafeGetItemProxy.__contains__j  s    <<,,S11r)   N)r   r   r   r   )r   r   r   r   )
r   r   r   r   r   __annotations__r   ro   TYPE_CHECKINGr   r   r)   r'   r   r   T  s.     I0 	2 r)   r   r   )r-   r   r.   z(type[Any] | tuple[type[Any], ...] | Noner   r   )r4   r   r.   r   r   r   )r4   r   r   zTypeGuard[type[BaseModel]])r<   r   r   r   )rD   dict[KeyType, Any]rE   r   r   r   )rD   zdict[Any, Any]rJ   r   r   r   )rQ   zlist[T] | tuple[T, ...]rM   ztyping.Callable[[T], str]r   zlist[T])r   r   r_   rL   r   rL   )r   r   r   r   )r   typing.Iterable[Any]r   r   r   r   )Or   
__future__r   _annotationsdataclassesr:   ro   weakrefcollectionsr   r   r   r@   r   	itertoolsr   typesr	   r
   r   r   r   r   r   r   r   typing_extensionsr   r    r   r   _import_utilsr   r   r   r   r   mainr   rs   floatcomplexr   r   bytesr1   NoneTyperefNotImplementedrq   Ellipsisr   r!   r#   r"   r$   rB   r   r(   r/   r5   r7   r=   r>   rC   rK   rL   rU   RepresentationrW   r   r   r   objectr   r   	dataclassr   r   r)   r'   <module>r      s  
 3     7 7  ! d d ( ( 2 " 3	"WiW#VyV 
 		KK '3  0 				' ^ 	NGK )
G CL /2' , 	,C%%% C%L 
5a a en& H	 d#2 2 $2r)   