U
    #iG                  
   @  sx  d dl mZ d dl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m.Z. ed(e	d)Z/ed*Z0ed+d,d-Z1ed.d,d/Z2ed0Z3ed1d,d-Z4ej5r@e6ej%e%gZ7n
e6e%gZ7ej8r`d d2l9m:Z: ne;dZ:ed3Z<e#Z=e$Z>eee	 e?eee.d4f Z@G d5d6 d6e(ZAG d7d8 d8e(e/ ZBG d9d: d:e(e0e4f ZCe%d; ZDdd<dd=d>d?d@dAdBdCdDd>dEdFdGZEd?d?dHdIdJZFdKdLdMdNdOdPZGdddQd@d@dRdSdTdUdVdWZHddXd@d@dRdTdYdZd[ZId@d@d@d\d]d^ZJdd_d>d6d@dAdBd>d`dadbZKdcdCdHdddeZLdTdfdgdhdiZMd?dCdHdjdkZNdcdldHdmdnZOd?dodHdpdqZPd?drdHdsdtZQdud>dHdvdwZRdd?dCdxdydzd{ZSed@d@dHd|d}ZTed>d>dHd~d}ZTed?d?dHdd}ZTd?d?dHdd}ZTdd?dHddZUd?d>dddZVdd>dCdCddddZWdTddHddZXdTdCdHddZYdTddHddZZdTddCdddZ[dddTd@ddCdddZ\d>d@dHddZ]G dd de(Z^ede^d)Z_G dd dee_ Z`ede^d,dZaG dd deea Zbedee
de	f  d)ZcG dd deec ZddS )    )annotationsN)Any)Callable)cast)Dict
ForwardRef)Generic)Iterable)Mapping)NewType)NoReturn)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )compat)	Annotated)Concatenate)dataclass_transform)Final)final)get_args)
get_origin)Literal)NotRequired)	ParamSpec)Protocol)SupportsIndex)	TypeAlias)	TypedDict)	TypeGuard)Self)TypeAliasType_T)bound_KT_KT_coT)	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 )ArgsTypeProcotolz_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=   ^/var/www/html/me.goteku.com/backend/venv/lib/python3.8/site-packages/sqlalchemy/util/typing.pyr4   [   s   
r4   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

    r5   r6   Type[_T]
__origin__Nr7   r=   r=   r=   r>   r?   e   s   
r?   c                   @  s*   e Zd ZddddZddddd	Zd
S )SupportsKeysAndGetItemzIterable[_KT])returnc                 C  s   d S Nr=   )selfr=   r=   r>   keysz       zSupportsKeysAndGetItem.keysr+   r1   )_SupportsKeysAndGetItem__krC   c                 C  s   d S rD   r=   )rE   rH   r=   r=   r>   __getitem__|   rG   z"SupportsKeysAndGetItem.__getitem__N)r8   r9   r:   rF   rI   r=   r=   r=   r>   rB   y   s   rB   *Fstr_cleanup_fninclude_generic_already_seenz	Type[Any]_AnnotationScanTypestrzMapping[str, Any]z#Optional[Callable[[str, str], str]]boolzOptional[Set[Any]])cls
annotationoriginating_modulelocals_rL   rM   rN   rC   c          	        s   |}t |r|j}t|tr:r*|}t|d}rt|rt|s dkr\t  | krh|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.

    rU   in_classNc              
   3  s$   | ]}t | d V  qdS )rK   Nde_stringify_annotation.0elemrN   rR   rM   rU   rT   rL   r=   r>   	<genexpr>   s   
z*de_stringify_annotation.<locals>.<genexpr>)
is_fwd_ref__forward_arg__
isinstancerP   eval_expression
is_generic
is_literalsetaddtupler6   _copy_generic_annotation_with)	rR   rS   rT   rU   rL   rM   rN   Zoriginal_annotationelementsr=   r]   r>   rY      s8    

   


rY   )type_rC   c              	   C  sb   t | r^t| ttttjtjtjtj	tj
fk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=   )ra   rP   r   rZ   r=   r=   r>   
<listcomp>   s   z,fixup_container_fwd_refs.<locals>.<listcomp>)rc   typing_get_origindictre   listcollections_abc
MutableSetMutableMappingMutableSequencer   Sequencerematchrepr__class_getitem__rg   typing_get_argsrj   r=   r=   r>   fixup_container_fwd_refs   s6    	 rz   zGenericProtocol[_T]r5   r@   )rS   ri   rC   c                 C  s"   t | dr| |S | j| S d S )N	copy_with)hasattrr{   rA   )rS   ri   r=   r=   r>   rh      s    

rh   rV   zOptional[Mapping[str, Any]]zOptional[Type[Any]]r   )
expressionmodule_namerU   rW   rC   c          	   
   C  s   zt j| j}W n8 tk
rH } ztd| d|  |W 5 d }~X Y nX zH|d k	rt|j}||j| || t	| ||}nt	| ||}W n2 t
k
r } ztd| |W 5 d }~X Y nX |S d S )NModule z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation )sysmodules__dict__KeyError	NameErrorrm   
setdefaultr8   updateeval	Exception)	r}   r~   rU   rW   base_globalskeZcls_namespacerS   errr=   r=   r>   rb      s,    

rb   rU   )namer~   rU   rC   c                C  s   d| krt | ||dS ztj| j}W n8 tk
r^ } ztd| d|  |W 5 d }~X Y nX z
||  W S  tk
r } zDztj|  W  W Y 0S  tk
r   Y nX td|  d| |W 5 d }~X Y nX d S )N.r   r   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rb   r   r   r   r   r   builtins)r   r~   rU   r   r   r=   r=   r>   eval_name_only"  s,    
r   )r   r~   rC   c                 C  s8   zt | |}W n tk
r&   |  Y S X t|d| S d S )Nr8   )r   r   getattr)r   r~   objr=   r=   r>   resolve_name_to_real_class_nameD  s
    
r   rL   )rR   rS   rT   rU   rL   rC   c                  s   t  fdd|jD  S )Nc              	     s   g | ]}t  |i d qS )r   rX   )r[   annorR   rT   rL   r=   r>   rk   V  s   z/de_stringify_union_elements.<locals>.<listcomp>)make_union_typer6   )rR   rS   rT   rU   rL   r=   r   r>   de_stringify_union_elementsM  s
    r   zOptional[_AnnotationScanType]c                 C  s   | d k	ot | tkS rD   )rl   r   ry   r=   r=   r>   	is_pep593c  s    r   zTypeGuard[Iterable[Any]])r   rC   c                 C  s   t | tjot | ttf S rD   )ra   ro   r
   rP   bytes)r   r=   r=   r>   is_non_string_iterableg  s     r   c                 C  s   t | tkS rD   )r   _LITERAL_TYPESry   r=   r=   r>   rd   m  s    rd   zTypeGuard[NewType]c                 C  s
   t | dS )N__supertype__r|   ry   r=   r=   r>   
is_newtypeq  s    r   zTypeGuard[GenericProtocol[Any]]c                 C  s   t | dot | dS )Nr6   rA   r   ry   r=   r=   r>   rc   y  s    rc   zTypeGuard[TypeAliasType]c                 C  s
   t | tS rD   )ra   r(   ry   r=   r=   r>   	is_pep695}  s    r   r   c                 C  s   | j }t|r|j }q|S rD   )r   r   )rj   Z
super_typer=   r=   r>   flatten_newtype  s    r   zTypeGuard[ForwardRef])rj   check_genericrC   c                 C  s6   t | trdS |r.t| r.tdd | jD S dS d S )NTc                 s  s   | ]}t |d V  qdS )TN)r_   )r[   argr=   r=   r>   r^     s     zis_fwd_ref.<locals>.<genexpr>F)ra   r   rc   anyr6   )rj   r   r=   r=   r>   r_     s
    
r_   c                 C  s   d S rD   r=   ry   r=   r=   r>   de_optionalize_union_types  s    r   c                 C  s   d S rD   r=   ry   r=   r=   r>   r     s    c                 C  s   d S rD   r=   ry   r=   r=   r>   r     s    c                 C  sF   t | rt| S t| r>t| j}|t |t t| S | S dS )zmGiven a type, filter out ``Union`` types that include ``NoneType``
    to not include the ``NoneType``.

    N)	r_   "de_optionalize_fwd_ref_union_typesis_optionalre   r6   discardr2   NoneFwdr   )rj   typr=   r=   r>   r     s    


r   c                 C  s   | j }td|}|rh|ddkr2t|dS |ddkrdtd|d}tdd |D  S | S td	|}d
|krtddd |D S | S )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   z,\s*c                 S  s   g | ]}|d krt |qS )r3   r   rZ   r=   r=   r>   rk     s      z6de_optionalize_fwd_ref_union_types.<locals>.<listcomp>z\s*\|\s*r3   |c                 s  s   | ]}|d kr|V  qdS )r3   Nr=   )r[   pr=   r=   r>   r^     s      z5de_optionalize_fwd_ref_union_types.<locals>.<genexpr>)r`   rt   ru   groupr   splitr   join)rj   rS   mmri   Zpipe_tokensr=   r=   r>   r     s    
r   )typesrC   c                  G  s   t tt| S )zMake a Union type.

    This is needed by :func:`.de_optionalize_union_types` which removes
    ``NoneType`` from a ``Union``.

    )r   r   r   rI   )r   r=   r=   r>   r     s    r   zTuple[Type[Any], ...])rj   include_uniondiscard_nonerC   c                 C  sF   t | r<t| j}|r |t |r2| ft| S t|S n| fS dS )zPReturn a type as a tuple of individual types, expanding for
    ``Union`` types.N)is_unionre   r6   r   r2   rg   )rj   r   r   r   r=   r=   r>   expand_unions  s    


