|oiEddZddlmZddlmZGddeZiZd dZd d Zd Z d Z d Z dS)zThe :class:`.Annotated` class and related routines; creates hash-equivalent copies of SQL constructs which contain context-specific markers and associations. ) operators)utilcfeZdZdZdZdZdZdZddZd Z e d Z d Z d Z d ZdZdS) AnnotatedaEclones a ClauseElement 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". c|st|S|\}} t|j}n%#t$rt |j|}YnwxYwt|SN)object__new__annotated_classes __class__KeyError_new_annotation_type)clsargselementvaluess P/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/sql/annotation.pyr zAnnotated.__new__&s '>>#&& &"OGV C'(9: C C C*7+>#&& &s6AAc|j|_||_||_t ||_dSr )__dict__copy_Annotated__element _annotationshash_hash)selfrrs r__init__zAnnotated.__init__4s8(--//  "']] c|j}||||Sr )rrupdate_with_annotations)rr_valuess r _annotatezAnnotated._annotate:s<#((**v%%g...rc|j|j}|j|_||_|Sr )r r rrr)rrclones rr!zAnnotated._with_annotations?s;&&t~66++--# rNTc||jS|j}|D]}||d||Sr )rrrpopr!)rrr%r"vs r _deannotatezAnnotated._deannotateEs] >> !',,..G % % At$$$$))'22 2rc 4|jjj||fi|Sr )rr _compiler_dispatch)rvisitorkws rr+zAnnotated._compiler_dispatchNs$:t~':4OOBOOOrc|jjSr )r _constructorrs rr/zAnnotated._constructorQs ~**rc|j}||jur|S|j|j|||jSr )r_clonerr r r)rr%s rr2zAnnotated._cloneUsX%%'' DN " "K N ! !$- 0 0 0>>%):;; ;rc,|j|j|jffSr )r rrr0s r __reduce__zAnnotated.__reduce__`s~0ABBBrc|jSr )rr0s r__hash__zAnnotated.__hash__cs zrct|jtjr |jj||St |t |kSr ) isinstancerrColumnOperatorsr __eq__r)rothers rr:zAnnotated.__eq__fsK dni&? @ @ ->+224?? ?;;$t**, ,r)NT)__name__ __module__ __qualname____doc__r rr#r!r)r+propertyr/r2r4r6r:rrrrs& ' ' '### ///  3333PPP++X+ < < <CCC-----rrNc8fd| |}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. cr?t|dr/|jr|}n#|jkr|}n|}||S)N proxy_setr%)hasattrrD intersectionr2rr#_copy_internals)elemnewelem annotationsr%excludes rr%z_deep_annotate..clone{s  k** ++G44  kkmmGG D- - -nn[11GGGe,,,rNrA)rrKrLr%s ``@r_deep_annotaterMssG       %.. E Nrc^tjfd| |}d|S)z2Deep copy the given element, removing annotations.cs|vr6|d}|s||<|S|S)NT)rr%rE)r)rH)rIrJr%clonedrs rr%z_deep_deannotate..clonesf  T''&&fD&AAG  # #% # 0 0 0 '&t N$< rN)r column_dict)rrr%rPs `@@r_deep_deannotaterRsW   F       %.. E NrcX||}||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 "dont traverse" annotation to a selectable, without digging throughout the whole structure wasting time. )r#rH)rrKs r_shallow_annotaterTs. ,,G  Nrc t|tr|S|tvr t|S|jD]}|tvrt|}nt d|jz||fixt|<}|t d|jz<|S)Nz Annotated%s) issubclassrr __mro__typer<globals)rbase_clssuper_anno_clss rrrs#y!!& ! ! ! %%+ & & &(0H E ')- $xor))cX/7GIImcl*+ Orc|g}|rO|}||t|||MdSdSr )r'extend__subclasses__r)target_hierarchyrZstackrs r_prepare_annotationsrbsk  E ,iikk S''))***S(+++ ,,,,,rr ) r?rrr rr rMrRrTrrbrArrrds X-X-X-X-X-X-X-X-|86   *,,,,,r