U kf@sddlmZddlmZddlmZddlZddlmZddl Z ddl Z ddl m Z ddl m Z ddl m Z ddl mZdd l mZdd l mZdd l mZdd l mZdd l mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!e"dZ#dZ$dZ%dddddd d!Z&d"d#d$d%d&Z'Gd'd(d(eZ(Gd)d*d*e(Z)d+d,Z*Gd-d.d.eZ+Gd/d0d0eZ,e,Z-d1d2Z.Gd3d4d4eZ/e/Z0e1d5d6d7Z2Gd8d9d9eej3Z4Gd:d;d;e4Z5dS)<) annotations)dequeN) zip_longest)Any)Callable)Deque)Dict)Iterable)Optional)Set)Tuple)Type) operators) HasCacheKey)_TraverseInternalsTypeanon_map)ExternallyTraversible)HasTraversalDispatch)HasTraverseInternals)util) langhelpers)SelfZ skip_traverseFTrboolobj1obj2kwreturncKs*|ddrt}nt}|j||f|S)N use_proxiesF)getColIdentityComparatorStrategyTraversalComparatorStrategycompare)rrrZstrategyr&I/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/traversals.pyr%,s r%z Type[Any]None)target_hierarchyr cCsPt|D]@}t|dr t|dr |t||jdt||jdq dS)N_generate_cache_attrs_traverse_internals#_generated_copy_internals_traversalZ!_generated_get_children_traversal)rZwalk_subclasseshasattrr*_copy_internalsZgenerate_dispatchr+ _get_children)r)clsr&r&r'_preconfigure_traversals6s  r1c@seZdZdZdZejrDdddddZddd d d Zdd d dZ e ddddddZ e ddddddZ e ddddddZ ddd ddZdd ddZddddd Zd!dd"d#d$Zd%S)&HasShallowCopyzattribute-wide operations that are useful for classes that use __slots__ and therefore can't operate on their attributes in a dictionary. r&rr()otherr cCsdSNr&)selfr3r&r&r'!_generated_shallow_copy_traversalSz0HasShallowCopy._generated_shallow_copy_traversalzDict[str, Any])dr cCsdSr4r&)r5r8r&r&r'&_generated_shallow_from_dict_traversalUsz5HasShallowCopy._generated_shallow_from_dict_traversalr cCsdSr4r&r5r&r&r'$_generated_shallow_to_dict_traversalYr7z3HasShallowCopy._generated_shallow_to_dict_traversalrstrzCallable[[Self, Self], None])internal_dispatch method_namer cCs4ddd|D}d|d|d}t|i|S)N css"|]\}}d|d|VqdS)z other.z = self.Nr&.0attrname_r&r&r' asz8HasShallowCopy._generate_shallow_copy..def z(self, other): joinrZ_exec_code_in_envr0r>r?codeZ meth_textr&r&r'_generate_shallow_copy[s  z%HasShallowCopy._generate_shallow_copyz Callable[[Self], Dict[str, Any]]cCs4ddd|D}d|d|d}t|i|S)Nz, css"|]\}}d|d|VqdS)z 'z': self.Nr&rAr&r&r'rEnsz;HasShallowCopy._generate_shallow_to_dict..rFz(self): return {z} rGrIr&r&r'_generate_shallow_to_dicths  z(HasShallowCopy._generate_shallow_to_dictz&Callable[[Self, Dict[str, Any]], None]cCs4ddd|D}d|d|d}t|i|S)Nr@css$|]\}}d|d|dVqdS)z self.z = d['z']Nr&rAr&r&r'rE{sz=HasShallowCopy._generate_shallow_from_dict..rFz (self, d): rGrIr&r&r'_generate_shallow_from_dictus  z*HasShallowCopy._generate_shallow_from_dictcCsL|j}z|jd}Wn(tk r<||jd}||_YnX|||dS)Nr9) __class____dict__KeyErrorrMr+r9)r5r8r0Zshallow_from_dictr&r&r'_shallow_from_dicts z!HasShallowCopy._shallow_from_dictcCsF|j}z|jd}Wn(tk r<||jd}||_YnX||S)Nr<)rNrOrPrLr+r<)r5r0Zshallow_to_dictr&r&r'_shallow_to_dicts zHasShallowCopy._shallow_to_dictcCsL|j}z|jd}Wn(tk r<||jd}||_YnX|||dS)Nr6)rNrOrPrKr+r6)r5r3r0Z shallow_copyr&r&r'_shallow_copy_tos zHasShallowCopy._shallow_copy_tor)rr cKs|j|j}|||S)zCreate a shallow copyrN__new__rS)r5rcr&r&r'_clones zHasShallowCopy._cloneN)__name__ __module__ __qualname____doc__ __slots__typing TYPE_CHECKINGr6r9r< classmethodrKrLrMrQrRrSrWr&r&r&r'r2Hs    r2c@s"eZdZdZdZddddZdS)GenerativeOnTraversalzSupplies Generative behavior but making use of traversals to shallow copy. .. seealso:: :class:`sqlalchemy.sql.base.Generative` r&rr:cCs|j}||}|||Sr4rT)r5r0sr&r&r' _generates  zGenerativeOnTraversal._generateN)rXrYrZr[r\rbr&r&r&r'r`s r`cKs|Sr4)rW)elementrr&r&r'rWsrWc@s0eZdZdZddZddddddd d Zd S) HasCopyInternalsr&cKs tdSr4NotImplementedError)r5rr&r&r'rWszHasCopyInternals._clone) omit_attrsz Iterable[str]rr()rgrr cKsvz |j}Wntk r YdSXt||dD]@\}}}||krDq0|dk r0||||f|}|dk r0t|||q0dS)atReassign internal elements to be clones of themselves. Called during a copy-and-traverse operation on newly shallow-copied elements to create a deep copy. The given clone function should be used, which may be applying additional transformations to the element (i.e. replacement traversal, cloned traversal, annotations). Nr,)r+AttributeErrorr.Zrun_generated_dispatchsetattr)r5rgrZtraverse_internalsrCobjmethresultr&r&r'r.s z HasCopyInternals._copy_internalsN)rXrYrZr\rWr.r&r&r&r'rdsrdc@seZdZdZefddZefddZefddZefdd Zefd d Z efd d Z efddZ efddZ ddZ efddZefddZefddZefddZdS)_CopyInternalsTraversalzmGenerate a _copy_internals internal traversal dispatch for classes with a _traverse_internals collection.cKs ||f|Sr4r&r5rCparentrcclonerr&r&r'visit_clauseelementsz+_CopyInternalsTraversal.visit_clauseelementc sfdd|DS)Ncsg|]}|fqSr&r&rBclauserprr&r' szD_CopyInternalsTraversal.visit_clauseelement_list..r&rnr&rtr'visit_clauseelement_listsz0_CopyInternalsTraversal.visit_clauseelement_listc stfdd|DS)Ncsg|]}|fqSr&r&rrrtr&r'ru szE_CopyInternalsTraversal.visit_clauseelement_tuple..tuplernr&rtr'visit_clauseelement_tuplesz1_CopyInternalsTraversal.visit_clauseelement_tuplec stfdd|DS)Ncsg|]}|fqSr&r&rrrtr&r'ruszD_CopyInternalsTraversal.visit_executable_options..rwrnr&rtr'visit_executable_options sz0_CopyInternalsTraversal.visit_executable_optionsc sfdd|DS)Ncsh|]}|fqSr&r&rrrtr&r' szL_CopyInternalsTraversal.visit_clauseelement_unordered_set..r&rnr&rtr'!visit_clauseelement_unordered_setsz9_CopyInternalsTraversal.visit_clauseelement_unordered_setc sfdd|DS)Ncs$g|]}tfdd|DqS)c3s|]}|fVqdSr4r&)rBZtup_elemrtr&r'rEszP_CopyInternalsTraversal.visit_clauseelement_tuples...rw)rBelemrtr&r'ruszF_CopyInternalsTraversal.visit_clauseelement_tuples..r&rnr&rtr'visit_clauseelement_tupless z2_CopyInternalsTraversal.visit_clauseelement_tuplesc sfdd|DS)Ncsi|]\}}||fqSr&r&rBkeyvaluertr&r' szK_CopyInternalsTraversal.visit_string_clauseelement_dict..itemsrnr&rtr'visit_string_clauseelement_dictsz7_CopyInternalsTraversal.visit_string_clauseelement_dictc stfdd|DS)Nc3s^|]V\}}}}|dk r"|fnd|dk r8|fnd|dk rN|fnd|fVqdSr4r&)rBtargetonclausefrom_flagsrtr&r'rE%s  zA_CopyInternalsTraversal.visit_setup_join_tuple..rwrnr&rtr'visit_setup_join_tuple"sz._CopyInternalsTraversal.visit_setup_join_tuplecKs|j|||f|Sr4ry)r5rCrorcrr&r&r'visit_memoized_select_entities/sz6_CopyInternalsTraversal.visit_memoized_select_entitiesc sfdd|DS)Ncs6g|].\}}t|dr"|fn||ffqS__clause_element__r-rrtr&r'ru6s   zD_CopyInternalsTraversal.visit_dml_ordered_values..r&rnr&rtr'visit_dml_ordered_values2s z0_CopyInternalsTraversal.visit_dml_ordered_valuesc sfdd|DS)Ncs4i|],\}}t|dr"|fn||fqSrrrrtr&r'rCsz<_CopyInternalsTraversal.visit_dml_values..rrnr&rtr'visit_dml_valuesBs z(_CopyInternalsTraversal.visit_dml_valuesc s fddfdd|DS)NcsPt|ttfr"fdd|DSt|trDfdd|DSdsLtdS)Ncs&g|]}t|dr|fn|qSrr)rBrrtr&r'ruQszP_CopyInternalsTraversal.visit_dml_multi_values..copy..csBi|]:\}}t|dr"|fn|t|dr:|fn|qSrrrrtr&r'rZs zP_CopyInternalsTraversal.visit_dml_multi_values..copy..F) isinstancelistrxdictrAssertionErrorr}rtr&r'copyOs   z<_CopyInternalsTraversal.visit_dml_multi_values..copycsg|]}fdd|DqS)csg|] }|qSr&r&)rBZ sub_elementrr&r'rukszM_CopyInternalsTraversal.visit_dml_multi_values...r&)rBsequencerr&r'rujszB_CopyInternalsTraversal.visit_dml_multi_values..r&rnr&)rprrr'visit_dml_multi_valuesJs z._CopyInternalsTraversal.visit_dml_multi_valuescKs|Sr4r&rnr&r&r'visit_propagate_attrsosz-_CopyInternalsTraversal.visit_propagate_attrsN)rXrYrZr[rWrqrvryrzr|r~rrrrrrrr&r&r&r'rms2           &rmcCs$t|dr t|dds |}q|S)NrZis_clause_elementF)r-getattrr)rcr&r&r'_flatten_clauseelementxs  rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd S)!_GetChildrenTraversalzqGenerate a _children_traversal internal traversal dispatch for classes with a _traverse_internals collection.cKsdSNr&r&r5rcrr&r&r'visit_has_cache_keysz)_GetChildrenTraversal.visit_has_cache_keycKs|fSr4r&rr&r&r'rqsz)_GetChildrenTraversal.visit_clauseelementcKs|Sr4r&rr&r&r'rvsz._GetChildrenTraversal.visit_clauseelement_listcKs|Sr4r&rr&r&r'rysz/_GetChildrenTraversal.visit_clauseelement_tuplecKs tj|Sr4) itertoolschain from_iterablerr&r&r'r~sz0_GetChildrenTraversal.visit_clauseelement_tuplescKsdSrr&rr&r&r',visit_fromclause_canonical_column_collectionszB_GetChildrenTraversal.visit_fromclause_canonical_column_collectioncKs|Sr4)valuesrr&r&r'rsz5_GetChildrenTraversal.visit_string_clauseelement_dictcKs|Sr4r&rr&r&r'visit_fromclause_ordered_setsz2_GetChildrenTraversal.visit_fromclause_ordered_setcKs|Sr4r&rr&r&r'r|sz7_GetChildrenTraversal.visit_clauseelement_unordered_setcksT|D]J\}}}}|dk r|Vt|ts2t|V|dk rt|tst|VqdSr4)rr=r)r5rcrrrrrr&r&r'rs  z,_GetChildrenTraversal.visit_setup_join_tuplecKs|j|f|Sr4rrr&r&r'rsz4_GetChildrenTraversal.visit_memoized_select_entitiescks(|D]\}}t|dr|V|VqdS)Nrr)r5rcrkvr&r&r'rs  z._GetChildrenTraversal.visit_dml_ordered_valuescksNdd|D}||}t|D]}||Vq |D]}|V||Vq4dS)NcSsh|]}t|dr|qSrr)rBrr&r&r'r{s z9_GetChildrenTraversal.visit_dml_values..)symmetric_differencesorted)r5rcrZ expr_valuesZ str_valuesrr&r&r'rs   z&_GetChildrenTraversal.visit_dml_valuescKsdSrr&rr&r&r'rsz,_GetChildrenTraversal.visit_dml_multi_valuescKsdSrr&rr&r&r'rsz+_GetChildrenTraversal.visit_propagate_attrsN)rXrYrZr[rrqrvryr~rrrr|rrrrrrr&r&r&r'rs   rzsqlalchemy.sql.elementscKst|tjjjr||}|Sr4)rrZ preloadedZ sql_elementsZ_anonymous_labelZ apply_map)rcnamerrr&r&r'_resolve_name_for_compares rc@seZdZdZddZddZddddd d d Zd d ZddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Z d@dAZ!dBdCZ"dDdEZ#dFdGZ$dHdIZ%dJdKZ&dLdMZ'dNdOZ(dPdQZ)dRdSZ*dTdUZ+dVdWZ,dXdYZ-dZd[Z.d\d]Z/d^d_Z0d`daZ1dbS)cr$)stackcachercCst|_t|_dSr4)rrsetrr;r&r&r'__init__sz$TraversalComparatorStrategy.__init__cCs ttfSr4rr;r&r&r'_memoized_attr_anon_mapsz3TraversalComparatorStrategy._memoized_attr_anon_maprrrrcKs|j}|j}|dd}|||f|r|\}}||krDq&n"|dksT|dkrXdS||f|krfq&|||f|j} | |jkrdSt|d| d} | r| ||f|} | tkrdS| t krq&nd} t |j |j ddD]\\} } \}}|s| dks|dkrq| |ks| |k rdS| | kr*q| dk s8t | dk sFt |dk sTt | | }|dk st |jd|j| d t| |}t||}|dkr|dk rdSqn|dkrdS|| ||||f|}|tkrdSqq&d S) Ncompare_annotationsFz compare_%sr&NN fillvalueZ _annotationsz has no dispatch for ''T)rrr"appendpopleftaddZ__visit_name__rCOMPARE_FAILED SKIP_TRAVERSErr+rdispatchrNZ_dispatch_lookupoperator attrgetter)r5rrrrrrleftrightZ visit_namerkZattributes_comparedZ left_attrnameZleft_visit_symZright_attrnameZright_visit_symrZ left_childZ right_childZ comparisonr&r&r'r%s          z#TraversalComparatorStrategy.comparecKs|}|j||f|Sr4)rNr%)r5rrrZ comparatorr&r&r' compare_inner@sz)TraversalComparatorStrategy.compare_innercKs,||jdg||jdgkr(tSdSNrr)_gen_cache_keyrrr5rC left_parentr right_parentrrr&r&r'rDs z/TraversalComparatorStrategy.visit_has_cache_keycKs||dd|ddS)NZplugin_subject)rr"rr&r&r'rLs z1TraversalComparatorStrategy.visit_propagate_attrsc Kstt||ddD]`\}}|dkr2|dk rtSqn|dkrBtS||jdg||jdgkrtSqdSNrrr)rrrr r5rCrrrrrlrr&r&r'visit_has_cache_key_listSsz4TraversalComparatorStrategy.visit_has_cache_key_listc Kst||ddD]t\}}|dkr2|dk rtSqn|dkrBtS|jrZ||jdgn||jrt||jdgn|krtSqdSr)rrZ_is_has_cache_keyrrrr&r&r'rzds z4TraversalComparatorStrategy.visit_executable_optionscKs|j||fdSr4)rrrr&r&r'rq{sz/TraversalComparatorStrategy.visit_clauseelementc Ks,t||ddD]\}}|j||fqdSNrrrr) r5rCrrrrrZlcolZrcolr&r&r'rszHTraversalComparatorStrategy.visit_fromclause_canonical_column_collectioncKsdSr4r&rr&r&r'*visit_fromclause_derived_column_collectionszFTraversalComparatorStrategy.visit_fromclause_derived_column_collectionc KsLtt|t|ddD]0\}}||kr.tS|j||||fqdSr)rrrrr) r5rCrrrrrZlstrZrstrr&r&r'rsz;TraversalComparatorStrategy.visit_string_clauseelement_dictc Ks\t||ddD]H\}}|dks&|dkr.tSt||ddD]\} } |j| | fq.rwrr&r&r'visit_with_context_optionssz6TraversalComparatorStrategy.visit_with_context_optionscKs||kSr4r&rr&r&r'visit_plain_obj&sz+TraversalComparatorStrategy.visit_plain_objcKs |dkr|dk rtS|j|jkSr4)rrrr&r&r'visit_named_ddl_element+sz3TraversalComparatorStrategy.visit_named_ddl_elementc KsDt||ddD]0\\}}\} } || kr.tS|j|| fqdSNrrr) r5rCrrrrrZl_clauseZl_strZr_clauseZr_strr&r&r'visit_prefix_sequence4sz1TraversalComparatorStrategy.visit_prefix_sequencecKslt||ddD]X\\}}} } \} } } }| |kr6tS|j|| f|j|| f|j| | fqdS)N)NNNNrr)r5rCrrrrrZl_targetZ l_onclauseZl_fromZl_flagsZr_targetZ r_onclauseZr_fromZr_flagsr&r&r'r?s   z2TraversalComparatorStrategy.visit_setup_join_tuplecKs|j|||||f|Sr4rrr&r&r'rMsz:TraversalComparatorStrategy.visit_memoized_select_entitiesc Kst|ddd}t|ddd}t||ddD]P\\} } \} } | | krNtS|| | f|| | fkrntS|j| | fq.dS)NcSs|dj|dfSrfullnamerr&r&r'Wr7zCTraversalComparatorStrategy.visit_table_hint_list..)rcSs|dj|dfSrrrr&r&r'rYr7rr)rrrrr) r5rCrrrrrZ left_keysZ right_keysZltableZldialectZrtableZrdialectr&r&r'visit_table_hint_listTsz1TraversalComparatorStrategy.visit_table_hint_listcKs||kSr4r&rr&r&r'visit_statement_hint_listesz5TraversalComparatorStrategy.visit_statement_hint_listcKs tdSr4rerr&r&r'visit_unknown_structurejsz3TraversalComparatorStrategy.visit_unknown_structurec Ks<t||ddD](\\}}\} } |j|| f|stSqdSr)r_compare_dml_values_or_cer) r5rCrrrrrrrrrr&r&r'rosz4TraversalComparatorStrategy.visit_dml_ordered_valuescKs`t|d}t|d}||kr dS|r8|j||f|s8dS|sH||krHdS|j||f|s\dSdS)NrFT)r-r)r5rrrZlvceZrvcer&r&r'rzs   z5TraversalComparatorStrategy._compare_dml_values_or_cec Ks|dks |dks t|t|kr$tSt|tjr^t||D] \}}|j||f|s:tSq:ndt|tjrntSt||D]@\\} }\} }|j| | f|stS|j||f|stSqdSr4)rrrcollections_abcSequenceziprr) r5rCrrrrrrrrrr&r&r'rs    "z,TraversalComparatorStrategy.visit_dml_valuesc Ksrt||ddD]^\}}|dks&|dkr.tSt||ddD].\} } |j||| || f|tkr||r>tSt|t|kr$tSq$tS)zCompare ColumnElements using proxies and equivalent collections. This is a comparison strategy specific to the ORM. N)unionZshares_lineagerhashr)r5rrr!Z equivalentsrZ to_compareZothr&r&r'compare_column_elements  z4ColIdentityComparatorStrategy.compare_column_elementcKs|j||f|Sr4rrr&r&r'compare_columnsz,ColIdentityComparatorStrategy.compare_columncKs|j||f|Sr4rrr&r&r' compare_labelsz+ColIdentityComparatorStrategy.compare_labelcKs||kr tStSr4)rrrr&r&r' compare_tablesz+ColIdentityComparatorStrategy.compare_tableN)Tr&)rXrYrZrr r r r&r&r&r'r#s  r#)6 __future__r collectionsrcollections.abcabcrrrrr]rrrrr r r r r r cache_keyrZvisitorsrrrrrrrZ util.typingrsymbolrrZCOMPARE_SUCCEEDEDr%r1r2r`rWrdrmr.rrr/Zpreload_modulerZ MemoizedSlotsr$r#r&r&r&r' s^                         r&} G