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rd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    [/var/www/html/ecg_monitoring/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 )
zDeep 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

/