
    m[hW                    8   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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d d4l9m:Z: n e;d      Z:dod5Z<eee   e=eee/d6f   Z> G d7 d8e)      Z? G d9 d:e)e2         Z@ G d; d<e)e3e7f         ZAe&d=   ZBdd>dd?	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dpd@ZC	 	 	 	 dqdAZD	 	 	 	 	 	 drdBZEdddC	 	 	 	 	 	 	 	 	 dsdDZFddE	 	 	 	 	 	 	 dtdFZGdudGZHdvdHZIdwdIZJdxdJZKdydKZLdzdLZMd{dMZNd|dNZOd}dOZP	 	 d~	 	 	 	 	 	 	 ddPZQeddQ       ZReddR       ZRe	 	 	 	 dqdS       ZR	 	 	 	 dqdTZRe	 	 	 	 	 	 ddU       ZSe	 	 	 	 	 	 ddV       ZS	 	 	 	 	 	 ddWZSddXZTdxdYZUdxdZZVdd[ZW	 	 	 	 	 	 dd\ZXdd]	 	 	 	 	 	 	 dd^ZYdd_ZZ G d` dae)      Z[ edbe[,      Z\ G dc ddee\         Z] edee[df      Z^ G dg dhee^         Z_ edieedjef      ,      Z` G dk dlee`         Za G dm dn      Zb eb       ZcereZdecjL                  ZeyecZdecjL                  Zey)    )annotationsN)deque)Any)Callable)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)LiteralString_T)bound_KT_KT_co)	covariant
_KT_contra)contravariant_VT_VT_co)NoneTypec                D    t        | t              xr | j                  dk(  S )NNone)
isinstancer   __forward_arg__)typs    b/var/www/html/p-interativo-gestao-midia/env/lib/python3.12/site-packages/sqlalchemy/util/typing.pyis_fwd_noner<   M   s    c:&H3+>+>&+HH    z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__ r=   r;   r?   r?   V   s     .-r=   r?   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

    r@   rA   Type[_T]
__origin__NrB   rH   r=   r;   rJ   rJ   `   s     .-r=   rJ   c                      e Zd ZddZddZy)SupportsKeysAndGetItemc                     y NrH   )selfs    r;   keyszSupportsKeysAndGetItem.keysu   s    Sr=   c                     y rP   rH   )rQ   _SupportsKeysAndGetItem__ks     r;   __getitem__z"SupportsKeysAndGetItem.__getitem__w   s    sr=   N)returnzIterable[_KT])rT   r.   rV   r4   )rC   rD   rE   rR   rU   rH   r=   r;   rN   rN   t   s    (2r=   rN   *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)rX   N)de_stringify_annotation).0elemr[   clsrZ   r^   originating_modulerY   s     r;   	<genexpr>z*de_stringify_annotation.<locals>.<genexpr>   s<      
 , $"- /+  ,s   )
is_fwd_refr9   r8   streval_expression
is_generic
is_literalsetaddtuplerA   _copy_generic_annotation_with)	rd   
annotationre   r^   rY   rZ   r[   original_annotationelementss	   ` `````  r;   ra   ra   ~   s    . %*//
*c"'
4FGJ$*Gc


 	z":& EM&
 '&j) 
 
 #++
 
 -ZBBr=   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))rj   r   dictrl   listcollections_abc
MutableSetMutableMappingMutableSequencer   Sequencerematchrepr__class_getitem__rn   r   r8   rh   r   )type_rc   s     r;   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   rL   )rp   rr   s     r;   ro   ro      s2     z;'##H-- $$X..r=   r]   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	NameErrorrt   
setdefaultrC   updateeval	Exception)	
expressionmodule_namer^   r_   base_globalskecls_namespacerp   errs	            r;   ri   ri      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r^   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 )ri   r   r   r   r   r   builtins)namer   r^   r   r   s        r;   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)NrC   )r   getattrr   )r   r   objs      r;   resolve_name_to_real_class_namer   ?  s:    .T;/ sJ--  s    ))c                D    | d uxr t        |       t        j                  v S rP   )r   _type_tuplesr   r   s    r;   	is_pep593r   H  s"    LE!2l6L6L!LLr=   c                h    t        | t        j                        xr t        | t        t        f       S rP   )r8   rv   r
   rh   bytes)r   s    r;   is_non_string_iterabler   L  s1    c?334 Zc5\> : r=   c                8    t        |       t        j                  v S rP   )r   r   r    r   s    r;   rk   rk   R  s    e 4 444r=   c                    t        | d      S )N__supertype__r   r   s    r;   
