
    gQ                    $   d dl mZ d dlZd dlmZ d dlmZ d dlZd dl	Z	d dl
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 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 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 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$ 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* 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m0Z0 d d*lm1Z1  ed+e,      Z2 ed-      Z3 ed.d/      Z4 ed0d1      Z5 ed2      Z6 ed3d/      Z7ejp                  r e9e
jN                  e'g      Z:n	 e9e'g      Z:ejv                  rd d4l<m=Z= n e>d      Z= ed5      Z?eee   e@eee0d6f   ZA G d7 d8e*      ZB G d9 d:e*e2         ZC G d; d<e*e3e7f         ZDe'd=   ZEdd>dd?	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dld@ZF	 	 	 	 dmdAZG	 	 	 	 	 	 dndBZHdddC	 	 	 	 	 	 	 	 	 dodDZIddE	 	 	 	 	 	 	 dpdFZJdqdGZKdrdHZLdsdIZMdtdJZNdudKZOdvdLZPdwdMZQdxdNZRdydOZS	 	 dz	 	 	 	 	 	 	 d{dPZTed|dQ       ZUed}dR       ZUe	 	 	 	 dmdS       ZU	 	 	 	 dmdTZUe	 	 	 	 	 	 d~dU       ZVe	 	 	 	 	 	 ddV       ZV	 	 	 	 	 	 ddWZVddXZWdtdYZXddZZY	 	 	 	 	 	 dd[ZZdd\	 	 	 	 	 	 	 dd]Z[dd^Z\ G d_ d`e*      Z] edae],      Z^ G db dcee^         Z_ edde]de      Z` G df dgee`         Za edheedief      ,      Zb G dj dkeeb         Zcy)    )annotationsN)deque)Any)Callable)cast)Dict)
ForwardRef)Generic)Iterable)Mapping)NewType)NoReturn)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )compatT)	Annotated)Concatenate)dataclass_transform)Final)final)get_args)
get_origin)Literal)NotRequired)	ParamSpec)Protocol)SupportsIndex)	TypeAlias)	TypedDict)	TypeGuard)Self)TypeAliasType)Never_T)bound_KT_KT_co)	covariant
_KT_contra)contravariant_VT_VT_co)NoneTypeNonezGenericProtocol[Any]c                      e Zd ZU dZded<   y)ArgsTypeProtocolz_protocol for types that have ``__args__``

    there's no public interface for this AFAIK

    Tuple[_AnnotationScanType, ...]__args__N__name__
__module____qualname____doc____annotations__     U/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/sqlalchemy/util/typing.pyr7   r7   Z   s     .-rA   r7   c                  &    e Zd ZU dZded<   ded<   y)GenericProtocolzXprotocol for generic types.

    this since Python.typing _GenericAlias is private

    r8   r9   Type[_T]
__origin__Nr:   r@   rA   rB   rD   rD   d   s     .-rA   rD   c                      e Zd ZddZddZy)SupportsKeysAndGetItemc                     y Nr@   )selfs    rB   keyszSupportsKeysAndGetItem.keysy       rA   c                     y rJ   r@   )rK   _SupportsKeysAndGetItem__ks     rB   __getitem__z"SupportsKeysAndGetItem.__getitem__{   rM   rA   N)returnzIterable[_KT])rO   r-   rQ   r3   )r;   r<   r=   rL   rP   r@   rA   rB   rH   rH   x   s    (2rA   rH   *Fstr_cleanup_fninclude_generic_already_seenc               l    |}t        |      r|j                  }t        |t              rr	 |      }t	        |       }rht        |      r]t        |      sR
t               |v r|S j                  |       t         fd|j                  D              }t        ||      S |S )a;  Resolve annotations that may be string based into real objects.

    This is particularly important if a module defines "from __future__ import
    annotations", as everything inside of __annotations__ is a string. We want
    to at least have generic containers like ``Mapped``, ``Union``, ``List``,
    etc.

    locals_in_classc           
   3  B   K   | ]  }t        |         yw)rS   N)de_stringify_annotation).0elemrV   clsrU   rY   originating_modulerT   s     rB   	<genexpr>z*de_stringify_annotation.<locals>.<genexpr>   s:      
  $"- /+ 
