
    gEG                       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jD                  Z#de$d<    G d d e      Z% G d! d"e%      Z& G d# d$e&      Z' G d% d&e%      Z(i Z)d'e$d(<    ed)d *      Z*d5d+Z+	 d6d,d,dd-	 	 	 	 	 	 	 	 	 	 	 	 	 d7d.Z,e	 d6	 	 	 	 	 d8d/       Z-e	 d6	 	 	 	 	 d9d0       Z-	 d6	 	 	 	 	 d:d1Z-d;d2Z.	 	 	 	 	 	 d<d3Z/	 	 	 	 	 	 d=d4Z0y)>a*  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                      e Zd ZU dZeZded<   ded<   ded<   ddZe	 	 d	 	 	 	 	 dd	       Z	e	 	 d	 	 	 	 	 dd
       Z		 	 d	 	 	 	 	 ddZ	e
j                  dd       Z	 	 	 	 ddZy)SupportsAnnotations r   _annotationsz*util.generic_fn_descriptor[FrozenSet[Any]]	proxy_setbool_is_immutablec                    t               NNotImplementedErrorselfvaluess     Y/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/sqlalchemy/sql/annotation.py	_annotatezSupportsAnnotations._annotate>   s    !##    c                     y r'   r!   r+   r,   clones      r-   _deannotatezSupportsAnnotations._deannotateA       
 r/   c                     y r'   r!   r1   s      r-   r3   zSupportsAnnotations._deannotateH       
 "r/   Nc                    t               r'   r(   r1   s      r-   r3   zSupportsAnnotations._deannotateO   s    
 "##r/   c                8    t               }| j                  |      S r'   )r   _gen_annotations_cache_key)r+   	anon_map_s     r-   _annotations_cache_keyz*SupportsAnnotations._annotations_cache_keyV   s    J	..y99r/   c           
         dt        fdt        | j                        D cg c]  }|| j                  |   f c}D              fS c c}w )Nr"   c              3  p   K   | ]-  \  }}|t        |t              r|j                  g       n|f / y wr'   )
isinstancer   _gen_cache_key).0keyvaluer   s      r-   	<genexpr>zASupportsAnnotations._gen_annotations_cache_key.<locals>.<genexpr>a   sG      #JC  &e[9 ,,Xr:"#s   36)tuplesortedr"   )r+   r   rA   s    ` r-   r9   z.SupportsAnnotations._gen_annotations_cache_key\   sa        &d&7&78#8 $++C018# 
 	
#s   Ar,   _AnnotationDictreturnr   ..r,   Literal[None]r2   r$   rH   r   r,   Sequence[str]r2   r$   rH   r    NFr,   Optional[Sequence[str]]r2   r$   rH   r    )rH   Tuple[Any, ...])r   r   rH   rQ   )__name__
__module____qualname__	__slots__r   r"   __annotations__r.   r   r3   r   memoized_propertyr;   r9   r!   r/   r-   r    r    5   s    I1BL.B99$  !$  
	   !$"" " 
	" " +/$'$ $ 
	$ 
: :

 
	
