o
    Šåg¸Q  ã                   @  s¸  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d,�Z2ed-ƒZ3ed.dd/�Z4ed0dd1�Z5ed2ƒZ6ed3dd/�Z7ej8�r-e9e
j'e'gƒZ:ne9e'gƒZ:ej;�r=d d4l<m=Z= ne>dƒZ=ed5ƒZ?eee e@eee0d6f ZAG d7d8„ d8e*ƒZBG d9d:„ d:e*e2 ƒZCG d;d<„ d<e*e3e7f ƒZDe'd= ZEdd>dd?œd¶dOdP„ZFd·dRdS„ZGd¸dXdY„ZHdddZœd¹dadb„ZIddcœdºdedf„ZJd»dgdh„ZKd¼djdk„ZLd½dndo„ZMd¾dpdq„ZNd¿dtdu„ZOdÀdwdx„ZPdÁdzd{„ZQdÂd}d~„ZRdÃd€d�„ZS	>	>dÄdÅd…d†„ZTedÆd‡dˆ„ƒZUedÇd‰dˆ„ƒZUed·dŠdˆ„ƒZUd·d‹dˆ„ZUedÈd�d�„ƒZVedÉd’d�„ƒZVdÊd”d�„ZVdËd–d—„ZWd¾d˜d™„ZXdÌd›dœ„ZYdÍdŸd „ZZdd¡œdÎd¥d¦„Z[dÏd§d¨„Z\G d©dª„ dªe*ƒZ]ed«e]d,�Z^G d¬d­„ d­ee^ ƒZ_ed®e]dd¯�Z`G d°d±„ d±ee` ƒZaed²eed³ef  d,�ZbG d´dµ„ dµeeb ƒZcdS )Ðé    )Ú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                   @  s   e Zd ZU dZded< dS )ÚArgsTypeProtocolz_protocol for types that have ``__args__``

    there's no public interface for this AFAIK

    úTuple[_AnnotationScanType, ...]Ú__args__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© r?   r?   úR/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/util/typing.pyr6   Z   s   
 r6   c                   @  s"   e Zd ZU dZded< ded< dS )ÚGenericProtocolzXprotocol for generic types.

    this since Python.typing _GenericAlias is private

    r7   r8   úType[_T]Ú
__origin__Nr9   r?   r?   r?   r@   rA   d   s   
 rA   c                   @  s    e Zd Zddd„Zddd	„Zd
S )ÚSupportsKeysAndGetItemÚreturnúIterable[_KT]c                 C  ó   d S ©Nr?   )Úselfr?   r?   r@   Úkeysy   ó    zSupportsKeysAndGetItem.keysÚ_SupportsKeysAndGetItem__kr-   r3   c                 C  rG   rH   r?   )rI   rL   r?   r?   r@   Ú__getitem__{   rK   z"SupportsKeysAndGetItem.__getitem__N)rE   rF   )rL   r-   rE   r3   )r:   r;   r<   rJ   rM   r?   r?   r?   r@   rD   x   s    
rD   Ú*F©Ústr_cleanup_fnÚinclude_genericÚ_already_seenÚclsú	Type[Any]Ú
annotationÚ_AnnotationScanTypeÚoriginating_moduleÚstrÚlocals_úMapping[str, Any]rP   ú#Optional[Callable[[str, str], str]]rQ   ÚboolrR   úOptional[Set[Any]]rE   c          	        s¢   |}t |ƒr	|j}t|tƒrˆrˆ|ˆƒ}t|ˆˆˆd�}ˆrOt|ƒrOt|ƒsOˆ du r.tƒ ‰ |ˆ v r4|S ˆ  |¡ t	‡ ‡‡‡‡‡fd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.

    ©rY   Úin_classNc              
   3  s&   � | ]}t ˆ|ˆˆˆˆˆ d �V  qdS )rO   N)Úde_stringify_annotation©Ú.0Úelem©rR   rS   rQ   rY   rW   rP   r?   r@   Ú	<genexpr>·   s   € 
