L i:eUdZddlmZddlmZddlmZddlZddlZddl m Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZerEddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddlm'Z'ddlm(Z(ddl)m*Z*dd l+m,Z,dd!l-m.Z.dd"l-m/Z/dFd$Z0dGd%Z1n$ejdd&Z0ejdd'Z1ee Z3e4Z5ee5d(d)fZ6ee6d*fZ7ed(Z8eed)e4fZ9ejte;Zd-e?d.<d/Z@Gd0d#eZAGd1d2eAZBGd3d4eBZCeCeA_DGd5d6ejee4ZFGd7d8eAZGGd9d:eAZHGd;deIZJGd?d@e e e fZKGdAdBeIZLer dGdCZMdIdDZNyejdd'ZMejddEZNy)Jz>Path tracking utilities, representing mapper graph traversals.) annotations)reduce)chainN)Any)cast)Dict)Iterator)List)Optional)overload)Sequence)Tuple) TYPE_CHECKING)Union)base)insp_is_mapper_property)exc)util)visitors) HasCacheKey)_InternalEntityType)StrategizedProperty)Mapper)RelationshipProperty) AliasedInsp)_CacheKeyTraversalType) BindParameter)anon_map) _LiteralStar) TypeGuard PathRegistrycyNpaths b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/orm/path_registry.pyis_rootr*.cyr%r&r's r) is_entityr.0r+r,r*r._InternalEntityType[Any]StrategizedProperty[Any].c,tj|Sr%)r# deserializer's r)_unreduce_pathr3Ns  # #D ))r,*r!_WILDCARD_TOKEN _sa_defaultcveZdZUdZdZdZdZdZdZdZ de d<de d<de d<d e d <d e d <de jjfgZd e d<d/dZd/dZed0dZd1dZd2dZ d2dZ d3 d4dZd5dZd5dZed6dZed7dZed8dZe d9dZe d:dZ d;dZed5dZ dd"Zd?d#Ze d@d$Z!e dAd%Z"dBd&Z#e dCd'Z$ee dDd(Z%ee dEd)Z%e dFd*Z%e dGd+Z&dHd,Z'dId-Z(dId.Z)y)Jr#aRepresent query load paths and registry functions. Basically represents structures like: (, "orders", , "items", ) These structures are generated by things like query options (joinedload(), subqueryload(), etc.) and are used to compose keys stored in the query._attributes dictionary for various options. They are then re-composed at query compile/result row time as the query is formed and as rows are fetched, where they again serve to compose keys to look up options in the context.attributes dictionary, which is copied from query._attributes. The path structure has a limited amount of caching, where each "root" ultimately pulls from a fixed registry associated with the first mapper, that also contains elements for each of its property keys. However paths longer than two elements, which are the exception rather than the rule, are generated on an as-needed basis. r&Fbool is_unnatural_PathRepresentationr( natural_pathzOptional[PathRegistry]parent RootRegistryrootr_cache_key_traversalc |duxr|j|jk(S#t$r$tjdt |zYywxYw)N1Comparison of PathRegistry to %r is not supportedFr(_path_for_compareAttributeErrorrwarntypeselfothers r)__eq__zPathRegistry.__eq__sU $Me6M6M)M M  IIC;    !*A Ac |duxs|j|jk7S#t$r$tjdt |zYywxYw)NrATrBrGs r)__ne__zPathRegistry.__ne__sT D=HDII1H1H$H H  IIC;    rKc|jSr%r'rHs r)rCzPathRegistry._path_for_compares yyr,c |j|Sr%r')rHindexs r) odd_elementzPathRegistry.odd_elementsyyr,cVtjd|||||||jf<y)Nzset '%s' on path '%s' to '%s')logdebugr;rH attributeskeyvalues r)setzPathRegistry.sets* 13eD/4 C**+,r,cptjd||||j||jf|y)Nz$setdefault '%s' on path '%s' to '%s')rTrU setdefaultr;rVs r)r\zPathRegistry.setdefaults2 8#tUKsD$5$56>r,Nc4||jf}||vr||S|Sr%)r;rVs r)getzPathRegistry.gets+D%%& * c? "Lr,c,t|jSr%lenr(rOs r)__len__zPathRegistry.__len__s499~r,ct|Sr%)idrOs r)__hash__zPathRegistry.__hash__s $xr,cyr%r&rHentitys r) __getitem__zPathRegistry.__getitem__sCFr,cyr%r&rgs r)rizPathRegistry.__getitem__sz/PathRegistry._serialize_path..s3"#0B0BAHHQOs9;rrc3`K|]&}t|r |jn t|(ywr%)rrXr)rps r)rz/PathRegistry._serialize_path..s,5Q7AEESVCs,.rr%)rrsrtlistziptuplerura)clsr(r}_p_pathrxs r)_serialize_pathzPathRegistry._serialize_paths-t4.5 273w<2KLQgajL273w<2KLQgajL    MMs B# B(c dd}dd}tt|Dcgc]\}}|||||fc}}}|r |d|dd}|Scc}}w)Ncz|tjvrtj|dStj|SNT) configure) PathToken_internorm_base_inspect_mapped_class)mclss r)_deserialize_mapper_tokenzAPathRegistry._deserialize_path.._deserialize_mapper_tokens> y000..ttD  &&t,  r,c|y|tjvrtj|Stj|d}|J|j|Sr)rrrrattrs)rrXmps r)_deserialize_key_tokenz>PathRegistry._deserialize_path.._deserialize_key_tokensS{ ))) ((--33DDI~%~xx}$r,r)rrreturnr)rrrXrrr)rr)rr(rrrrXrs r)_deserialize_pathzPathRegistry._deserialize_path st  %   &*  "c2$7.tS9   2!BAsA c<|j}|j|Sr%)r(r)rHr(s r)rzPathRegistry.serialize0syy##D))r,cN|J|j|}|j|Sr%)rcoerce)rr(rs r)r2zPathRegistry.deserialize4s,  ! !$ 'zz!}r,cyr%r&rr{s r) per_mapperzPathRegistry.per_mapper:sGJr,cyr%r&rs r)rzPathRegistry.per_mapper>sJMr,cr|jrt|j|St|j|Sr%)rCachingEntityRegistryr>SlotsEntityRegistryrs r)rzPathRegistry.per_mapperBs/   (6: :&sxx8 8r,c8dd}t|||jS)Nc ||Sr%r&prevnext_s r)_redz!PathRegistry.coerce.._redM ; r,rr#r_PathElementTyperr#)rr>)rrawrs r)rzPathRegistry.coerceKs dC**r,c8dd}t||j|S)Nc ||Sr%r&rs r)rz"PathRegistry.__add__.._redTrr,r)rr()rHrIrs r)__add__zPathRegistry.__add__Ss dEJJ--r,cNddjd|jDdS)Nz ORM Path[z -> c32K|]}t|ywr%r)relems r)rz'PathRegistry.__str__..Zs>s4y&Gs])joinr(rOs r)__str__zPathRegistry.__str__Ys%6;;>YY&GGHJJr,cN|jjd|jdS)N()) __class____name__r(rOs r)__repr__zPathRegistry.__repr__\s$..))*!DII=::r,)rIrrr8rzOptional[_PathRepresentation])rQintrr/)rWDict[Any, Any]rXrrYrrNoner%)rWrrXrrYz Optional[Any]rr)rr)rh _StrPathTokenr TokenRegistry)rhrrr)rhslicerr:)rhr/rAbstractEntityRegistry)rhr0r PropRegistry)rhzTUnion[_StrPathToken, int, slice, _InternalEntityType[Any], StrategizedProperty[Any]]rzaUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry])rzOIterator[Tuple[_InternalEntityType[Any], Union[str, StrategizedProperty[Any]]]])r{ Mapper[Any]rr8)rWrrXrrr8)rr)r(r:r_SerializedPath)r(rrr:)rrr(rrr#)r{rrr)r{AliasedInsp[Any]rr)r{r/rr)rr:rr#)rIr#rr#)rr)*r __module__ __qualname____doc__ __slots__is_tokenr* has_entity is_propertyr.__annotations__rExtendedInternalTraversaldp_has_cache_key_listr?rJrMpropertyrCrRrZr\r^rbrer rirqryrrr classmethodrrrr2rrrrrr&r,r)r#r#Vsa2IHGJKI %% ""  33IIJ40 5?(?/2?;>? ?LP(/2;H FF ?? DD %.% %%. $ $ $&0 0.3  $!!F* JJ MM9-9 99++. K;r,c.eZdZUdZded<ded<ddZy) CreatesTokenr&r8rr*c|jdtr t||S|jdtrt|j|St j d|)N:zinvalid token: )endswithr5r_DEFAULT_TOKENr>r ArgumentError)rHtokens r)rzCreatesToken.tokenfs` >>Ao./ 0 u- - ^^a/0 1 E2 2##oeW$=> >r,N)rrrr)rrrrrrr&r,r)rr`sI M?r,rcReZdZdZdZdZdxZZdZdZ dZ dZ ddZ d dZ ese Zyy) r=zXRoot registry, defers to mappers so that paths are maintained per-root-mapper. r&TFc|tjvr5trt|tsJt |tj|S |j S#t$rtd|wxYw)Nz/invalid argument for RootRegistry.__getitem__: ) rrr isinstancerr_path_registryrD IndexErrorrgs r)_getitemzRootRegistry._getitemst Y&& &!&-888 y'8'8'@A A ,,,!  EfXN s AA-c|Sr%r&rOs r)_truncate_recursivez RootRegistry._truncate_recursives r,N)rhrrz,Union[TokenRegistry, AbstractEntityRegistry])rr=)rrrrr inherit_cacher(r;rrr*r9rrrrir&r,r)r=r=os[ IMD<JGL   5    r,r=cXeZdZUdZiZded< ddZed dZe d dZ y) rzcacheable string tokenzDict[str, PathToken]rct|fSr%r)rHr bindparamss r)_gen_cache_keyzPathToken._gen_cache_keysD |r,cyr%r&rOs r)rCzPathToken._path_for_comparesr,ct||jvr|j|St|x|j|<}|Sr%)rr)rstrvalueresults r)internzPathToken.interns: s{{ ";;x( (-6x-@ @CKK !FMr,N)r r rzList[BindParameter[Any]]rzTuple[Any, ...]r)rrrr) rrrrrrrrrCrrr&r,r)rrsU $&G !& .F  r,rc`eZdZUdZdZded<ded<d dZdZdZdd Z dd Z dd Z e se Z y y )r)rr<r(r;Trrrr<ctj|}||_||_|j|fz|_|j |fz|_yr%)rrrr<r(r;)rHr<rs r)__init__zTokenRegistry.__init__sG  '  KK5(* "//5(:r,Fc#K|j}t|r|ytrt|tsJ|j sE|j jD]'}t|j||j)y|j rotd|jjrO|td|jjD]'}t|j||j)y|ywNr)r<r*rrrrr{iterate_to_rootrrrrh_is_with_polymorphic_with_polymorphic_entitiesrHr<mp_entents r)generate_for_superclassesz'TokenRegistry.generate_for_superclassess 6?J  f&<= ==&& --779 G#FMM&$94::FF G  # #" #"# J"FMM(( D$FMM#$6 CC D JsDDc#^K|j}t|r|jytrt |t sJ|j jD]1}t|j||jj3|jrtd|jjrc|jtd|jjD]1}t|j||jj3y|jywr)r<r*r;rrrr{rrrrrrhrrrs r)"_generate_natural_for_superclassesz0TokenRegistry._generate_natural_for_superclassess 6?## #  f&<= ==mm335 PF f 5tzzBOO O P  # #" #"# ## #"FMM(( "&--"4djjANN ## #sD+D-c^ |j|S#t$r}t||d}~wwxYwr%)r( TypeErrorr)rHrherrs r)rzTokenRegistry._getitems5 399V$ $ 3x)s 2 3s , ',N)r<rrr)rzIterator[PathRegistry])rzIterator[_PathRepresentation]rhrrr)rrrrrrrrrr r rrrir&r,r)rrsO;IM  ;JH6$ &$:3   r,rc|eZdZUdZdZdZded<ded<ded< dd Zdd Ze dd Z dd Z e se Z y y )r) propr<r(r;rrhr{_wildcard_path_loader_key_default_path_loader_key _loader_keyr9Tr0rzOptional[Mapper[Any]]r{z"Optional[_InternalEntityType[Any]]rhctd|d}|}|jjxst|jj |_|j r |jr|j|jx}}n|j r|jru|j|jvr]|dj|j}|j|}|jr!|j|j}d|_nq|}nn|jrb|j rV|j|jur>|jj|jr|j|j}||_ ||_|j|fz|_ |j|fz|_ |j|_|j r;t"rt%|t&sJ|j(|_|j|_nd|_d|_d|j|jj*zf|_|jj.|_d|jf|_y)Nr/rTloader)rr<r9r8r{inheritsr_use_mapper_pathwith_polymorphic_mappers_entity_for_mapperr|rr(r;_links_to_entityr_is_relationshiprrrrh_wildcard_tokenrrr)rHr<rinspnatural_parentsubclass_entitys r)rzPropRegistry.__init__s .r ;17#MM66 $ MM " "; $$(=(=&,mmDKK&@ @F^  ! !-- t<<<8>r 8U8UVZVaVa8bO]]?3F@}}!'/E/E!F$(!!'  ! !%% ;;  ,#]]4;;7N  KK4') *774'A//  !$(<===++DK++DKDKDK    $))";"; ;* &)- (J(J%$d&7&78r,cd}tt|jddD]\}}||jus|}||S|j |jd|dz S)Nrrr) enumeratereversedr(rr)rHearliestrxrs r)rz PropRegistry._truncate_recursivetsl!(499Sb>":; HAu !   K;;tyyx!|_=> >r,c<|jJ||jSr%)rhrOs r) entity_pathzPropRegistry.entity_paths!{{&&&DKK  r,cdt|ttfr|j|St ||Sr%)rrrr(rrgs r)rzPropRegistry._getitems. fsEl +99V$ $&tV4 4r,N)r<rrr0)rrrr)rhz+Union[int, slice, _InternalEntityType[Any]]rzDUnion[AbstractEntityRegistry, _PathElementType, _PathRepresentation])rrrrrrrrrrr&rrrir&r,r)rrs} IMK "" !! ..X9,X94LX9t ?!!5A5 M5   r,rceZdZUdZdZdZded<ded<ded<ded < dd Zdd Ze dd Z e dd Z e ddZ ddZ ddZeseZyy)r)rXr<rr(rhr;T!Union[RootRegistry, PropRegistry]r<r/rXrhr8rc||_||_|j|_||_|j|fz|_|jr|js |j r|j j|jdj r |j|j fz|_y|j|jdjfz|_y|j|_y)Nr) rXr<rrhr(r9r{r|r;)rHr<rhs r)rzAbstractEntityRegistry.__init__s  & 7 7 KK6)+ $ ;;D11V5H5H}}  !4!4R!8!?!?@$*$7$76==:J$J!$*$7$7''+22;%!!% D r,cP|jj|jSr%)r<rrhrOs r)rz*AbstractEntityRegistry._truncate_recursives{{..0==r,c$|jdS)Nr)rRrOs r) root_entityz"AbstractEntityRegistry.root_entitys""r,c|Sr%r&rOs r)r&z"AbstractEntityRegistry.entity_paths r,c.|jjSr%)rhr{rOs r)r{zAbstractEntityRegistry.mappers{{!!!r,cy)NTr&rOs r)__bool__zAbstractEntityRegistry.__bool__sr,ct|ttfr|j|S|tj vrt |tj |St||Sr%)rrrr(rrrrrgs r)rzAbstractEntityRegistry._getitemsT fsEl +99V$ $ y(( ( y'8'8'@A Af- -r,Nr<r*rhr/r()rr/)rr#)rr)rr8)rhrrz:Union[_PathElementType, _PathRepresentation, PathRegistry])rrrrrr.rrrrr.r&r{r2rrrir&r,r)rrsIJI -- !! $$,*1,*),*\>##"".. C.   r,rceZdZdZy)rTN)rrrrr&r,r)rrs Mr,rceZdZddZddZy)_ERDictc||_yr%)registry)rHr9s r)rz_ERDict.__init__s   r,c<t|j|x||<}|Sr%)rr9)rHrXitems r) __missing__z_ERDict.__missing__s ' s;;S D r,N)r9r)rXrrr)rrrrr<r&r,r)r7r7s !r,r7cPeZdZdZdZ dfd ZddZddZeseZ xZ SxZ S) r)_cacheTcFt|||t||_yr%)superrr7r>)rHr<rhrs r)rzCachingEntityRegistry.__init__s (dm r,c:|jj||Sr%)r>pop)rHrXdefaults r)rBzCachingEntityRegistry.pops{{sG,,r,ct|ttfr|j|St|tr t ||S|j |Sr%)rrrr(rrr>rgs r)rzCachingEntityRegistry._getitemsE fsEl +99V$ $  * v. .;;v& &r,r4)rXrrCrrrr) rrrrrrrBrrri __classcell__)rs@r)rrs?IM$1$)$-'   r,rcyr%r&r's r)path_is_entityrG!s,/r,cyr%r&r's r)path_is_propertyrI%r+r,r)r(r#rzTypeGuard[RootRegistry])r(r#rz!TypeGuard[AbstractEntityRegistry]r)r(r#rzTypeGuard[PropRegistry])Or __future__r functoolsr itertoolsrloggingoperatortypingrrrr r r r r rrrrr_typingrrrsqlr sql.cache_keyrr interfacesrr{r relationshipsrrr sql.elementsr sql.visitorsr util.typingr!r"r*r. attrgetterrrrrr:rsrt getLoggerrrTr3r5rrr#rr=r>InspectionAttrrrrrrr7rrGrIr&r,r)r\sE" ,',/3!6,'*'CO"h!!),G###K0Is) -/II,c12""<="5)CS)H#IJg!*!$#G;;G;T ?< ?#<#L!N ''c.SLSlH<HV]\]@0 d38n2>00 *0M)X((5N*x**=9r,