o
    ŠågEG  ã                   @  s  U d 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mZ ddlmZ ddlmZ er™ddlmZ ddlmZ e	e ef Z!ej"Z#de$d< G dd „ d eƒZ%G d!d"„ d"e%ƒZ&G d#d$„ d$e&ƒZ'G d%d&„ d&e%ƒZ(i Z)d'e$d(< ed)d d*�Z*dQd/d0„Z+	dRd1d1dd2œdSd;d<„Z,e	dRdTd@dA„ƒZ-e	dRdUdBdA„ƒZ-	dRdVdDdA„Z-dWdEdF„Z.dXdKdL„Z/dYdOdP„Z0dS )Za*  The :class:`.Annotated` class and related routines; creates hash-equivalent
copies of SQL constructs which contain context-specific markers and
associations.

Note that the :class:`.Annotated` concept as implemented in this module is not
related in any way to the pep-593 concept of "Annotated".


é    )ÚannotationsN)ÚAny)ÚCallable)Úcast)ÚDict)Ú	FrozenSet)ÚMapping)ÚOptional)Úoverload)ÚSequence)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚTypeVaré   )Ú	operators)ÚHasCacheKey©Úanon_map)ÚExternallyTraversible)ÚInternalTraversalé   )Úutil)ÚLiteral)ÚSelf)Ú_EntityNamespace)Ú_TraverseInternalsTypeúutil.immutabledict[str, Any]ÚEMPTY_ANNOTATIONSc                   @  sŠ   e Zd ZU dZeZded< ded< ded< ddd„Ze		d d!dd„ƒZ	e		d d"dd„ƒZ			d#d$dd„Z	e
jd%dd„ƒZd&dd„ZdS )'ÚSupportsAnnotations© r   Ú_annotationsz*util.generic_fn_descriptor[FrozenSet[Any]]Ú	proxy_setÚboolÚ_is_immutableÚvaluesÚ_AnnotationDictÚreturnr   c                 C  ó   t ƒ ‚©N©ÚNotImplementedError©Úselfr%   r    r    úU/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/sql/annotation.pyÚ	_annotate>   ó   zSupportsAnnotations._annotate.úLiteral[None]Úclonec                 C  ó   d S r)   r    ©r-   r%   r2   r    r    r.   Ú_deannotateA   ó   zSupportsAnnotations._deannotateúSequence[str]c                 C  r3   r)   r    r4   r    r    r.   r5   H   r6   NFúOptional[Sequence[str]]c                 C  r(   r)   r*   r4   r    r    r.   r5   O   s   úTuple[Any, ...]c                 C  s   t ƒ }|  |¡S r)   )r   Ú_gen_annotations_cache_key)r-   Ú	anon_map_r    r    r.   Ú_annotations_cache_keyV   s   
z*SupportsAnnotations._annotations_cache_keyr   c                   s.   dt ‡ fdd„‡fdd„tˆjƒD ƒD ƒƒfS )Nr!   c                 3  s2   � | ]\}}|t |tƒr| ˆ g ¡n|fV  qd S r)   )Ú
isinstancer   Ú_gen_cache_key©Ú.0ÚkeyÚvaluer   r    r.   Ú	<genexpr>a   s   € 	ùÿû
ÿzASupportsAnnotations._gen_annotations_cache_key.<locals>.<genexpr>c                   s   g | ]	}|ˆ j | f‘qS r    )r!   )r@   rA   ©r-   r    r.   Ú
<listcomp>j   s    ÿÿzBSupportsAnnotations._gen_annotations_cache_key.<locals>.<listcomp>)ÚtupleÚsortedr!   )r-   r   r    )r   r-   r.   r:   \   s   
	þ÷þz.SupportsAnnotations._gen_annotations_cache_key©r%   r&   r'   r   ©..©r%   r1   r2   r#   r'   r   ©r%   r7   r2   r#   r'   r   ©NF©r%   r8   r2   r#   r'   r   )r'   r9   )r   r   r'   r9   )Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r   r!   Ú__annotations__r/   r
   r5   r   Úmemoized_propertyr<   r:   r    r    r    r.   r   5   s(   
 
ýýýr   c                   @  sz   e Zd ZU dZded< erejddd„ƒZddd„Z	ddd„Z
e		dddd„ƒZe		dd dd„ƒZ		d!d"dd„ZdS )#ÚSupportsWrappingAnnotationsr    z*Callable[..., SupportsWrappingAnnotations]Ú_constructorr'   r   c                 C  r3   r)   r    rD   r    r    r.   Úentity_namespacey   s   z,SupportsWrappingAnnotations.entity_namespacer%   r&   r   c                 C  ó   t  | |¡S )úgreturn a copy of this ClauseElement with annotations
        updated by the given dictionary.

        ©Ú	AnnotatedÚ_as_annotated_instancer,   r    r    r.   r/   |   ó   z%SupportsWrappingAnnotations._annotatec                 C  rW   )úhreturn a copy of this ClauseElement with annotations
        replaced by the given dictionary.

        rY   r,   r    r    r.   Ú_with_annotationsƒ   r\   z-SupportsWrappingAnnotations._with_annotations.r1   r2   r#   c                 C  r3   r)   r    r4   r    r    r.   r5   Š   r6   z'SupportsWrappingAnnotations._deannotater7   r   c                 C  r3   r)   r    r4   r    r    r.   r5   ‘   r6   NFr8   c                 C  s   |r|   ¡ }|S | S )ú¼return a copy of this :class:`_expression.ClauseElement`
        with annotations
        removed.

        :param values: optional tuple of individual values
         to remove.

        )Ú_clone)r-   r%   r2   Úsr    r    r.   r5   ˜   s   ©r'   r   rH   rI   rJ   rK   rL   rM   )rN   rO   rP   rQ   rR   r   r   Úro_non_memoized_propertyrV   r/   r^   r
   r5   r    r    r    r.   rT   r   s&   
 