÷ù
ÿz*de_stringify_annotation.<locals>.<genexpr>)Ú
is_fwd_refÚ__forward_arg__Ú
isinstancerX   Úeval_expressionÚ
is_genericÚ
is_literalÚsetÚaddÚtupler8   Ú_copy_generic_annotation_with)	rS   rU   rW   rY   rP   rQ   rR   Úoriginal_annotationÚelementsr?   rd   r@   r`   ‚   s2   

ÿÿþý

ö
r`   Útype_c              	   C  sb   t | ƒr/t| ƒttttjtjtjtj	tj
fv r/t dt| ƒ¡s/t| ƒ tdd„ t| ƒD ƒƒ¡S | S )zfCorrect dict['x', 'y'] into dict[ForwardRef('x'), ForwardRef('y')]
    and similar for list, set

    z3typing.(?:Dict|List|Set|.*Mapping|.*Sequence|.*Set)c                 S  s"   g | ]}t |tƒrt|ƒn|‘qS r?   )rh   rX   r	   ra   r?   r?   r@   Ú
<listcomp>é   s    ÿÿz,fixup_container_fwd_refs.<locals>.<listcomp>)rj   r   Údictrl   ÚlistÚcollections_abcÚ
MutableSetÚMutableMappingÚMutableSequencer   ÚSequenceÚreÚmatchÚreprÚ__class_getitem__rn   r   ©rr   r?   r?   r@   Úfixup_container_fwd_refsÉ   s2   	ÿøÿÿñþÿÿr€   úGenericProtocol[_T]rq   r7   rB   c                 C  s   t | dƒr
|  |¡S | j| S )NÚ	copy_with)Úhasattrr‚   rC   )rU   rq   r?   r?   r@   ro   ò   s   


ro   r^   Ú
expressionÚmodule_nameúOptional[Mapping[str, Any]]r_   úOptional[Type[Any]]r   c          	   
   C  s¸   zt j| j}W n ty } ztd|› d| › �ƒ|‚d }~ww z'|d ur?t|jƒ}| |j|¡ | |¡ t	| ||ƒ}W |S t	| ||ƒ}W |S  t
y[ } ztd| ›�ƒ|‚d }~ww )NúModule z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation )ÚsysÚmodulesÚ__dict__ÚKeyErrorÚ	NameErrorrt   Ú
setdefaultr:   ÚupdateÚevalÚ	Exception)	r„   r…   rY   r_   Úbase_globalsÚkeÚcls_namespacerU   Úerrr?   r?   r@   ri   ý   s:   ÿÿý€ÿ

úûÿþ€ÿri   ©rY   Únamec                C  s¼   d| v rt | ||d�S ztj| j}W n ty* } ztd|› d| › �ƒ|‚d }~ww z||  W S  ty] } z!ztj|  W W  Y d }~S  tyM   Y nw td| › d|› �ƒ|‚d }~ww )NÚ.r–   rˆ   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )ri   r‰   rŠ   r‹   rŒ   r�   Úbuiltins)r—   r…   rY   r’   r“   r?   r?   r@   Úeval_name_only!  s:   ÿÿý€ÿ	
ÿÿþ€ùrš   c                 C  s2   zt | |ƒ}W n ty   |  Y S w t|d| ƒS )Nr:   )rš   r�   Úgetattr)r—   r…   Úobjr?   r?   r@   Úresolve_name_to_real_class_nameC  s   ÿr�   úOptional[Any]c                 C  s   | d uo	t | ƒtu S rH   )r   r   r   r?   r?   r@   Ú	is_pep593L  ó   rŸ   rœ   úTypeGuard[Iterable[Any]]c                 C  s   t | tjƒot | ttfƒ S rH   )rh   rv   r   rX   Úbytes)rœ   r?   r?   r@   Úis_non_string_iterableP  s   ÿr£   c                 C  s   t | ƒtv S rH   )r   ÚLITERAL_TYPESr   r?   r?   r@   rk   V  ó   rk   úOptional[_AnnotationScanType]úTypeGuard[NewType]c                 C  s
   t | dƒS )NÚ__supertype__©rƒ   r   r?   r?   r@   Ú
