L iu NddlmZddlZddlmZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZej@rddl!m"Z"ddl!m#Z#ddl!m$Z$ddlm%Z%dd l&m'Z'Gd!d"eZ(Gd#d$ejRZ*e*jVZ+ed%ee*jVedfZ,Gd&d'ejRZ-e.e-\Z/Z0Z1Z2Z3eee4eeed(eed(ffe-effZ5Gd)d*Z6Gd+d,ee6Z7Gd-d.e6eZ8Gd/d0e6ejrZ:Gd1d2e Z; d6d3Z<Gd4d5eZ=e=Z>y)7) annotationsN) zip_longest)Any)Callable)Dict)Iterable)Iterator)List)MutableMapping) NamedTuple)Optional)Sequence)Tuple)Union)anon_map)HasTraversalDispatch)HasTraverseInternals)InternalTraversal)prefix_anon_map)util)inspect) HasMemoized)Literal)Protocol) BindParameter) ClauseElement) ColumnElement)_TraverseInternalsType)_CoreSingleExecuteParamsc eZdZ ddZy)_CacheKeyTraversalDispatchTypecyN)sselfvisitors ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/sql/cache_key.py__call__z'_CacheKeyTraversalDispatchType.__call__.s/2N)r( HasCacheKeyr)_CacheKeyTraversalreturn$_CacheKeyTraversalDispatchTypeReturn)__name__ __module__ __qualname__r+r&r,r*r#r#-s33'93 -3r,r#ceZdZdZy) CacheConstrN)r1r2r3NO_CACHEr&r,r*r5r53sHr,r5r c eZdZdZdZdZdZdZy)CacheTraverseTargetrrrN)r1r2r3CACHE_IN_PLACECALL_GEN_CACHE_KEYSTATIC_CACHE_KEYPROPAGATE_ATTRS ANON_NAMEr&r,r*r8r8?sNOIr,r8.ceZdZUdZdZeZded<dZdZ dZ ded< dZd ed <e dd Z e jd  dd ZddZe ddZy)r-apMixin for objects which can produce a cache key. This class is usually in a hierarchy that starts with the :class:`.HasTraverseInternals` base, but this is optional. Currently, the class should be able to work on its own without including :class:`.HasTraverseInternals`. .. seealso:: :class:`.CacheKey` :ref:`sql_caching` r&_CacheKeyTraversalType_cache_key_traversalTNzOptional[bool] inherit_cacher_generated_cache_key_traversalcp|jjdd}t|}|rXt|dd}| t |t sJ|j }|tus Jd|dtj||dS|jjdd}|a|jjdd}|Ct|_ |0|jr$tjd|jzd tStj||dS#t$rt|_ tcYSwxYw) zgenerate cache key dispatcher for a new class. This sets the _generated_cache_key_traversal attribute once called so should only be called once per class. rCNrBzclass zK has _cache_key_traversal=NO_CACHE, which conflicts with inherit_cache=TruerD_traverse_internalsaClass %s will not make use of SQL compilation caching as it does not set the 'inherit_cache' attribute to ``True``. This can have significant performance implications including some performance degradations in comparison to prior SQLAlchemy versions. Set this attribute to True if this object can make use of the cache key generated by the superclass. Alternatively, this attribute may be set to False which will disable this warning.cprf)code)__dict__getboolgetattr issubclassrrFAttributeErrorr6rD_cache_key_traversal_visitorgenerate_dispatch_hierarchy_supports_cachingrwarnr1)clsrCinheritrBs r*_generate_cache_attrsz!HasCacheKey._generate_cache_attrssi (($? }% #*30F#M #+$%c+?@@@+.+B+B( (x7 :: 70AA$0  $'<<#3#3&$ $+'*||'7'7)4($(/9AC6%-;;  48;|| E"( $O/AA$0 a&$9AC6#O$sDD54D5sqlalchemy.sql.elementsc V|j}|j|\}}|r||fS |jd}|t ur d|t <y||f}||t D]\}} } |  | tur'| j} | t ur d|t <y||| fz }:| turItjj} t| | jr| j|} ||| fz }| t ur||| j#||fz }| s| t$ur||| fz }| t&ur&||| d| dr| dj#||ndfz }| t(j*ur3|j,r||j.z }||j1|z }1| t(j2us$| t(j4us| t(j6ur0||t9| D cgc]} | j#||c} fz }|| || |||z }|S#t$r|j }YwxYwcc} w)aBreturn an optional cache key. The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query. The cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. If a structure cannot produce a useful cache key, the NO_CACHE symbol should be added to the anon_map and the method should return None. rDTNcompile_state_pluginplugin_subject) __class__get_anonrIKeyErrorrUr6rOr=_static_cache_keyr?r preloaded sql_elements isinstance_anonymous_label apply_mapr<_gen_cache_keyr;r>rdp_annotations_key!_gen_static_annotations_cache_key_annotations_cache_key_gen_annotations_cache_keydp_clauseelement_listdp_clauseelement_tupledp_memoized_select_entitiestuple)r(r bindparamsrSid_found dispatcherresultattrnameobjmethsckelementselems r*rczHasCacheKey._gen_cache_keys.nn&X&&t, U :  5&FGJ  !!%HX #&*$. .$ H  Hc4++//Ch-1*#xo-FY&#~~::H!#x'@'@A!mmH5xo-F// **8Z@F~-8S/10$ 67 $''7#8!$$4 5 D D$,j!"&* # !2!E!EE AA"d&A&AAF"d&E&Eh&OOF 1 G GG#4#K#KK,HHI$!14!"(,%)$7$7*$M!"#$$c4:#MH R q 5 224J  5\!"sH H&H#"H#cpg}t}|j||}t|vry|Jt||S)apreturn a cache key. The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query. The cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. The cache key returned by this method is an instance of :class:`.CacheKey`, which consists of a tuple representing the cache key, as well as a list of :class:`.BindParameter` objects which are extracted from the expression. While two expressions that produce identical cache key tuples will themselves generate identical SQL strings, the list of :class:`.BindParameter` objects indicates the bound values which may have different values in each one; these bound parameters must be consulted in order to execute the statement with the correct parameters. a :class:`_expression.ClauseElement` structure that does not implement a :meth:`._gen_cache_key` method and does not implement a :attr:`.traverse_internals` attribute will not be cacheable; when such an element is embedded into a larger structure, this method will return None, indicating no cache key is available. Nrrcr6CacheKey)r(rl _anon_mapkeys r*_generate_cache_keyzHasCacheKey._generate_cache_key[sE@02 J !!)Z8 y ? "?C, ,r,cpg}t}|j||}t|vry|Jt||Sr%rx)rSrrrlrzr{s r*_generate_cache_key_for_objectz*HasCacheKey._generate_cache_key_for_objectsD02 J   J7 y ? "?C, ,r,)r/zCUnion[_CacheKeyTraversalDispatchType, Literal[CacheConst.NO_CACHE]])rrrlList[BindParameter[Any]]r/zOptional[Tuple[Any, ...]]r/Optional[CacheKey])rrr-r/r)r1r2r3__doc__ __slots__r6rB__annotations___is_has_cache_keyrQrC classmethodrUrpreload_modulercr|r~r&r,r*r-r-\s I3;0;"&%)M>((I$''F LFFPT23{ {.F{ "{4{z(-T - -  - -r,r-c eZdZy)HasCacheKeyTraverseN)r1r2r3r&r,r*rrsr,rc6eZdZdZej ddZy)MemoizedHasCacheKeyr&c,tj|Sr%r-r|r(s r*r|z'MemoizedHasCacheKey._generate_cache_keys..t44r,Nr)r1r2r3rrmemoized_instancemethodr|r&r,r*rrsI((5)5r,rceZdZdZddZy)SlotsMemoizedHasCacheKeyr&c,tj|Sr%rrs r*$_memoized_method__generate_cache_keyz=SlotsMemoizedHasCacheKey._memoized_method__generate_cache_keys..t44r,Nr)r1r2r3rrr&r,r*rrs I5r,rceZdZUdZded<ded<ddZ ddZddZdd Ze dd Z dd Z dd Z dd Z ddZej d ddZy)ryzThe key used to identify a SQL statement construct in the SQL compilation cache. .. seealso:: :ref:`sql_caching` Tuple[Any, ...]r{zSequence[BindParameter[Any]]rlcy)z7CacheKey itself is not hashable - hash the .key portionNr&rs r*__hash__zCacheKey.__hash__sr,c|j|vrt|x||j<}n||j}|jstfdt D}ntfd|jD}t ||fS)aGenerate an "offline string" form of this :class:`.CacheKey` The "offline string" is basically the string SQL for the statement plus a repr of the bound parameter values in series. Whereas the :class:`.CacheKey` object is dependent on in-memory identities in order to work as a cache key, the "offline" version is suitable for a cache that will work for other processes as well. The given ``statement_cache`` is a dictionary-like object where the string form of the statement itself will be cached. This dictionary should be in a longer lived scope in order to reduce the time spent stringifying statements. c3(K|] }| ywr%r&).0r{ parameterss r* z-CacheKey.to_offline_string..sNC 3Nsc3jK|]*}j|j|j,ywr%)rJr{value)r bindparamrs r*rz-CacheKey.to_offline_string..s, y}}ioo> s03)r{strrlrksortedrepr)r(statement_cache statementrsql_str param_tuples ` r*to_offline_stringzCacheKey.to_offline_strings* 88? *25i. @ODHH %%dhh/GN6*;MNNK !% K Wk*++r,cFt|j|jk(Sr%)rKr{r(others r*__eq__zCacheKey.__eq__sDHH )**r,c6|j|jk( Sr%)r{rs r*__ne__zCacheKey.__ne__sHH )**r,cTt|g}t|g}|j|Sr%)ry_diff)rSleftrightck1ck2s r* _diff_tupleszCacheKey._diff_tupless(tR ub!yy~r,c#K|j}|j}g}d} ||}}|D] }||}||}tt||D]h\}\} } ||kr| | k7st| tr#t| tr|j |n5ddj d|D|| | fzj|jdyw)Nrzkey%s[%d]: %s != %sc3&K|] }d|z yw)z[%d]Nr&)rrms r*rz,CacheKey._whats_different..s#BSFSL#Bs)r{ enumeraterr`rkappendjoinpop) r(rk1k2stack pickup_indexs1s2idxe1e2s r*_whats_differentzCacheKey._whats_differents XX YY B WW "+;r2+>!?  Xb"%8!"e,B1F S)4GG#BE#BB 8  " -s ACA)CcBdj|j|S)N, )rrrs r*rzCacheKey._diff syy..u566r,cr|jg}g}t}d}|r|jd}||ur |jd|dzzdz|dz}nt |t rR|s|jd|dzdzzdzn|dz }t ||gz|z}|jd|dzzdznjt |tr/d t|jd tt|d }n t|}|jd|dzzd z|zd z|rddj|dS)Nrr rz),rz()(z rz CacheKey(key= ))r{objectrrr`rklistr-typer1hexidrr)r(routputsentinelindentrvrepr_s r*__str__zCacheKey.__str__ s/<@HH:899QBooN !1#4#44NNNs!=rVc|js||ur|Stjj}|j ||j |j Sr%) _is_immutablerr^r__OverrideBindsrl)r(original_cache_keytarget_elementrus r*_apply_params_to_elementz!CacheKey._apply_params_to_element1sO  ' '+=+E! !>>..&& DOO-?-J-J  r,N)r/z Optional[int])rzMutableMapping[Any, str]rrrr!r/r)rrr/rK)rryrryr/r)rryr/z Iterator[str])rryr/r)r/r)r/zDict[str, Any])rryrColumnElement[Any]r/r)r1r2r3rrrrrrrrrrrrrrrr&r,r*ryrys ,, ",1",!",- ", ",H++ <79<O T23  "*  NotImplementedError) tokens traverse_argsargsrlrztuprqsymargr{ visit_keyrss r*_ad_hoc_cache_key_from_argsr>s ,.J I C #M4 8D3hhKKx0 ; Hd# #C 3Y? > ! Hc? "C        &-dV3LM  4#tY C CC+D, Jr,ceZdZexZZejZejZ ejZ ejZexZxZxZZeZeZeZeZ ddZ ddZ ddZ ddZ ddZ ddZ ddZ! ddZ" dd Z# dd Z$ dd Z% dd Z& dd Z' ddZ( ddZ) ddZ* ddZ+ ddZ, ddZ- ddZ. ddZ/ ddZ0 ddZ1 ddZ2 ddZ3y)r.c&td|DS)Nc3>K|]\}}|j|fywr%)__code__)rfnc_keys r*rz@_CacheKeyTraversal.visit_with_context_options..s?ib%bkk5)?srkr(rqrrparentrrls r*visit_with_context_optionsz-_CacheKeyTraversal.visit_with_context_optionsxs?3???r,c<|t|j||fSr%)rrcrs r*visit_inspectablez$_CacheKeyTraversal.visit_inspectables '#,55h KLLr,ct|Sr%rrs r*visit_string_listz$_CacheKeyTraversal.visit_string_listsSzr,cP|t|tr|j||fS|fSr%r`r-rcrs r* visit_multiz_CacheKeyTraversal.visit_multis> c;/""8Z8     r,c4|tfd|DfS)Nc3fK|](}t|tr|jn|*ywr%rrrvrrls r*rz6_CacheKeyTraversal.visit_multi_list..s< "$ 4''*=s.1rrs ``r*visit_multi_listz#_CacheKeyTraversal.visit_multi_lists)       r,c:|sy|tfd|DfS)Nr&c3HK|]}tfd|Dyw)c3BK|]}|jywr%rcrs r*rzJ_CacheKeyTraversal.visit_has_cache_key_tuples...s&''*=Nr)rtup_elemrrls r*rz@_CacheKeyTraversal.visit_has_cache_key_tuples..s-   (s"rrs ``r*visit_has_cache_key_tuplesz-_CacheKeyTraversal.visit_has_cache_key_tupless/   !$    r,c:|sy|tfd|DfS)Nr&c3BK|]}|jywr%r rs r*rz>_CacheKeyTraversal.visit_has_cache_key_list..sL$%%h ;Lr rrs ``r*visit_has_cache_key_listz+_CacheKeyTraversal.visit_has_cache_key_lists&  LL L  r,c:|sy|tfd|DfS)Nr&c3ZK|]"}|jr|j$ywr%)rrcrs r*rz>_CacheKeyTraversal.visit_executable_options..s/))##Hj9s(+rrs ``r*visit_executable_optionsz+_CacheKeyTraversal.visit_executable_optionss-     r,c d|j||Dcgc] }t|c}|||Scc}wr%)rr)r(rqrrrrrlos r*visit_inspectable_listz)_CacheKeyTraversal.visit_inspectable_lists4,, 3/awqz/:  /s- c,|j|||||Sr%)rrs r*visit_clauseelement_tuplesz-_CacheKeyTraversal.visit_clauseelement_tupless".. c68Z  r,c h|sy|t|Dcgc]}|j||c}fScc}wNr&rkrc)r(rqrrrrrlrvs r*visit_fromclause_ordered_setz/_CacheKeyTraversal.visit_fromclause_ordered_set s:  M4&&x<M N  Ms/ c||sy|Dcgc]}|j||}}|tt|fScc}wrrcrkr)r(rqrrrrrlrv cache_keyss r*!visit_clauseelement_unordered_setz4_CacheKeyTraversal.visit_clauseelement_unordered_setsUBE :>D  * 5    z"    s9c||jfSr%)rrs r*visit_named_ddl_elementz*_CacheKeyTraversal.visit_named_ddl_element-s#((##r,c x|sy|t|Dcgc]\}}|j|||fc}}fScc}}wrr)r(rqrrrrrlclausestrvals r*visit_prefix_sequencez(_CacheKeyTraversal.visit_prefix_sequence7sT  +.&**8Z@&I   s6 c0tfd|DS)Nc 3K|]l\}}}}|j||jnd||jndtt|Dcgc] }|||f c}fnycc}wwr%r )rtargetonclausefrom_flagsr{rrls r*rz<_CacheKeyTraversal.visit_setup_join_tuple..Ts 15%%%h ; +++HjA(((:>F5MBSU3Z(BC  CsAA:A5(A:rrs ``r*visit_setup_join_tuplez)_CacheKeyTraversal.visit_setup_join_tupleLs! 58   r,c |sy|t|jDcgc]\\}}}|j||||fc}}}fScc}}}wr)rkitemsrc) r(rqrrrrrlr& dialect_nametexts r*visit_table_hint_listz(_CacheKeyTraversal.visit_table_hint_listfsl  9<  5. --h C$   s"A c ^|tt|Dcgc] }|||f c}fScc}wr%rkrr(rqrrrrrlr{s r*visit_plain_dictz#_CacheKeyTraversal.visit_plain_dicts.%F3K HS#s3x HIJJ Hs* cB|tfdtDfS)Nc 3K|]3}|tt|Dcgc] }|||fc}f5ycc}wwr%r6)rr2r{rrs r*rz;_CacheKeyTraversal.visit_dialect_options..s^ !!(.c,.?'@ #!#l"3C"89 sA< Ar6rs ` r*visit_dialect_optionsz(_CacheKeyTraversal.visit_dialect_optionss-   %+3K    r,cJ|tfdtDfS)Nc3LK|]}||jfywr%r )rr{rrlrrs r*rzE_CacheKeyTraversal.visit_string_clauseelement_dict..s/c#h--h CDs!$r6rs ` ``r*visit_string_clauseelement_dictz2_CacheKeyTraversal.visit_string_clauseelement_dicts+  !#;   r,c v|tfdt|Dcgc] }|||f c}DfScc}w)Nc3pK|]-\}}|t|tr|jn|f/ywr%rrr{rrrls r*rz=_CacheKeyTraversal.visit_string_multi_dict..sE C&e[9,,XzB"  s36r6r7s `` r*visit_string_multi_dictz*_CacheKeyTraversal.visit_string_multi_dictsG   ?ESk"JsCS?"J    #Ks6 cH|tfd|jDfS)Nc3JK|]\}}}|jywr%r )rkcol_rrls r*rzR_CacheKeyTraversal.visit_fromclause_canonical_column_collection..s,AsA""8Z8s #)rk _collectionrs ``r*,visit_fromclause_canonical_column_collectionz?_CacheKeyTraversal.visit_fromclause_canonical_column_collections+  !$   r,cd|t<yNTr&r6rs r*visit_unknown_structurez*_CacheKeyTraversal.visit_unknown_structures"r,c4|tfd|DfS)Nc3K|]9\}}t|dr|jn||jf;yw__clause_element__NhasattrrcrAs r*rz>_CacheKeyTraversal.visit_dml_ordered_values..sQ C #3(<=**8Z@ ((:>  ?Arrs ``r*visit_dml_ordered_valuesz+_CacheKeyTraversal.visit_dml_ordered_valuess)   #&    r,c8|tfdDfS)Nc3K|]9}t|dr|jn||jf;ywrPrR)rrErrlrrs r*rz6_CacheKeyTraversal.visit_dml_values..sQ  #1&:;((:>F))(J?  rTrrs ` ``r*visit_dml_valuesz#_CacheKeyTraversal.visit_dml_valuess)       r,cd|t<yrKrLrs r*visit_dml_multi_valuesz)_CacheKeyTraversal.visit_dml_multi_valuess"r,N) rqrrrrrrrrrlrr/r)4r1r2r3r<visit_has_cache_keyvisit_clauseelementrrhvisit_clauseelement_listrdvisit_annotations_keyrivisit_clauseelement_tuplerjvisit_memoized_select_entitiesr; visit_string visit_booleanvisit_operatorvisit_plain_objvisit_statement_hint_listr= visit_typer?visit_anon_namer>visit_propagate_attrsrrrrrrrrrrrr"r$r(r/r4r8r;r>rBrIrMrUrXrZr&r,r*r.r.cs1CB-0FF-@@ 1 H H55# L=>O!/!JO+@@@ @  @ - @ @MMM M  M - M M    -         -    "       -    (       -    *          -            -    &          -               -               -            -    ($$$ $  $ - $ $       -    *       -    4       -    2KKK K  K - K K       -    0       -           -    .       -    "       -          -    .       -    2       -   r,r.)rrrz'Iterable[Tuple[str, InternalTraversal]]rz Iterable[Any]r/r)? __future__renum itertoolsrtypingrrrrr r r r r rrrvisitorsrrrrrrr inspectionrr util.typingrr TYPE_CHECKINGrurrrr engine.interfacesr!r#Enumr5r6rAr8rkr;r<r=r>r?rr0r-rr MemoizedSlotsrryrr.rOr&r,r*rts# ! !**'% !" '''0<3X3    gj&9&9:GDMI $))   (0    S%S/) *      ($u-u-p  .  5+{55{D,>,>5T zT n" ":" " "J{-{| 23r,