s   )
is_fwd_ref__forward_arg__
isinstancestreval_expression
is_generic
is_literalsetaddtupler9   _copy_generic_annotation_with)	r_   
annotationr`   rY   rT   rU   rV   original_annotationelementss	   ` `````  rB   r\   r\      s    . %*//
*c"'
4FGJ$*Gc


 	z":& EM&
 '&j) 
 
 #++
 
 -ZBBrA   c                   t        |       rt        |       t        t        t        t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  fv rtt        j                  dt        |             sUt        |       j                  t        t!        |       D cg c]  }t#        |t$              rt'        |      n|! c}            S | S c c}w )zfCorrect dict['x', 'y'] into dict[ForwardRef('x'), ForwardRef('y')]
    and similar for list, set

    z3typing.(?:Dict|List|Set|.*Mapping|.*Sequence|.*Set))rg   r   dictri   listcollections_abc
MutableSetMutableMappingMutableSequencer   Sequencerematchrepr__class_getitem__rk   r   rd   re   r	   )type_r^   s     rB   fixup_container_fwd_refsr}      s     	5u&&**++##$$	


 A4;

 % 22 !) )34(=Jt$4G
 	
 Ls   8$C)c                Z    t        | d      r| j                  |      S | j                  |   S )N	copy_with)hasattrr   rF   )rm   ro   s     rB   rl   rl      s2     z;'##H-- $$X..rA   rX   c                  	 t         j                  |   j                  }	 |Qt        |j                        }|j                  |j                  |       |j                  |       t        | ||      }|S t        | ||      }	 |S # t        $ r}t	        d| d|        |d }~ww xY w# t        $ r}t	        d|       |d }~ww xY w)NModule z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation )sysmodules__dict__KeyError	NameErrorrq   
setdefaultr;   updateeval	Exception)	
expressionmodule_namerY   rZ   base_globalskecls_namespacerm   errs	            rB   rf   rf      s    '*{{;'?'H'H !2!23M$$X%6%6A
   .j-AJ  j,@J 1  k] ###-,0
 	&  0?
	s5   B AB& 3B& 	B#BB#&	C/B>>CrY   c               J   d| v rt        | ||      S 	 t        j                  |   j                  }	 ||    S # t        $ r}t        d| d|        |d }~ww xY w# t        $ r?}	 t        j                  |    cY d }~S # t        $ r Y nw xY wt        d|  d|       |d }~ww xY w)N.r   r   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rf   r   r   r   r   r   builtins)namer   rY   r   r   s        rB   eval_name_onlyr   !  s     d{t['BB'*{{;'?'H'HD!!  k] # 6#
 	  		$$T** 		 $TF+k]C
		sJ   7 A 	A AA	B"$A<6B"<	BBBBB"c                X    	 t        | |      }t        |d|       S # t        $ r | cY S w xY w)Nr;   )r   getattrr   )r   r   objs      rB   resolve_name_to_real_class_namer   C  s:    .T;/ sJ--  s    ))c                0    | d uxr t        |       t        u S rJ   )r   r   r|   s    rB   	is_pep593r   L  s    ?E!2i!??rA   c                h    t        | t        j                        xr t        | t        t        f       S rJ   )rd   rs   r   re   bytes)r   s    rB   is_non_string_iterabler   P  s1    c?334 Zc5\> : rA   c                $    t        |       t        v S rJ   )r   LITERAL_TYPESr   s    rB   rh   rh   V  s    e--rA   c                    t        | d      S )N__supertype__r   r   s    rB   
is_newtyper   Z  s    5/**rA   c                6    t        | d      xr t        | d      S )Nr9   rF   r   r   s    rB   rg   rg   b  s    5*%F'%*FFrA   c                "    t        | t              S rJ   )rd   r)   r   s    rB   	is_pep695r   f  s    e]++rA   c                d    | j                   }t        |      r|j                   }t        |      r|S rJ   )r   r   )r|   
super_types     rB   flatten_newtyper   j  s0    $$J
Z
 --
 Z
 rA   c                :   t               fd |       }t        |t              rot               }t        |      }|rV|j	                         }t        |t              r|j                  |       n!|j                  |t        t        hv rdn|       |rV|S |hS )zExtracts the value from a TypeAliasType, recursively exploring unions
    and inner TypeAliasType to flatten them into a single set.

    Forward references are not evaluated, so no recursive exploration happens
    into them.
    c                    | v r| S j                  |        t        |       s| S | j                  }t        |      s|S |j                  D cg c]
  } |       c}S c c}w rJ   )rj   r   	__value__is_unionr9   )r|   valuet_seenrecursive_values      rB   r   z&pep695_values.<locals>.recursive_valuez  s\    E> L		%LL,1NN;q";;;s   AN)	ri   rd   rr   r   popleftextendrj   r4   NoneFwd)r|   restypesstackr   r   r   s        @@rB   pep695_valuesr   q  s     EE< %
 C#tc
A!T"Q		!'':":$B  urA   c                    rt        | t              ryt        | t              ry|r)t        |       rt	        fd| j
                  D              S y)NTc              3  :   K   | ]  }t        |d         yw)T)check_for_plain_stringN)rb   )r]   argr   s     rB   ra   zis_fwd_ref.<locals>.<genexpr>  s-      
  T2H 
s   F)rd   re   r	   rg   anyr9   )r|   check_genericr   s     `rB   rb   rb     sP    
 *UC"8	E:	&	:e, 
 ~~	
 
 	
 rA   c                     y rJ   r@   r   s    rB   de_optionalize_union_typesr     s    36rA   c                     y rJ   r@   r   s    rB   r   r     s    ?BrA   c                     y rJ   r@   r   s    rB   r   r          rA   c                   t        |       rt        | d      S t        |       rt        |       rt        j
                  rt        | j                        }n{t        | g      }t               }|rR|j                         }|j                  D ]0  }t        |      r|j                  |        |j                  |       2 |rR|j                  d       |j                  t               |j                  t               t        | S | S )zGiven a type, filter out ``Union`` types that include ``NoneType``
    to not include the ``NoneType``.

    Contains extra logic to work on non-flattened unions, unions that contain
    ``None`` (seen in py38, 37)

    FN)rb   #_de_optionalize_fwd_ref_union_typesr   includes_noner   py39ri   r9   r   r   appendrj   discardr4   r   make_union_type)r|   typstack_of_unionsu_typr^   s        rB   r   r     s     %25%@@	%]51;;enn%C $UGnO%C!'//1!NN &D~'..t4	& " KKHG$$ rA   c                     y rJ   r@   r|   return_has_nones     rB   r   r     s     rA   c                     y rJ   r@   r   s     rB   r   r     r   rA   c                   | j                   }t        j                  d|      }|r^|j                  d      j	                  d      d   }|dk(  r|rdS t        |j                  d            S |dk(  rd	|j                  d      v rg }g }d
}|j                  d      D ]r  }|d	k(  r|dz  }nT|dk(  r|dz  }nI|d
k(  rD|dk(  r?|j                  dj                  |      j                                |j                          b|j                  |       t n%t        j                  d|j                  d            }|D 	cg c]  }	|	dk7  s	t        |	       }
}	|rt        |      t        |
      k7  S |