is_newtypeZ  ó   
rª   úTypeGuard[GenericProtocol[Any]]c                 C  s   t | dƒo	t | dƒS )Nr8   rC   r©   r   r?   r?   r@   rj   b  r    rj   úTypeGuard[TypeAliasType]c                 C  s
   t | tƒS rH   )rh   r)   r   r?   r?   r@   Ú	is_pep695f  r«   r®   r   c                 C  s    | j }t|ƒr|j }t|ƒs|S rH   )r¨   rª   )rr   Ú
super_typer?   r?   r@   Úflatten_newtypej  s
   ÿr°   úSet[Any]c                   s~   t ƒ ‰ ‡ ‡fdd„‰ˆ| ƒ}t|tƒr<t ƒ }t|ƒ}|r:| ¡ }t|tƒr+| |¡ n| |tthv r5dn|¡ |s|S |hS )zçExtracts 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                   sH   | ˆ v r| S ˆ   | ¡ t| ƒs| S | j}t|ƒs|S ‡fdd„|jD ƒS )Nc                   s   g | ]}ˆ |ƒ‘qS r?   r?   ©rb   Út)Úrecursive_valuer?   r@   rs   …  s    z:pep695_values.<locals>.recursive_value.<locals>.<listcomp>)rm   r®   Ú	__value__Úis_unionr8   )rr   Úvalue©Ú_seenr´   r?   r@   r´   z  s   
z&pep695_values.<locals>.recursive_valueN)	rl   rh   ru   r   ÚpopleftÚextendrm   r4   ÚNoneFwd)rr   ÚresÚtypesÚstackr³   r?   r¸   r@   Úpep695_valuesq  s   

ûrÀ   Úcheck_genericÚcheck_for_plain_stringúTypeGuard[ForwardRef]c                   sH   ˆ r	t | tƒr	dS t | tƒrdS |r"t| ƒr"t‡ fdd„| jD ƒƒS dS )NTc                 3  s   � | ]
}t |d ˆ d�V  qdS )T©rÂ   N)rf   )rb   ÚargrÄ   r?   r@   re      s   € ýÿ
ÿzis_fwd_ref.<locals>.<genexpr>F)rh   rX   r	   rj   Úanyr8   )rr   rÁ   rÂ   r?   rÄ   r@   rf   –  s   
ürf   c                 C  rG   rH   r?   r   r?   r?   r@   Úde_optionalize_union_typesª  ó   rÇ   c                 C  rG   rH   r?   r   r?   r?   r@   rÇ   ®  rÈ   c                 C  rG   rH   r?   r   r?   r?   r@   rÇ   ²  ó   c                 C  s¨   t | ƒr	t| dƒS t| ƒrRt| ƒrRtjrt| jƒ}n*t| gƒ}tƒ }|r?| 	¡ }|jD ]}t|ƒr7| 
|¡ q+| |¡ q+|s$| d¡ | t¡ | t¡ t|Ž S | S )zÜGiven 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)rf   Ú#_de_optionalize_fwd_ref_union_typesr¶   Úincludes_noner   Úpy39rl   r8   r   rº   Úappendrm   Údiscardr4   r¼   Úmake_union_type)rr   ÚtypÚstack_of_unionsÚu_typrc   r?   r?   r@   rÇ   ¸  s&   


ú


