
    -h.                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  \	R                  " 5       r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r0 rS r SS jrSS jrS rS rS rg)zThe :class:`.Annotated` class and related routines; creates hash-equivalent
copies of SQL constructs which contain context-specific markers and
associations.

   )	operators)HasCacheKey)anon_map)InternalTraversal   )utilc                   B    \ rS rSr\r\R                  S 5       rS r	Sr
g)SupportsAnnotations   c                 8    [        5       nU R                  U5      $ N)r   _gen_annotations_cache_key)self	anon_map_s     nC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/sql/annotation.py_annotations_cache_key*SupportsAnnotations._annotations_cache_key   s    J	..y99    c           
         ^ S[        U4S j[        U R                  5       Vs/ s H  nX R                  U   4PM     sn 5       5      4$ s  snf )N_annotationsc              3   ~   >#    U  H2  u  pU[        U[        5      (       a  UR                  T/ 5      OU4v   M4     g 7fr   )
isinstancer   _gen_cache_key).0keyvaluer   s      r   	<genexpr>ASupportsAnnotations._gen_annotations_cache_key.<locals>.<genexpr>#   sE      #JC !%55 ((26	#s   :=)tuplesortedr   )r   r   r   s    ` r   r   .SupportsAnnotations._gen_annotations_cache_key    s]       &d&7&78#8 ++C018# 
 	
#s   A N)__name__
__module____qualname____firstlineno__EMPTY_ANNOTATIONSr   r   memoized_propertyr   r   __static_attributes__r"   r   r   r
   r
      s$    $L	: :

r   r
   c                   H    \ rS rSrS\R
                  4/rS rS rSS jr	Sr
g)	SupportsCloneAnnotations2   r   c                     U R                  5       nUR                  R                  U5      Ul        UR                  R	                  SS5        UR                  R	                  SS5        U$ )Wreturn a copy of this ClauseElement with annotations
updated by the given dictionary.

r   N_generate_cache_key)_cloner   union__dict__popr   valuesnews      r   	_annotate"SupportsCloneAnnotations._annotate8   sW    
 kkm++11&9148.5
r   c                     U R                  5       n[        R                  " U5      Ul        UR                  R                  SS5        UR                  R                  SS5        U$ )Xreturn a copy of this ClauseElement with annotations
replaced by the given dictionary.

r   Nr/   )r0   r   immutabledictr   r2   r3   r4   s      r   _with_annotations*SupportsCloneAnnotations._with_annotationsC   sQ    
 kkm--f5148.5
r   Nc                     U(       d  U R                   (       aH  U R                  5       n[        R                  " 5       Ul         UR                  R                  SS5        U$ U $ )return a copy of this :class:`_expression.ClauseElement`
with annotations
removed.

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

r   N)r   r0   r   r;   r2   r3   )r   r5   cloner6   s       r   _deannotate$SupportsCloneAnnotations._deannotateN   sL     D%% ++-C#113CLL5t<JKr   r"   NF)r#   r$   r%   r&   r   dp_annotations_key%_clone_annotations_traverse_internalsr7   r<   rA   r)   r"   r   r   r+   r+   2   s*     
*==>-)		r   r+   c                   *    \ rS rSrS rS rSS jrSrg)SupportsWrappingAnnotationsb   c                     [        X5      $ )r.   	Annotatedr   r5   s     r   r7   %SupportsWrappingAnnotations._annotatec       
 &&r   c                     [        X5      $ )r:   rJ   rL   s     r   r<   -SupportsWrappingAnnotations._with_annotationsj   rN   r   Nc                 8    U(       a  U R                  5       nU$ U $ )r?   )r0   )r   r5   r@   ss       r   rA   'SupportsWrappingAnnotations._deannotateq   s     AHKr   r"   rC   )r#   r$   r%   r&   r7   r<   rA   r)   r"   r   r   rG   rG   b   s    ''r   rG   c                   |    \ rS rSrSrSrS rS rS rS r	SS	 jr
S
 r\S 5       rS rS rS rS r\S 5       rSrg)rK      a  clones a SupportsAnnotated and applies an 'annotations' dictionary.

Unlike regular clones, this clone also mimics __hash__() and
__cmp__() 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".

Fc                     U(       d  [         R                  U 5      $ Uu  p# [        UR                     n [         R                  U 5      $ ! [         a    [        UR                  U 5      n  N7f = fr   )object__new__annotated_classes	__class__KeyError_new_annotation_type)clsargselementr5   s       r   rX   Annotated.__new__   sg    >>#&&"OGC'(9(9: >>#&&  C*7+<+<cBCs   A
 
 A-,A-c                    UR                   R                  5       U l         U R                   R                  SS 5        U R                   R                  SS 5        Xl        [        R
                  " U5      U l        [        U5      U l        g Nr   r/   )	r2   copyr3   _Annotated__elementr   r;   r   hash_hash)r   r_   r5   s      r   __init__Annotated.__init__   se    ((--/2D9/6  ..v6']
r   c                 Z    U R                   R                  U5      nU R                  U5      $ r   )r   r1   r<   )r   r5   _valuess      r   r7   Annotated._annotate   s)    ##))&1%%g..r   c                 
   U R                   R                  U R                   5      nU R                  R                  5       Ul        UR                  R	                  SS 5        UR                  R	                  SS 5        Xl        U$ rb   )rZ   rX   r2   rc   r3   r   )r   r5   r@   s      r   r<   Annotated._with_annotations   sc    &&t~~6++-3T:0$7#r   Nc           
          Uc  U R                   $ U R                  [        R                  " U R                  R                  5        VVs0 s H  u  p4X1;  d  M  X4_M     snn5      5      $ s  snnf r   )rd   r<   r   r;   r   items)r   r5   r@   r   r   s        r   rA   Annotated._deannotate   so    >>>!))"" +/*;*;*A*A*C*CJC, #
*C s   A)A)c                 P    U R                   R                  R                  " X40 UD6$ r   )rd   rZ   _compiler_dispatch)r   visitorkws      r   rr   Annotated._compiler_dispatch   s"    ~~''::4OBOOr   c                 .    U R                   R                  $ r   )rd   _constructorr   s    r   rw   Annotated._constructor   s    ~~***r   c                     U R                   R                  " S0 UD6nX R                   L a  U $ UR                  R                  U R                  5        U R	                  X R
                  5      $ )Nr"   )rd   r0   r2   updaterZ   r   )r   rt   r@   s      r   r0   Annotated._clone   sU    %%++NN"K NN!!$--0>>%):):;;r   c                 J    U R                   U R                  U R                  44$ r   )rZ   rd   r   rx   s    r   
