U aI-@sdZddlmZddlmZddlmZddlmZddlm Z e Z Gdd d e Z Gd d d e ZGd d d e ZGddde ZiZdddZdddZddZddZddZdS)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@seZdZeZejddZdS)SupportsAnnotationscs4tdtfddfddtjDDfS)N _annotationsc3s0|](\}}|t|tr"|gn|fVqdSN) isinstancerZ_gen_cache_key.0keyvalue) anon_map_ZC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\sql\annotation.py s z=SupportsAnnotations._annotations_cache_key..csg|]}|j|fqSr)r )r rselfrr &sz>SupportsAnnotations._annotations_cache_key..)rtuplesortedr rr)rrr_annotations_cache_keys  z*SupportsAnnotations._annotations_cache_keyN)__name__ __module__ __qualname__EMPTY_ANNOTATIONSr rZmemoized_propertyrrrrrrsrc@s2eZdZdejfgZddZddZd dd ZdS) SupportsCloneAnnotationsr cCs6|}|j||_|jdd|jdd|S)greturn a copy of this ClauseElement with annotations updated by the given dictionary. rN_generate_cache_key)_cloner union__dict__poprvaluesnewrrr _annotate4s z"SupportsCloneAnnotations._annotatecCs4|}t||_|jdd|jdd|S)hreturn a copy of this ClauseElement with annotations replaced by the given dictionary. rNr )r!r immutabledictr r#r$r%rrr_with_annotations?s  z*SupportsCloneAnnotations._with_annotationsNFcCs6|s |jr.|}t|_|jdd|S|SdS)return a copy of this :class:`_expression.ClauseElement` with annotations removed. :param values: optional tuple of individual values to remove. rN)r r!rr*r#r$)rr&cloner'rrr _deannotateJs  z$SupportsCloneAnnotations._deannotate)NF) rrrrdp_annotations_keyZ%_clone_annotations_traverse_internalsr(r+r.rrrrr.s   rc@s&eZdZddZddZd ddZdS) SupportsWrappingAnnotationscCs t||S)r Annotatedrr&rrrr(_sz%SupportsWrappingAnnotations._annotatecCs t||S)r)r1r3rrrr+fsz-SupportsWrappingAnnotations._with_annotationsNFcCs|r|}|S|SdS)r,N)r!)rr&r-srrrr.ms z'SupportsWrappingAnnotations._deannotate)NF)rrrr(r+r.rrrrr0^sr0c@s~eZdZdZdZddZddZddZd d Zdd dZ ddZ e ddZ ddZ ddZddZddZe ddZd S)r2aIclones 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". FcGsT|st|S|\}}zt|j}Wn tk rDt|j|}YnXt|SdSr )object__new__annotated_classes __class__KeyError_new_annotation_type)clsargselementr&rrrr6s zAnnotated.__new__cCsH|j|_|jdd|jdd||_t||_t||_dSNrr ) r#copyr$_Annotated__elementrr*r hash_hash)rr=r&rrr__init__s   zAnnotated.__init__cCs|j|}||Sr )r r"r+)rr&Z_valuesrrrr(s zAnnotated._annotatecCs@|j|j}|j|_|jdd|jdd||_|Sr>)r8r6r#r?r$r rr&r-rrrr+s  zAnnotated._with_annotationsNTcs6dkr|jS|tfdd|jDSdS)Ncsi|]\}}|kr||qSrrr r&rr sz)Annotated._deannotate..)r@r+rr*r itemsrDrrErr.s zAnnotated._deannotatecKs|jjj||f|Sr )r@r8_compiler_dispatch)rZvisitorkwrrrrHszAnnotated._compiler_dispatchcCs|jjSr )r@ _constructorrrrrrJszAnnotated._constructorcKs<|jjf|}||jkr|S|j|j|||jSdSr )r@r!r#updater8r )rrIr-rrrr!s  zAnnotated._clonecCs|j|j|jffSr )r8r@r rrrr __reduce__szAnnotated.__reduce__cCs|jSr )rBrrrr__hash__szAnnotated.__hash__cCs*|jr|jj||St|t|kSdSr )_is_column_operatorsr@r8__eq__rA)rotherrrrrOszAnnotated.__eq__cCs"d|jkr|jdjS|jjSdS)Nentity_namespace)r rQr@rrrrrQs  zAnnotated.entity_namespace)NT)rrr__doc__rNr6rCr(r+r.rHpropertyrJr!rLrMrOrQrrrrr2}s    r2Ncs.ifdd|dk r&|}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. csrt|}|kr|Sr@t|dr@|jr@|jf|}n|jkrV|}n|}|jd||<|S)N proxy_setr-)idhasattrrT intersectionr!r r(_copy_internals)elemrIZid_newelem annotationsr-Z cloned_idsexcluderrr-s     z_deep_annotate..cloneNr)r=r]r^rr\r_deep_annotates r_cs,ifdd|dk r$|}d|S)z2Deep copy the given element, removing annotations.csLrt|}n|}|kr@|jdd}|jd||<|S|SdS)NT)r&r-rU)rVr.rY)rZrIrr[r-Zclonedr&rrr-s  z_deep_deannotate..cloneNr)r=r&rr`r_deep_deannotates racCs||}||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(rY)r=r]rrr_shallow_annotate1s rbcCst|tr|S|tkrt|S|jD]}|tkr$t|}q>q$td|j||fit|<}|td|j<d|jkrt|j dt j fg|_ n&|j ddrt|j dt j fg|_ |j ddrd|_ t|tj|_|S)Nz Annotated%s_traverse_internalsr inherit_cacheFT) issubclassr2r7__mro__typerglobalsr#listrcrr/getrdrZColumnOperatorsrN)r;base_clsZsuper_Zanno_clsrrrr:>s4     r:cCst|D]}t||q dSr )rZwalk_subclassesr:)Ztarget_hierarchyrkr;rrr_prepare_annotationsdsrl)N)N)rRrbaserZ traversalsrZvisitorsrrr*rr5rrr0r2r7r_rarbr:rlrrrrs      0q '  &