r	   Úreturn_has_noneúLiteral[True]c                 C  rG   rH   r?   ©rr   rÓ   r?   r?   r@   rÊ   á  rÉ   rÊ   úLiteral[False]c                 C  rG   rH   r?   rÕ   r?   r?   r@   rÊ   ç  rÉ   ú Union[_AnnotationScanType, bool]c                 C  sp  | j }t d|¡}|r”| d¡ d¡d }|dkr$|rdS t| d¡ƒS |dkrŽd	| d¡v rlg }g }d
}| d¡D ]0}|d	krE|d7 }n |dkrN|d8 }n|d
kre|dkre| d |¡ ¡ ¡ | 	¡  q:| |¡ q:n	t d| d¡¡}dd„ |D ƒ}	|r†t
|ƒt
|	ƒkS |	rŒt|	Ž S tS |r’dS | S t d|¡}
d|
v }|r¢|S |r¶d dd„ |
D ƒ¡}|r´t|ƒS tS | S )zÁreturn 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*c                 S  s   g | ]
}|d krt |ƒ‘qS )r5   r   ra   r?   r?   r@   rs     s    z7_de_optionalize_fwd_ref_union_types.<locals>.<listcomp>Fz\s*\|\s*r5   ú|c                 s  s   � | ]	}|d kr|V  qdS )r5   Nr?   )rb   Úpr?   r?   r@   re     s   € z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>)rg   r{   r|   ÚgroupÚsplitr	   rÍ   ÚjoinÚstripÚclearÚlenrÏ   r*   )rr   rÓ   rU   ÚmmÚg1rq   ÚcurrentÚignore_commaÚcharÚpartsÚpipe_tokensÚhas_noneÚanno_strr?   r?   r@   rÊ   í  sH   


÷r¾   c                  G  s
   t  | ¡S )zMake a Union type.)r   rM   )r¾   r?   r?   r@   rÏ   #  s   
rÏ   c                 C  s†   t | ƒr	t| dƒS t| ƒrtdd„ t| ƒD ƒƒS t| ƒr$tt| ƒd ƒS t| ƒr3td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                 s  ó   � | ]}t |ƒV  qd S rH   ©rË   r²   r?   r?   r@   re   7  ó   € z includes_none.<locals>.<genexpr>r   c                 s  rï   rH   rð   r²   r?   r?   r@   re   ;  rñ   N)rf   rÊ   r¶   rÆ   r   rŸ   rË   r®   rÀ   rª   r¨   r¼   r4   r   r?   r?   r@   rË   (  s   

rË   úTypeGuard[ArgsTypeProtocol]c                 C  s   t | ddƒS )Nr   Ú	UnionType)Úis_origin_ofr   r?   r?   r@   r¶   A  r¥   r¶   Ú	class_objú'Union[Tuple[Type[Any], ...], Type[Any]]c                 C  s(   t | ƒ}|du r
dS t|tƒot||ƒS )z[return True if the given type has an __origin__ that shares a base
    with the given classNF)r   rh   ÚtypeÚ
issubclass)rr   rõ   Úoriginr?   r?   r@   Úis_origin_of_clsE  s   rú   )ÚmoduleÚnamesrû   úOptional[str]c                G  s4   t | ƒ}|du r
dS t|ƒ|v o|du p|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)rr   rû   rü   rù   r?   r?   r@   rô   R  s   ÿrô   c                 C  s0   t jr| jS t| dd ƒ}|d u rt| dd ƒ}|S )Nr:   Ú_name)r   Úpy310r:   r›   )rr   Útyp_namer?   r?   r@   rþ   a  s   rþ   c                   @  s*   e Zd Zddd„Zdd
d„Zddd„ZdS )ÚDescriptorProtoÚinstanceÚobjectÚownerr   rE   c                 C  rG   rH   r?   ©rI   r  r  r?   r?   r@   Ú__get__m  rK   zDescriptorProto.__get__r·   r5   c                 C  rG   rH   r?   ©rI   r  r·   r?   r?   r@   Ú__set__o  rK   zDescriptorProto.__set__c                 C  rG   rH   r?   ©rI   r  r?   r?   r@   Ú
__delete__q  rK   zDescriptorProto.__delete__N)r  r  r  r   rE   r   )r  r   r·   r   rE   r5   ©r  r   rE   r5   )r:   r;   r<   r  r
  r  r?   r?   r?   r@   r  l  s    