is_newtyper   V  s    5/**r=   c                6    t        | d      xr t        | d      S )NrA   rL   r   r   s    r;   rj   rj   ^  s    5*%F'%*FFr=   c                v    t        |       rt        | j                        S t        | t        j
                        S rP   )rj   	is_pep695rL   r8   _type_instancesr)   r   s    r;   r   r   b  s0    
 %))**e_::;;r=   c                d    | j                   }t        |      r|j                   }t        |      r|S rP   )r   r   )r   
super_types     r;   flatten_newtyper   l  s0    $$J
Z
 --
 Z
 r=   c                D   t               fd |       }t        |t              rtt               }t        |      }|r[|j	                         }t        |t              r|j                  |       n&|j                  |t        u st        |      rdn|       |r[|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 rP   )rm   r   	__value__is_unionrA   )
inner_typevaluet_seenrecursive_values      r;   r   z&pep695_values.<locals>.recursive_value|  se     		*$$$L,1NN;Nq"N;;;s   AN)	rl   r8   ru   r   popleftextendrm   r5   r<   )r   restypesstackr   r   r   s        @@r;   pep695_valuesr   s  s     EE< %
 C#tc
A!T"Q		!x-;q>$qI  ur=   c                    rt        | t              ryt        | t        j                        ry|r)t	        |       rt        fd| j                  D              S y)NTc              3  :   K   | ]  }t        |d         yw)T)check_for_plain_stringN)rg   )rb   argr   s     r;   rf   zis_fwd_ref.<locals>.<genexpr>  s/      
 & T2H  &s   F)r8   rh   r   r   rj   anyrA   )r   check_genericr   s     `r;   rg   rg     sV    
 *UC"8	E?55	6	:e, 
 ~~	
 
 	
 r=   c                     y rP   rH   r   s    r;   de_optionalize_union_typesr     s    36r=   c                     y rP   rH   r   s    r;   r   r     s    ?Br=   c                     y rP   rH   r   s    r;   r   r          r=   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       |D ch c]  }|t        ust        |      r| }}t        | S | S c c}w )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)rg   #_de_optionalize_fwd_ref_union_typesr   includes_noner   py39rl   rA   r   r   appendrm   discardr5   r<   make_union_type)r   r:   stack_of_unionsu_typrc   r   s         r;   r   r     s     %25%@@	%]51;;enn%C $UGnO%C!'//1!NND~'..t4	 + " KKJ#Q(!2;q>q#J$$  Ks   C=!C=-C=c                     y rP   rH   r   return_has_nones     r;   r   r     s     r=   c                     y rP   rH   r   s     r;   r   r     r   r=   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*r7   Fz\s*\|\s*|c              3  ,   K   | ]  }|d k7  s	|  yw)r7   NrH   )rb   ps     r;   rf   z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>  s     B{!a6kA{s   
)r9   r{   r|   groupsplitr   r   joinstripclearlenr   r*   )r   r   rp   mmg1rr   currentignore_commacharrc   partspipe_tokenshas_noneanno_strs                 r;   r   r     s    &&J	$j	1B	XXa[s#B'*4G
288A;0GG7]bhhqk!&(%' HHQKDs{$)$)%*ts{ (8(>(>(@A NN4( ( 88GRXXa[92:M($dfnZ%(E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         |    S )zMake a Union type.r   )r   s    r;   r   r   $  s     <r=   c                   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        dfv xs t        |       S # t        $ r Y yw xY w)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rP   r   rb   r   s     r;   rf   z includes_none.<locals>.<genexpr>9  s     =_=#_   r   c              3  2   K   | ]  }t        |        y wrP   r   r   s     r;   rf   z includes_none.<locals>.<genexpr>=  s     B-A=#-Ar   NF)rg   r   r   r   r   r   r   r   r   r   r   r5   r<   	TypeErrorr   s    r;   r   r   *  s     %25$??=Xe_===Xe_Q/00B]5-ABBB%U00114((>K,>>  	s   'B> >	C
	C
c                    t        | t              xsB t        | d      xs4 | j                  dv xs$ t        |       j                  d   j                  dv S )NrL   )typingtyping_extensionsr   )r8   typer   rD   __mro__r   s    r;   	is_a_typer   I  s\    5$ 	P5,'	P>>	P ;q!,,0OO	r=   c                    t        | dd      S )Nr   	UnionType)is_origin_ofr   s    r;   r   r   R  s    w44r=   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   r8   r   
issubclass)r   	class_objorigins      r;   is_origin_of_clsr  V  s/     F~fd#E
69(EEr=   )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_namerD   
startswith)r   r  namesr  s       r;   r  r  c  sJ     F~&!U* $>&++66v>r=   c                v    t         j                  r| j                  S t        | dd       }|t        | dd       }|S )NrC   _name)r   py310rC   r   )r   typ_names     r;   r
  r
  r  s:    ||~~5*d3ugt4Hr=   c                  $    e Zd ZddZddZddZy)DescriptorProtoc                     y rP   rH   rQ   instanceowners      r;   __get__zDescriptorProto.__get__~  s    Cr=   c                     y rP   rH   rQ   r  r   s      r;   __set__zDescriptorProto.__set__  s    #r=   c                     y rP   rH   rQ   r  s     r;   
__delete__zDescriptorProto.__delete__  s    r=   N)r  objectr  r   rV   r   )r  r   r   r   rV   r7   r  r   rV   r7   )rC   rD   rE   r  r  r  rH   r=   r;   r  r  }  s    ?=4r=   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 rP   rH   r  s      r;   r  zDescriptorReference.__get__      #r=   c                     y rP   rH   r  s      r;   r  zDescriptorReference.__set__      r=   c                     y rP   rH   r  s     r;   r  zDescriptorReference.__delete__      Sr=   N)r  r  r  r   rV   r   )r  r   r   r   rV   r7   r  rC   rD   rE   rF   r   r  r  r  rH   r=   r;   r"  r"    s     EC8 r=   r"  _DESC_co)r-   r0   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 rP   rH   r  s      r;   r  zRODescriptorReference.__get__  s    Sr=   c                     y rP   rH   r  s      r;   r  zRODescriptorReference.__set__  r$  r=   c                     y rP   rH   r  s     r;   r  z RODescriptorReference.__delete__  s    r=   N)r  r  r  r   rV   r*  )r  r   r   r   rV   r   )r  r   rV   r   r)  rH   r=   r;   r,  r,    s     HE< r=   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 rP   rH   r  s      r;   r  zCallableReference.__get__  r&  r=   c                     y rP   rH   r  s      r;   r  zCallableReference.__set__  s    cr=   c                     y rP   rH   r  s     r;   r  zCallableReference.__delete__  r(  r=   N)r  r  r  r   rV   r0  )r  r   r   r0  rV   r7   r  r)  rH   r=   r;   r2  r2    s     CA8 r=   r2  c                      e Zd ZddZy)_TypingInstancesc                    t        t        t        |d       t        t        |d       fD ch c]  }|| c}      }|st	        |      || j
                  |<   |S c c}w rP   )rn   r   r   r   AttributeErrorr   )rQ   keyr   r   s       r;   __getattr__z_TypingInstances.__getattr__  sw     FC.-sD9A = 	
  %%"cs   AN)r:  rh   rV   ztuple[type, ...])rC   rD   rE   r;  rH   r=   r;   r7  r7    s    r=   r7  )r:   r   rV   bool)rd   	Type[Any]rp   _AnnotationScanTypere   rh   r^   zMapping[str, Any]rY   z#Optional[Callable[[str, str], str]]rZ   r<  r[   zOptional[Set[Any]]rV   r=  )r   r>  rV   r>  )rp   zGenericProtocol[_T]rr   r@   rV   rK   )
r   rh   r   rh   r^   Optional[Mapping[str, Any]]r_   zOptional[Type[Any]]rV   r   )r   rh   r   rh   r^   r?  rV   r   )r   rh   r   rh   rV   rh   )r   zOptional[Any]rV   r<  )r   r   rV   zTypeGuard[Iterable[Any]])r   r   rV   r<  )r   zOptional[_AnnotationScanType]rV   zTypeGuard[NewType])r   r>  rV   zTypeGuard[GenericProtocol[Any]])r   r>  rV   zTypeGuard[TypeAliasType])r   r   rV   r=  )r   r>  rV   zSet[Any])FF)r   r>  r   r<  r   r<  rV   zTypeGuard[ForwardRef])r   rh   rV   rh   )r   r=  rV   r=  )r   r   r   zLiteral[True]rV   r<  )r   r   r   zLiteral[False]rV   r>  )r   r   r   r<  rV   z Union[_AnnotationScanType, bool])r   r>  rV   r=  )r   r   rV   zTypeGuard[ArgsTypeProtocol])r   r   r  z'Union[Tuple[Type[Any], ...], Type[Any]]rV   r<  )r   r   r  rh   r  zOptional[str]rV   r<  )r   r=  rV   rh   )f
__future__r   r   collectionsr   collections.abcabcrv   r{   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r.   r/   r1   r3   r4   r  r   r5   r   r<   rh   r>  r?   rJ   rN   _LiteralStarra   r   ro   ri   r   r   r   r   rk   r   rj   r   r   r   rg   r   r   r   r   r   r   r  r  r
  r  r   r"  r*  r,  r0  r2  r7  r   r   LITERAL_TYPESrH   r=   r;   <module>rF     s   #   ) 	 
                     8< 106:4<86@888.@0@Ten	T	*\6
en	T	*	<< +DzHI 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.M5+G<"N  #( ! 	( 
 6 
 6 
 B 
 B 
 

%%%P 
(5	 

 
(6 

33(,3%3l>5
F
FB
F	
F 6:%2	5h 5 	/9'%. 9( :_E=GH- =" e8HS#X$6789 9$ $  !'O $$ #O$$r=   