ýýýrT   c                   @  sx   e Zd ZU ejs
dZdejfgZde	d< dd	d
„Z
ddd„Ze		dddd„ƒZe		dddd„ƒZ		dddd„ZdS ) ÚSupportsCloneAnnotationsr    r!   r   Ú%_clone_annotations_traverse_internalsr%   r&   r'   r   c                 C  s6   |   ¡ }|j |¡|_|j dd¡ |j dd¡ |S )rX   r<   NÚ_generate_cache_key)r`   r!   ÚunionÚ__dict__Úpop©r-   r%   Únewr    r    r.   r/   »   s
   z"SupportsCloneAnnotations._annotatec                 C  s4   |   ¡ }t |¡|_|j dd¡ |j dd¡ |S )r]   r<   Nrf   )r`   r   Úimmutabledictr!   rh   ri   rj   r    r    r.   r^   Æ   s
   z*SupportsCloneAnnotations._with_annotations.r1   r2   r#   c                 C  r3   r)   r    r4   r    r    r.   r5   Ñ   r6   z$SupportsCloneAnnotations._deannotater7   r   c                 C  r3   r)   r    r4   r    r    r.   r5   Ø   r6   NFr8   c                 C  s2   |s| j r|  ¡ }t ¡ |_ |j dd¡ |S | S )r_   r<   N)r!   r`   r   rl   rh   ri   )r-   r%   r2   rk   r    r    r.   r5   ß   s   

rH   rI   rJ   rK   rL   rM   )rN   rO   rP   Útypingr   rQ   r   Údp_annotations_keyre   rR   r/   r^   r
   r5   r    r    r    r.   rd   ¬   s$   
 ÿ

ýýýrd   c                   @  sð   e Zd ZU dZdZed<dd	„ƒZd
ed< ded< ded< d=dd„Zd>dd„Z	d?dd„Z
d?dd„Ze		d@dAd d!„ƒZe		d@dBd#d!„ƒZ	$	%dCdDd(d!„ZejsZdEd+d,„Zed-d.„ ƒZdFd/d0„ZdGd2d3„ZdHd4d5„ZdId7d8„ZejdJd:d;„ƒZd$S )KrZ   aJ  clones a SupportsAnnotations and applies an 'annotations' dictionary.

    Unlike regular clones, this clone also mimics __hash__() and
    __eq__() of the original element so that it takes its place
    in hashed collections.

    A reference to the original element is maintained, for the important
    reason of keeping its hash value current.  When GC'ed, the
    hash value may be reused, causing conflicts.

    .. note::  The rationale for Annotated producing a brand new class,
       rather than placing the functionality directly within ClauseElement,
       is **performance**.  The __hash__() method is absent on plain
       ClauseElement which leads to significantly reduced function call
       overhead, as the use of sets and dictionaries against ClauseElement
       objects is prevalent, but most are not "annotated".

    FÚelementrT   r%   r&   r'   c                 C  s8   zt |j } W n ty   t|j| ƒ} Y nw | ||ƒS r)   )Úannotated_classesÚ	__class__ÚKeyErrorÚ_new_annotation_type)Úclsro   r%   r    r    r.   r[     s   ÿ