rt        |
 S t        S |rdS | S t        j                  d|      }d|v }|r|S |r+dj                  d |D              }|rt        |      S t        S | S c c}	w )zreturn the non-optional type for Optional[], Union[None, ...], x|None,
    etc. without de-stringifying forward refs.

    unfortunately this seems to require lots of hardcoded heuristics

    z^(.+?)\[(.+)\]$r   r   r   T   r   [r   ], z,\s*r5   Fz\s*\|\s*|c              3  ,   K   | ]  }|d k7  s	|  yw)r5   Nr@   )r]   ps     rB   ra   z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>  s     B!a6kABs   
)rc   rx   ry   groupsplitr	   r   joinstripclearlenr   r*   )r|   r   rm   mmg1ro   currentignore_commacharr^   partspipe_tokenshas_noneanno_strs                 rB   r   r     s    &&J	$j	1B	XXa[s#B'*4G
288A;0GG7]bhhqk!&(%' HHQK 	)Ds{$)$)%*ts{ (8(>(>(@A NN4(	) 88GRXXa[92:M$dfnZ%MEM8}E
2227.BUB+566((;
3K$H88B{BB'/z(#:U:L! Ns   ;
GGc                 ,    t        j                  |       S )zMake a Union type.)r   rP   )r   s    rB   r   r   #  s    U##rA   c                j   t        |       rt        | d      S t        |       rt        d t	        |       D              S t        |       rt        t	        |       d         S t        |       rt        d t        |       D              S t        |       rt        | j                        S | t        t        dfv S )a.  Returns if the type annotation ``type_`` allows ``None``.

    This function supports:
    * forward refs
    * unions
    * pep593 - Annotated
    * pep695 - TypeAliasType (does not support looking into
    fw reference of other pep695)
    * NewType
    * plain types like ``int``, ``None``, etc
    Tc              3  2   K   | ]  }t        |        y wrJ   r   r]   r   s     rB   ra   z includes_none.<locals>.<genexpr>7  s     ==#=   r   c              3  2   K   | ]  }t        |        y wrJ   r   r   s     rB   ra   z includes_none.<locals>.<genexpr>;  s     B=#Br   N)rb   r   r   r   r   r   r   r   r   r   r   r   r4   r   s    rB   r   r   (  s     %25$??=Xe_===Xe_Q/00B]5-ABBB%U0011Wh---rA   c                    t        | dd      S )Nr   	UnionType)is_origin_ofr   s    rB   r   r   A  s    w44rA   c                Z    t        |       }|yt        |t              xr t        ||      S )z[return True if the given type has an __origin__ that shares a base
    with the given classF)r   rd   type