r   zTypeGuard[ArgsTypeProcotol]c                 C  s   t | dddS )Nr   r   	UnionTypeis_origin_ofry   r=   r=   r>   r     s    r   c                 C  s   t | ott| kS rD   )r   r2   rx   ry   r=   r=   r>   is_optional_union  s    r   c                 C  s
   t | dS )Nr   r   ry   r=   r=   r>   r     s    r   z'Union[Tuple[Type[Any], ...], Type[Any]])rj   	class_objrC   c                 C  s(   t | }|dk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)rl   ra   type
issubclass)rj   r   originr=   r=   r>   is_origin_of_cls  s    r   )modulezOptional[str])rj   namesr   rC   c                G  s4   t | }|dkrdS t||ko2|dkp2|j|S )z\return True if the given type has an __origin__ with the given name
    and optional module.NF)rl   _get_type_namer9   
startswith)rj   r   r   r   r=   r=   r>   r     s    r   c                 C  s4   t jr| jS t| dd }|d kr,t| dd }|S d S )Nr8   _name)r   py310r8   r   )rj   Ztyp_namer=   r=   r>   r   "  s    r   c                   @  s@   e Zd ZddddddZdddddd	Zddd
ddZdS )DescriptorProtoobjectr   instanceownerrC   c                 C  s   d S rD   r=   rE   r   r   r=   r=   r>   __get__.  rG   zDescriptorProto.__get__r3   r   valuerC   c                 C  s   d S rD   r=   rE   r   r   r=   r=   r>   __set__0  rG   zDescriptorProto.__set__r   rC   c                 C  s   d S rD   r=   rE   r   r=   r=   r>   
__delete__2  rG   zDescriptorProto.__delete__N)r8   r9   r:   r   r   r   r=   r=   r=   r>   r   -  s   r   _DESCc                   @  sH   e Zd ZdZerDddddddZdddd	d
dZdddddZ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   c                 C  s   d S rD   r=   r   r=   r=   r>   r   E  rG   zDescriptorReference.__get__r3   r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   G  rG   zDescriptorReference.__set__r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   I  rG   zDescriptorReference.__delete__Nr8   r9   r:   r;   r   r   r   r   r=   r=   r=   r>   r   8  s
   
r   _DESC_co)r*   r-   c                   @  sH   e Zd ZdZerDddddddZdddd	d
dZdddddZdS )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

    r   r   r   r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   Y  rG   zRODescriptorReference.__get__r   r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   [  rG   zRODescriptorReference.__set__r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   ]  rG   z RODescriptorReference.__delete__Nr   r=   r=   r=   r>   r   O  s
   r   _FN.c                   @  sH   e Zd ZdZerDddddddZdddd	d
dZdddddZdS )CallableReferenceza descriptor that refers to a callable.

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


    r   r   r   r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   n  rG   zCallableReference.__get__r3   r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   p  rG   zCallableReference.__set__r   c                 C  s   d S rD   r=   r   r=   r=   r>   r   r  rG   zCallableReference.__delete__Nr   r=   r=   r=   r>   r   c  s
   r   )F)FF)e
__future__r   r   collections.abcabcro   rt   r   typingr   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   r1   Zpy38	frozensetr   r   r   r2   r   r   rx   rl   rP   rO   r4   r?   rB   Z_LiteralStarrY   rz   rh   rb   r   r   r   r   r   rd   r   rc   r   r   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r=   r=   r>   <module>	   s   

	 G)("    	