r/   r    c                      e Zd ZU dZded<   erej                  dd       ZddZ	ddZ
e	 	 d	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 dd       Z	 	 d	 	 	 	 	 dd
Zy	)SupportsWrappingAnnotationsr!   z*Callable[..., SupportsWrappingAnnotations]_constructorc                     y r'   r!   r+   s    r-   entity_namespacez,SupportsWrappingAnnotations.entity_namespacey   s    8;r/   c                .    t         j                  | |      S )greturn a copy of this ClauseElement with annotations
        updated by the given dictionary.

        	Annotated_as_annotated_instancer*   s     r-   r.   z%SupportsWrappingAnnotations._annotate|       
 //f==r/   c                .    t         j                  | |      S )hreturn a copy of this ClauseElement with annotations
        replaced by the given dictionary.

        r`   r*   s     r-   _with_annotationsz-SupportsWrappingAnnotations._with_annotations   rc   r/   c                     y r'   r!   r1   s      r-   r3   z'SupportsWrappingAnnotations._deannotate   r4   r/   c                     y r'   r!   r1   s      r-   r3   z'SupportsWrappingAnnotations._deannotate   r6   r/   Nc                .    |r| j                         }|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   ss       r-   r3   z'SupportsWrappingAnnotations._deannotate   s     AHKr/   rH   r   rF   rI   rJ   rL   rN   rO   )rR   rS   rT   rU   rV   r   r   ro_non_memoized_propertyr]   r.   rf   r   r3   r!   r/   r-   rY   rY   r   s    I<<		&	&; 
';>>  !$  
	   !$"" " 
	" " +/'  
	r/   rY   c                      e Zd ZU ej                  sdZdej                  fgZde	d<   ddZ
ddZe	 	 d	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 dd       Z	 	 d	 	 	 	 	 dd
Zy	)SupportsCloneAnnotationsr!   r"   r   %_clone_annotations_traverse_internalsc                    | j                         }|j                  j                  |      |_        |j                  j	                  dd       |j                  j	                  dd       |S )r_   r;   N_generate_cache_key)rk   r"   union__dict__popr+   r,   news      r-   r.   z"SupportsCloneAnnotations._annotate   sW    
 kkm++11&9148.5
r/   c                    | j                         }t        j                  |      |_        |j                  j                  dd       |j                  j                  dd       |S )re   r;   Nrs   )rk   r   immutabledictr"   ru   rv   rw   s      r-   rf   z*SupportsCloneAnnotations._with_annotations   sQ    
 kkm--f5148.5
r/   c                     y r'   r!   r1   s      r-   r3   z$SupportsCloneAnnotations._deannotate   r4   r/   c                     y r'   r!   r1   s      r-   r3   z$SupportsCloneAnnotations._deannotate   r6   r/   Nc                    |s| j                   rG| j                         }t        j                         |_         |j                  j                  dd       |S | S )rj   r;   N)r"   rk   r   rz   ru   rv   )r+   r,   r2   rx   s       r-   r3   z$SupportsCloneAnnotations._deannotate   sL     D%% ++-C#113CLL5t<JKr/   rF   rI   rJ   rL   rN   rO   )rR   rS   rT   typingr   rU   r   dp_annotations_keyrq   rV   r.   rf   r   r3   r!   r/   r-   rp   rp      s     	 
*==>E)+A 		  !$  
	   !$"" " 
	" " +/'  
	r/   rp   c                  L   e Zd ZU dZdZe	 	 	 	 	 	 dd       Zded<   ded<   ded	<   dd
Z	 	 	 	 ddZ	ddZ
ddZe	 	 d	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 dd       Z	 	 d 	 	 	 	 	 d!dZej                  sd"dZed        Zd#dZd$dZd%dZd&dZej0                  d'd       Zy)(ra   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".

    FrY   c                    	 t         |j                     }  | ||      S # t        $ r t        |j                  |       } Y *w xY wr'   )annotated_classes	__class__KeyError_new_annotation_type)clselementr,   s      r-   rb   z Annotated._as_annotated_instance  sI    	?#G$5$56C 7F##  	?&w'8'8#>C	?s    A A r   r"   _Annotated__elementint_hashc                ,    t         j                  |       S r'   )object__new__)r   argss     r-   r   zAnnotated.__new__  s    ~~c""r/   c                   |j                   j                         | _         | j                   j                  dd        | j                   j                  dd        || _        t	        j
                  |      | _        t        |      | _        y Nr;   rs   )	ru   copyrv   r   r   rz   r"   hashr   )r+   r   r,   s      r-   __init__zAnnotated.__init__  si      ((--/2D9/6  ..v6']
r/   c                ^    | j                   j                  |      }| j                  |      }|S r'   )r"   rt   rf   )r+   r,   _valuesrx   s       r-   r.   zAnnotated._annotate(  s-    ##))&1$$W-
r/   c                2   | j                   j                  | j                         }| j                  j                         |_        |j                  j	                  dd        |j                  j	                  dd        t        j                  |      |_        |S r   )r   r   ru   r   rv   r   rz   r"   r1   s      r-   rf   zAnnotated._with_annotations-  sp    &&t~~6++-3T:0$7!//7r/   c                     y r'   r!   r1   s      r-   r3   zAnnotated._deannotate5  r4   r/   c                     y r'   r!   r1   s      r-   r3   zAnnotated._deannotate<  s    
 r/   Nc           
         || j                   S | j                  t        j                  | j                  j                         D ci c]  \  }}||vr|| c}}            S c c}}w r'   )r   rf   r   rz   r"   items)r+   r,   r2   rA   rB   s        r-   r3   zAnnotated._deannotateC  su    
 >>>!))"" +/*;*;*A*A*C*CJCf, U
*C s   A#c                R     | j                   j                  j                  | |fi |S r'   )r   r   _compiler_dispatch)r+   visitorkws      r-   r   zAnnotated._compiler_dispatchW  s.    >4>>++>>g!# r/   c                .    | j                   j                  S r'   )r   rZ   r\   s    r-   rZ   zAnnotated._constructor\  s    >>...r/   c                     | j                   j                  di |}|| j                   u r| S |j                  j                  | j                         | j	                  || j
                        S )Nr!   )r   rk   ru   updater   r"   )r+   r   r2   s      r-   rk   zAnnotated._clone`  s[    %%%++DNN"K NN!!$--0>>%):):;;r/   c                J    | j                   | j                  | j                  ffS r'   )r   r   r"   r\   s    r-   
__reduce__zAnnotated.__reduce__k  s     ~~0A0ABBBr/   c                    | j                   S r'   )r   r\   s    r-   __hash__zAnnotated.__hash__n  s    zzr/   c                    | j                   r&| j                  j                  j                  | |      S t	        |      t	        |       k(  S r'   )_is_column_operatorsr   r   __eq__r   )r+   others     r-   r   zAnnotated.__eq__q  s;    $$>>++224??;$t*,,r/   c                    d| j                   v r't        t        | j                   d         j                  S | j                  j                  S )Nr]   )r"   r   rY   r]   r   r\   s    r-   r]   zAnnotated.entity_namespacew  sI    !2!22+!!"45 
 >>222r/   )r   rY   r,   rG   rH   ra   )r   z
