
    1P@i_G                       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     c/home/www/lebenam.kofcorporation.com/venv/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._deannotateI   r4   r/   Nc                    t               r'   r(   r1   s      r-   r3   zSupportsAnnotations._deannotateQ   s    
 "##r/   c                8    t               }| j                  |      S r'   )r   _gen_annotations_cache_key)r+   	anon_map_s     r-   _annotations_cache_keyz*SupportsAnnotations._annotations_cache_keyX   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>c   sC       C !%5 ((26	s   36)tuplesortedr"   )r+   r   r@   s    ` r-   r8   z.SupportsAnnotations._gen_annotations_cache_key^   s\        &d&7&78# $++C01# 
 	
#s   Ar,   _AnnotationDictreturnr   ..r,   Literal[None]r2   r$   rG   r   r,   Sequence[str]r2   r$   rG   r    NFr,   Optional[Sequence[str]]r2   r$   rG   r    )rG   Tuple[Any, ...])r   r   rG   rP   )__name__
__module____qualname__	__slots__r   r"   __annotations__r.   r   r3   r   memoized_propertyr:   r8   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    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   rb   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   r4   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/   rG   r   rE   rH   rI   rK   rM   rN   )rQ   rR   rS   rT   rU   r   r   ro_non_memoized_propertyr\   r.   re   r   r3   r!   r/   r-   rX   rX   r   s    I<<		&	&	 
'	>>  !$  
	   !$  
	  +/'  
	r/   rX   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)rj   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 )rd   r:   Nrr   )rj   r   immutabledictr"   rt   ru   rv   s      r-   re   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   r4   r/   Nc                    |s| j                   rG| j                         }t        j                         |_         |j                  j                  dd       |S | S )ri   r:   N)r"   rj   r   ry   rt   ru   )r+   r,   r2   rw   s       r-   r3   z$SupportsCloneAnnotations._deannotate   sL     D%% ++-C#113CLL5t<JKr/   rE   rH   rI   rK   rM   rN   )rQ   rR   rS   typingr   rT   r   dp_annotations_keyrp   rU   r.   re   r   r3   r!   r/   r-   ro   ro      s     	 
*==>E)+A 		  !$  
	   !$  
	  +/'  
	r/   ro   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)(r`   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".

    FrX   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-   ra   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:   rr   )	rt   copyru   r   r   ry   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"   rs   re   )r+   r,   _valuesrw   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   rt   r   ru   r   ry   r"   r1   s      r-   re   zAnnotated._with_annotations2  sp    &&t~~6++-3T:0$7!//7r/   c                     y r'   r!   r1   s      r-   r3   zAnnotated._deannotate:  r4   r/   c                     y r'   r!   r1   s      r-   r3   zAnnotated._deannotateB  r4   r/   Nc           
         || j                   S | j                  t        j                  | j                  j                         D ci c]  \  }}||vr|| c}}            S c c}}w r'   )r   re   r   ry   r"   items)r+   r,   r2   r@   rA   s        r-   r3   zAnnotated._deannotateJ  sp    
 >>>!))"" +/*;*;*A*A*C&Cf, U
 s   A#c                R     | j                   j                  j                  | |fi |S r'   )r   r   _compiler_dispatch)r+   visitorkws      r-   r   zAnnotated._compiler_dispatch^  s.    >4>>++>>g!# r/   c                .    | j                   j                  S r'   )r   rY   r[   s    r-   rY   zAnnotated._constructorc  s    >>...r/   c                     | j                   j                  di |}|| j                   u r| S |j                  j                  | j                         | j	                  || j
                        S )Nr!   )r   rj   rt   updater   r"   )r+   r   r2   s      r-   rj   zAnnotated._cloneg  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__r  s     ~~0A0ABBBr/   c                    | j                   S r'   )r   r[   s    r-   __hash__zAnnotated.__hash__u  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__x  s;    $$>>++224??;$t*,,r/   c                    d| j                   v r't        t        | j                   d         j                  S | j                  j                  S )Nr\   )r"   r   rX   r\   r   r[   s    r-   r\   zAnnotated.entity_namespace~  sI    !2!22+!!"45 
 >>222r/   )r   rX   r,   rF   rG   r`   )r   z
Type[Self]r   r   rG   r   )r   rX   r,   rF   rE   rH   rI   )r,   rL   r2   r$   rG   r`   )NTrN   )r   r   r   r   rG   r   )r   r   rG   r   )rG   z'Tuple[Type[Annotated], Tuple[Any, ...]])rG   r   )r   r   rG   r$   rl   )rQ   rR   rS   __doc__r   classmethodra   rU   r   r   r.   re   r   r3   r}   r   r   propertyrY   rj   r   r   r   r   rm   r\   r!   r/   r-   r`   r`      s\   & !$1$;J$	$ $ /.**J##2#<K#
  !$  
	   !$  
	  +/'  
	$ 	
 
	/ 
	/	<C- 
""3 #3r/   r`   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#   intersectionrj   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   rG   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          r/   c                     y r'   r!   r   s     r-   r   r     r   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   r@   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)
issubclassr`   r   __mro__r   r   typerQ   globalsrt   listr   r   r~   getr   r   ColumnOperatorsr   )r   base_clssuper_anno_clss       r-   r   r     ss    #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   M  s)     ##$45 ,S(+,r/   )r   r   r   rF   rG   r   r'   )r   r   r   rF   r   z'Optional[Sequence[SupportsAnnotations]]r   r$   r   r$   r   zOOptional[Callable[[SupportsAnnotations, _AnnotationDict], SupportsAnnotations]]rG   r   )r   rJ   r,   rO   rG   rJ   )r   r   r,   rO   rG   r   )r   Optional[_SA]r,   rO   rG   r   )r   r   r   rF   rG   r   )r   !Type[SupportsWrappingAnnotations]r   Type[Annotated]rG   r   )r   r   r   r   rG   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   strrF   
EMPTY_DICTr   rU   r    rX   ro   r`   r   r   r   r   r   r   r   r   r!   r/   r-   <module>r      s   #                 "  + '  ! &0#s(#26// / A:
/ :
z:"5 :zJ: JZJ3# J3h     e01	& 8<C
 "'#( 	CC C 5C
 C !CC 	CL 
>B$; 
 
481 
 ?C$;8
,	*,6E,,^,7,, 
,r/   