z Annotated._as_annotated_instancer   r!   Ú_Annotated__elementÚintÚ_hashrt   ú
Type[Self]Úargsr   r   c                 G  s
   t  | ¡S r)   )ÚobjectÚ__new__)rt   ry   r    r    r.   r{     s   
zAnnotated.__new__c                 C  sH   |j  ¡ | _ | j  dd ¡ | j  dd ¡ || _t |¡| _t|ƒ| _d S ©Nr<   rf   )	rh   Úcopyri   ru   r   rl   r!   Úhashrw   )r-   ro   r%   r    r    r.   Ú__init__  s   zAnnotated.__init__c                 C  s   | j  |¡}|  |¡}|S r)   )r!   rg   r^   )r-   r%   Ú_valuesrk   r    r    r.   r/   (  s   
zAnnotated._annotatec                 C  sF   | j  | j ¡}| j ¡ |_|j dd ¡ |j dd ¡ t |¡|_|S r|   )rq   r{   rh   r}   ri   r   rl   r!   r4   r    r    r.   r^   -  s   zAnnotated._with_annotations.r1   r2   r#   c                 C  r3   r)   r    r4   r    r    r.   r5   5  r6   zAnnotated._deannotater7   c                 C  r3   r)   r    r4   r    r    r.   r5   <  r6   NTr8   r   c                   s2   ˆ d u r| j S |  t ‡ fdd„| j ¡ D ƒ¡¡S )Nc                   s   i | ]\}}|ˆ vr||“qS r    r    r?   ©r%   r    r.   Ú
<dictcomp>M  s
    þz)Annotated._deannotate.<locals>.<dictcomp>)ru   r^   r   rl   r!   Úitemsr4   r    r�   r.   r5   C  s   
þÿÿÚvisitorÚkwc                 K  s   | j jj| |fi |¤ŽS r)   )ru   rq   Ú_compiler_dispatch)r-   r„   r…   r    r    r.   r†   W  s
   ÿÿzAnnotated._compiler_dispatchc                 C  s   | j jS r)   )ru   rU   rD   r    r    r.   rU   \  s   zAnnotated._constructorc                 K  s<   | j jdi |¤Ž}|| j u r| S |j | j¡ |  || j¡S )Nr    )ru   r`   rh   Úupdaterq   r!   )r-   r…   r2   r    r    r.   r`   `  s
   
zAnnotated._cloneú'Tuple[Type[Annotated], Tuple[Any, ...]]c                 C  s   | j | j| jffS r)   )rq   ru   r!   rD   r    r    r.   Ú
__reduce__k  s   zAnnotated.__reduce__c                 C  s   | j S r)   )rw   rD   r    r    r.   Ú__hash__n  r0   zAnnotated.__hash__Úotherc                 C  s&   | j r| jj | |¡S t|ƒt| ƒkS r)   )Ú_is_column_operatorsru   rq   Ú__eq__r~   )r-   r‹   r    r    r.   r�   q  s   zAnnotated.__eq__r   c                 C  s$   d| j v rtt| j d ƒjS | jjS )NrV   )r!   r   rT   rV   ru   rD   r    r    r.   rV   w  s   
þýzAnnotated.entity_namespace)ro   rT   r%   r&   r'   rZ   )rt   rx   ry   r   r'   r   )ro   rT   r%   r&   rH   rI   rJ   )r%   r7   r2   r#   r'   rZ   )NTrM   )r„   r   r…   r   r'   r   )r…   r   r'   r   )r'   rˆ   )r'   rv   )r‹   r   r'   r#   rb   )rN   rO   rP   Ú__doc__rŒ   Úclassmethodr[   rR   r{   r   r/   r^   r
   r5   rm   r   r†   ÚpropertyrU   r`   r‰   rŠ   r�   r   rc   rV   r    r    r    r.   rZ   ÷   sB   
 	




ýýý