Type[Self]r   r   rH   r   )r   rY   r,   rG   rF   rI   rJ   )r,   rM   r2   r$   rH   ra   )NTrO   )r   r   r   r   rH   r   )r   r   rH   r   )rH   z'Tuple[Type[Annotated], Tuple[Any, ...]])rH   r   )r   r   rH   r$   rm   )rR   rS   rT   __doc__r   classmethodrb   rV   r   r   r.   rf   r   r3   r~   r   r   propertyrZ   rk   r   r   r   r   rn   r]   r!   r/   r-   ra   ra      s\   & !$1$;J$	$ $ /.**J##2#<K#
  !$  
	   !$  
	  +/'  
	$ 	
 
	/ 
	/	<C- 
""3 #3r/   ra   z8Dict[Type[SupportsWrappingAnnotations], Type[Annotated]]r   _SA)boundc                N    	 | j                   } ||      S # t        $ r | cY S w xY wr'   )r.   AttributeError)to_annotater   r.   s      r-   _safe_annotater     s8    &))	 %%   	s    $$F)detect_subquery_colsind_cols_on_fromclauseannotate_callablec               d    i dfd| 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.

    c                   	|d<   t        |       }|v r|   S 
r<t        | d      r0| j                  j                  
      r | j                  ddi|}nO| j
                  k7  r>	r!| j                  r | j                  ddi|}n| }r
 |      }nt        |      }n| }|j                         ||<   |S )Nr   r#   r2   )r2   r   r!   )	idhasattrr#   intersectionrk   r"   r%   r   _copy_internals)elemr   id_newelemr   r   r   r2   
cloned_idsr   excluder   s        r-   r2   z_deep_annotate.<locals>.clone  s     &:!"h*c?" k*++G4!dkk444GD---#(:(:)dkk<<<" +KE(kBG0F 	  	
 "
3r/   Nr   r    r   r   rH   r    r   r   )r   r   r   r   r   r   r2   r   s    `````@@r-   _deep_annotater     s7    * 24J' 'R sE'N+ENr/   c                     y r'   r!   r   r,   s     r-   _deep_deannotater     s     r/   c                     y r'   r!   r   s     r-   r   r     s     r/   c                T    i dfd| t        t         |             } d| S )z2Deep copy the given element, removing annotations.c                    rt        |       }n| }|vr,| j                  d      }|j                         ||<   |S |   S )NT)r,   r2   )r2   )r   r3   r   )r   r   rA   r   r2   clonedr,   s       r-   r2   z_deep_deannotate.<locals>.clone  sZ    T(CCf&&fD&AG##%#0!F3KN#;r/   Nr   r   )r   r,   r2   r   s    `@@r-   r   r     s1    
 .0F sE'N+ENr/   c                H    | j                  |      } | j                          | 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   )r   r   s     r-   _shallow_annotater     s%     ,GNr/   c                   t        | t              r| S | t        v r	t        |    S | j                  D ]  }|t        v st        |   } n t	        t
        t           t        d| j                  z  || fi             xt        | <   }|t               d| j                  z  <   d| j                  v r/t        | j                        dt        j                  fgz   |_        nJ| j                  j                  dd      r.t        | j                        dt        j                  fgz   |_        | j                  j                  dd      rd|_        n"d| j                  v r| 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)
issubclassra   r   __mro__r   r   typerR   globalsru   listr   r   r   getr   r   ColumnOperatorsr   )r   base_clssuper_anno_clss       r-   r   r     sn    #y!
	!	! %%++ &&(0H  )-Y]S\\)Hc?B?) cX /7GImcll*+,'+C,C,C'D.AABH
 (
$ 
		/5	1'+C,C,C'D.AABH
 (
$ ||/!%	CLL	(!$o!>$.sI4M4M$NH!Or/   c                P    t        j                  |       D ]  }t        ||        y r'   )r   walk_subclassesr   )target_hierarchyr   r   s      r-   _prepare_annotationsr   D  s$     ##$45S(+ 6r/   )r   r   r   rG   rH   r   r'   )r   r   r   rG   r   z'Optional[Sequence[SupportsAnnotations]]r   r$   r   r$   r   zOOptional[Callable[[SupportsAnnotations, _AnnotationDict], SupportsAnnotations]]rH   r   )r   rK   r,   rP   rH   rK   )r   r   r,   rP   rH   r   )r   Optional[_SA]r,   rP   rH   r   )r   r   r   rG   rH   r   )r   !Type[SupportsWrappingAnnotations]r   Type[Annotated]rH   r   )r   r   r   r   rH   None)1r   
__future__r   r~   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   strrG   
EMPTY_DICTr   rV   r    rY   rp   ra   r   r   r   r   r   r   r   r   r!   r/   r-   <module>r      s   #                 "  + '  ! &0#s(#26// / A:
/ :
z7"5 7tH: HVH3# H3b  K  e01	& 8<C
 "'#( 	CC C 5C
 C !CC 	CL 
>B$; 

 
481 
 ?C$;8
,	*,6E,,^,7,, 
,r/   