r  Ú_DESCc                   @  ó6   e Zd ZdZerddd	„Zddd„Zddd„ZdS dS )Ú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

    r  r  r  r   rE   r  c                 C  rG   rH   r?   r  r?   r?   r@   r  „  rK   zDescriptorReference.__get__r·   r5   c                 C  rG   rH   r?   r	  r?   r?   r@   r
  †  rK   zDescriptorReference.__set__c                 C  rG   rH   r?   r  r?   r?   r@   r  ˆ  rK   zDescriptorReference.__delete__N)r  r  r  r   rE   r  )r  r   r·   r  rE   r5   r  ©r:   r;   r<   r=   r   r  r
  r  r?   r?   r?   r@   r  w  s    


úr  Ú_DESC_co)r,   r/   c                   @  r  )ÚRODescriptorReferencez½a 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

    r  r  r  r   rE   r  c                 C  rG   rH   r?   r  r?   r?   r@   r  ˜  rK   zRODescriptorReference.__get__r·   r   c                 C  rG   rH   r?   r	  r?   r?   r@   r
  š  rK   zRODescriptorReference.__set__c                 C  rG   rH   r?   r  r?   r?   r@   r  œ  rK   z RODescriptorReference.__delete__N)r  r  r  r   rE   r  )r  r   r·   r   rE   r   )r  r   rE   r   r  r?   r?   r?   r@   r  Ž  s    

úr  Ú_FN.c                   @  r  )ÚCallableReferencez�a descriptor that refers to a callable.

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


    r  r  r  r   rE   r  c                 C  rG   rH   r?   r  r?   r?   r@   r  ­  rK   zCallableReference.__get__r·   r5   c                 C  rG   rH   r?   r	  r?   r?   r@   r
  ¯  rK   zCallableReference.__set__c                 C  rG   rH   r?   r  r?   r?   r@   r  ±  rK   zCallableReference.__delete__N)r  r  r  r   rE   r  )r  r   r·   r  rE   r5   r  r  r?   r?   r?   r@   r  ¢  s    

úr  )rS   rT   rU   rV   rW   rX   rY   rZ   rP   r[   rQ   r\   rR   r]   rE   rT   )rr   rV   rE   rV   )rU   r�   rq   r7   rE   rB   )
r„   rX   r…   rX   rY   r†   r_   r‡   rE   r   )r—   rX   r…   rX   rY   r†   rE   r   )r—   rX   r…   rX   rE   rX   )rr   rž   rE   r\   )rœ   r   rE   r¡   )rr   r   rE   r\   )rr   r¦   rE   r§   )rr   rV   rE   r¬   )rr   rV   rE   r­   )rr   r   rE   rT   )rr   rV   rE   r±   )FF)rr   rV   rÁ   r\   rÂ   r\   rE   rÃ   )rr   rX   rE   rX   )rr   rT   rE   rT   )rr   r	   rÓ   rÔ   rE   r\   )rr   r	   rÓ   rÖ   rE   rV   )rr   r	   rÓ   r\   rE   r×   )r¾   rV   rE   rT   )rr   r   rE   rò   )rr   r   rõ   rö   rE   r\   )rr   r   rü   rX   rû   rý   rE   r\   )rr   rT   rE   rX   )dÚ
__future__r   r™   Úcollectionsr   Úcollections.abcÚabcrv   r{   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¼   rX   rV   r6   rA   rD   Ú_LiteralStarr`   r€   ro   ri   rš   r�   rŸ   r£   rk   rª   rj   r®   r°   rÀ   rf   rÇ   rÊ   rÏ   rË   r¶   rú   rô   rþ   r  r  r  r  r  r  r  r?   r?   r?   r@   Ú<module>   sä   
ÿ
	ø
G
)û(ü
"
	






'ý
)

6


ÿ