issubclass)r|   	class_objorigins      rB   is_origin_of_clsr   E  s/     F~fd#E
69(EErA   )modulec               ~    t        |       }|yt        |      |v xr! |du xs |j                  j                  |      S )z\return True if the given type has an __origin__ with the given name
    and optional module.NF)r   _get_type_namer<   
startswith)r|   r   namesr   s       rB   r   r   R  sJ     F~&!U* $>&++66v>rA   c                v    t         j                  r| j                  S t        | dd       }|t        | dd       }|S )Nr;   _name)r   py310r;   r   )r|   typ_names     rB   r  r  a  s:    ||~~5*d3ugt4HrA   c                  $    e Zd ZddZddZddZy)DescriptorProtoc                     y rJ   r@   rK   instanceowners      rB   __get__zDescriptorProto.__get__m  rM   rA   c                     y rJ   r@   rK   r  r   s      rB   __set__zDescriptorProto.__set__o  rM   rA   c                     y rJ   r@   rK   r  s     rB   
__delete__zDescriptorProto.__delete__q  rM   rA   N)r  objectr  r   rQ   r   )r  r   r   r   rQ   r5   r  r   rQ   r5   )r;   r<   r=   r  r  r  r@   rA   rB   r	  r	  l  s    ?=4rA   r	  _DESCc                  .    e Zd ZdZerddZddZddZyy)	DescriptorReferencea  a descriptor that refers to a descriptor.

    used for cases where we need to have an instance variable referring to an
    object that is itself a descriptor, which typically confuses typing tools
    as they don't know when they should use ``__get__`` or not when referring
    to the descriptor assignment as an instance variable. See
    sqlalchemy.orm.interfaces.PropComparator.prop

    c                     y rJ   r@   r  s      rB   r  zDescriptorReference.__get__  rM   rA   c                     y rJ   r@   r  s      rB   r  zDescriptorReference.__set__  rM   rA   c                     y rJ   r@   r  s     rB   r  zDescriptorReference.__delete__  rM   rA   N)r  r  r  r   rQ   r  )r  r   r   r  rQ   r5   r  r;   r<   r=   r>   r   r  r  r  r@   rA   rB   r  r  w  s     EC8 rA   r  _DESC_co)r,   r/   c                  .    e Zd ZdZerddZddZddZyy)	RODescriptorReferenceza descriptor that refers to a descriptor.

    same as :class:`.DescriptorReference` but is read-only, so that subclasses
    can define a subtype as the generically contained element

    c                     y rJ   r@   r  s      rB   r  zRODescriptorReference.__get__  rM   rA   c                     y rJ   r@   r  s      rB   r  zRODescriptorReference.__set__  rM   rA   c                     y rJ   r@   r  s     rB   r  z RODescriptorReference.__delete__  rM   rA   N)r  r  r  r   rQ   r  )r  r   r   r   rQ   r   )r  r   rQ   r   r  r@   rA   rB   r   r     s     HE< rA   r   _FN.c                  .    e Zd ZdZerddZddZddZyy)	CallableReferenceza descriptor that refers to a callable.

    works around mypy's limitation of not allowing callables assigned
    as instance variables


    c                     y rJ   r@   r  s      rB   r  zCallableReference.__get__  rM   rA   c                     y rJ   r@   r  s      rB   r  zCallableReference.__set__  rM   rA   c                     y rJ   r@   r  s     rB   r  zCallableReference.__delete__  rM   rA   N)r  r  r  r   rQ   r$  )r  r   r   r$  rQ   r5   r  r  r@   rA   rB   r&  r&    s     CA8 rA   r&  )r_   	Type[Any]rm   _AnnotationScanTyper`   re   rY   zMapping[str, Any]rT   z#Optional[Callable[[str, str], str]]rU   boolrV   zOptional[Set[Any]]rQ   r*  )r|   r+  rQ   r+  )rm   zGenericProtocol[_T]ro   r8   rQ   rE   )
r   re   r   re   rY   Optional[Mapping[str, Any]]rZ   zOptional[Type[Any]]rQ   r   )r   re   r   re   rY   r-  rQ   r   )r   re   r   re   rQ   re   )r|   zOptional[Any]rQ   r,  )r   r   rQ   zTypeGuard[Iterable[Any]])r|   r   rQ   r,  )r|   zOptional[_AnnotationScanType]rQ   zTypeGuard[NewType])r|   r+  rQ   zTypeGuard[GenericProtocol[Any]])r|   r+  rQ   zTypeGuard[TypeAliasType])r|   r   rQ   r*  )r|   r+  rQ   zSet[Any])FF)r|   r+  r   r,  r   r,  rQ   zTypeGuard[ForwardRef])r|   re   rQ   re   )r|   r*  rQ   r*  )r|   r	   r   zLiteral[True]rQ   r,  )r|   r	   r   zLiteral[False]rQ   r+  )r|   r	   r   r,  rQ   z Union[_AnnotationScanType, bool])r   r+  rQ   r*  )r|   r   rQ   zTypeGuard[ArgsTypeProtocol])r|   r   r   z'Union[Tuple[Type[Any], ...], Type[Any]]rQ   r,  )r|   r   r  re   r   zOptional[str]rQ   r,  )r|   r*  rQ   re   )d
__future__r   r   collectionsr   collections.abcabcrs   rx   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r-   r.   r0   r2   r3   py38	frozensetr   r  r   r4   r   r   re   r+  r7   rD   rH   _LiteralStarr\   r}   rl   rf   r   r   r   r   rh   r   rg   r   r   r   rb   r   r   r   r   r   r   r   r  r	  r  r  r  r   r$  r&  r@   rA   rB   <module>r7     s   #   ) 	 
                     8< 106:4<86@888.@0Ten	T	*\6
en	T	*	;; v~~w78Mwi(M 
<< +DzH
V
 IsJ8NN 
.x .hrl (3Xc6k2 3 s| ;?!(,D	D#D D 	D 8D D &D DN&&&R/#//N// ,0$(!!! )	!
 "! 	!P ,0	
 )	
 	D.@.+G,"N  #( ! 	( 
 6 
 6 
 B 
 B 
 

&&&R 
(5	 

 
(6 

33(,3%3l$
.25
F
FB
F	
F 6:%2	5h 5 	/9'%. 9( :_E=GH- =" e8HS#X$6789 9rA   