rZ   z8Dict[Type[SupportsWrappingAnnotations], Type[Annotated]]rp   Ú_SA)ÚboundÚto_annotater   r&   r'   c                 C  s(   z| j }W ||ƒS  ty   |  Y S w r)   )r/   ÚAttributeError)r“   r   r/   r    r    r.   Ú_safe_annotateŽ  s   úür•   F)Údetect_subquery_colsÚind_cols_on_fromclauseÚannotate_callablero   Úexcludeú'Optional[Sequence[SupportsAnnotations]]r–   r#   r—   r˜   úOOptional[Callable[[SupportsAnnotations, _AnnotationDict], SupportsAnnotations]]c                  s<   i ‰d	‡ ‡‡‡‡‡‡fdd„‰| durt tˆ| ƒƒ} d‰| S )
z¹Deep copy the given ClauseElement, annotating each element
    with the given annotations dictionary.

    Elements within the exclude collection will be cloned but not annotated.

    Úelemr   r…   r   r'   c                   s¸   ˆ|d< t | ƒ}|ˆv rˆ| S ˆr(t| dƒr(| j ˆ¡r(| jddˆi|¤Ž}n'ˆ| jkrMˆr=| jr=| jddˆi|¤Ž}n| }ˆ rGˆ |ˆƒ}nt|ˆƒ}n| }|jˆˆd� |ˆ|< |S )Nr–   r"   r2   )r2   r—   r    )	ÚidÚhasattrr"   Úintersectionr`   r!   r$   r•   Ú_copy_internals)rœ   r…   Úid_Únewelemr“   ©r˜   r   r2   Ú
cloned_idsr–   r™   r—   r    r.   r2   ±  s0   
ÿþ
ý

ÿz_deep_annotate.<locals>.cloneN©rœ   r   r…   r   r'   r   ©r   r‘   )ro   r   r™   r–   r—   r˜   r    r£   r.   Ú_deep_annotateš  s   )r§   r1   r%   r8   c                 C  r3   r)   r    ©ro   r%   r    r    r.   Ú_deep_deannotateà  ó   r©   c                 C  r3   r)   r    r¨   r    r    r.   r©   æ  rª   úOptional[_SA]c                   s4   i ‰d	‡ ‡‡fdd„‰ | durt tˆ | ƒƒ} d‰ | S )
z2Deep copy the given element, removing annotations.rœ   r   r…   r   r'   c                   sH   ˆrt | ƒ}n| }|ˆvr | jˆdd�}|jˆ d� |ˆ|< |S ˆ| S )NT)r%   r2   )r2   )r�   r5   r    )rœ   r…   rA   r¢   ©r2   Úclonedr%   r    r.   r2   ó  s   
z_deep_deannotate.<locals>.cloneNr¥   r¦   r¨   r    r¬   r.   r©   ì  s   c                 C  s   |   |¡} |  ¡  | S )a  Annotate the given ClauseElement and copy its internals so that
    internal objects refer to the new annotated object.

    Basically used to apply a "don't traverse" annotation to a
    selectable, without digging throughout the whole
    structure wasting time.
    )r/   r    )ro   r   r    r    r.   Ú_shallow_annotate  s   
r®   rt   ú!Type[SupportsWrappingAnnotations]Úbase_clsúType[Annotated]c                 C  sþ   t | tƒr| S | tv rt|  S | jD ]}|tv rt| } nqttt td| j || fi ƒƒ t| < }|tƒ d| j < d| j	v rMt
| jƒdtjfg |_n| j	 dd¡r`t
| jƒdtjfg |_| j	 dd¡rkd|_nd| j	v rv| j	d |_t | tjƒ|_|S )z[Generates a new class that subclasses Annotated and proxies a given
    element type.

    zAnnotated%sÚ_traverse_internalsr!   Úinherit_cacheFT)Ú
issubclassrZ   rp   Ú__mro__r   r   ÚtyperN   Úglobalsrh   Úlistr²   r   rn   Úgetr³   r   ÚColumnOperatorsrŒ   )rt   r°   Úsuper_Úanno_clsr    r    r.   rs     s8   

þþ

ÿÿ
rs   Útarget_hierarchyÚNonec                 C  s   t  | ¡D ]}t||ƒ qd S r)   )r   Úwalk_subclassesrs   )r½   r°   rt   r    r    r.   Ú_prepare_annotationsD  s   ÿrÀ   )r“   r‘   r   r&   r'   r‘   r)   )ro   r‘   r   r&   r™   rš   r–   r#   r—   r#   r˜   r›   r'   r‘   )ro   r1   r%   r8   r'   r1   )ro   r‘   r%   r8   r'   r‘   )ro   r«   r%   r8   r'   r«   )ro   r‘   r   r&   r'   r‘   )rt   r¯   r°   r±   r'   r±   )r½   r¯   r°   r±   r'   r¾   )1rŽ   Ú
__future__r   rm   r   r   r   r   r   r   r	   r
   r   r   r   r   r   Ú r   Ú	cache_keyr   Úvisitorsr   r   r   r   Úutil.typingr   r   Úbaser   r   Ústrr&   Ú
EMPTY_DICTr   rR   r   rT   rd   rZ   rp   r‘   r•   r§   r©   r®   rs   rÀ   r    r    r    r.   Ú<module>   sn   
=:K 
ÿ
ý÷Fÿÿÿ

/