__reduce__Annotated.__reduce__   s     ~~0A0ABBBr   c                     U R                   $ r   )rf   rx   s    r   __hash__Annotated.__hash__   s    zzr   c                     U R                   (       a%  U R                  R                  R                  X5      $ [	        U5      [	        U 5      :H  $ r   )_is_column_operatorsrd   rZ   __eq__re   )r   others     r   r   Annotated.__eq__   s9    $$>>++224??;$t*,,r   c                     SU R                   ;   a  U R                   S   R                  $ U R                  R                  $ )Nentity_namespace)r   r   rd   rx   s    r   r   Annotated.entity_namespace   s8    !2!22$$%78III>>222r   )r2   	__elementr   rf   )NT)r#   r$   r%   r&   __doc__r   rX   rg   r7   r<   rA   rr   propertyrw   r0   r~   r   r   r   r)   r"   r   r   rK   rK      sk    & !'#/P + +	<C- 3 3r   rK   c                 P     U R                   nU" U5      $ ! [         a    U s $ f = fr   )r7   AttributeError)to_annotateannotationsr7   s      r   _safe_annotater      s8    &))	 %%   	s    %%Nc                 B   ^^^^^ 0 mUUUUU4S jmU b  T" U 5      n SmU $ )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                   > TUS'   [        U 5      nUT;   a  TU   $ T(       aF  [        U S5      (       a5  U R                  R                  T5      (       a  U R                  " SST0UD6nOVTU R
                  :w  aD  T(       a0  U R                  (       a  [        U R                  " SST0UD6T5      nO[        U T5      nOU nUR                  TS9  UTU'   U$ )Ndetect_subquery_cols	proxy_setr@   r@   r"   )	idhasattrr   intersectionr0   r   _is_immutabler   _copy_internals)	elemrt   id_newelemr   r@   
cloned_idsr   excludes	       r   r@   _deep_annotate.<locals>.clone  s    %9!"h*c?" k**++G44kk444GD---#(:(:(KK2e2r2K ){;Ge,!
3r   Nr"   )r_   r   r   r   r@   r   s    ```@@r   _deep_annotater     s/     J 4 .ENr   c                 :   ^^^ 0 mUUU4S jmU b  T" U 5      n SmU $ )z2Deep copy the given element, removing annotations.c                    > T(       a  [        U 5      nOU nUT;  a&  U R                  TSS9nUR                  TS9  UTU'   U$ TU   $ )NT)r5   r@   r   )r   rA   r   )r   rt   r   r   r@   clonedr5   s       r   r@   _deep_deannotate.<locals>.clone5  sZ    T(CCf&&fD&AG##%#0!F3KN#;r   Nr"   )r_   r5   r@   r   s    `@@r   _deep_deannotater   0  s*     F .ENr   c                 H    U R                  U5      n U R                  5         U $ )zAnnotate 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.
)r7   r   )r_   r   s     r   _shallow_annotater   I  s%     ,GNr   c                    [        U [        5      (       a  U $ U [        ;   a	  [        U    $ U R                   H  nU[        ;   d  M  [        U   n  O   [	        SU R
                  -  X40 5      =[        U '   nU[        5       SU R
                  -  '   SU R                  ;   a/  [        U R                  5      S[        R                  4/-   Ul	        OOU R                  R                  SS5      (       a.  [        U R                  5      S[        R                  4/-   Ul	        U R                  R                  SS5      (       a  SUl        [        U [        R                  5      Ul        U$ )NzAnnotated%s_traverse_internalsr   inherit_cacheFT)
issubclassrK   rY   __mro__typer#   globalsr2   listr   r   rD   getr   r   ColumnOperatorsr   )r]   base_clssuper_anno_clss       r   r\   r\   V  sJ   #y!!
	!	! %%++ &&(0H  )-$xor) cX /7GImcll*+,'+C,C,C'D.AABH
 (
$ 
		/5	1	1'+C,C,C'D.AABH
 (
$ ||//!%$.sI4M4M$NH!Or   c                 T    [         R                  " U 5       H  n[        X!5        M     g r   )r   walk_subclassesr\   )target_hierarchyr   r]   s      r   _prepare_annotationsr   |  s     ##$45S+ 6r   rC   r   )r    r   baser   
traversalsr   visitorsr   r   r;   r'   rW   r
   r+   rG   rK   rY   r   r   r   r   r\   r   r"   r   r   <module>r      s        ' &&( 
& 
6-2 -`"5 >i3 i3b  	& >C,^2
#L,r   