zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
U
¸ý°dÄbã@sUdZddlmZddlmZddlmZddlZddlZddl    m
Z
ddl    m Z ddl    m Z dd    l    m Z dd
l    mZdd l    mZdd l    mZdd l    mZddl    mZddl    mZddl    mZddlmZddlmZddlmZddlmZddlmZddlmZer¦ddlm 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/d#d$d%œd&d'„Z0d#d(d%œd)d*„Z1ne 2d'¡Z0e 2d*¡Z1ee
Z3ee4d+d,fZ5ee5d-fZ6ed+Z7eed,e4fZ8e 9e:¡Z;d.d#d%œd/d0„Z<d1Z=d2e>d3<d4Z?Gd5d#„d#eƒZ@Gd6d7„d7e@ƒZAGd8d9„d9eAƒZBeBƒe@_CGd:d;„d;ejDee4ƒZEGd<d=„d=e@ƒZFGd>d?„d?e@ƒZGGd@dA„dAeAƒZHGdBdC„dCeHƒZIGdDdE„dEe e
e
fƒZJGdFdG„dGeHƒZKerüd#d(d%œdHdI„ZLd#dJd%œdKdL„ZMne 2d*¡ZLe 2dM¡ZMdS)Nz@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)ÚMapperProperty)ÚMapper)ÚRelationshipProperty)Ú AliasedInsp)Ú_CacheKeyTraversalType)Ú BindParameter)Úanon_map)Ú _LiteralStar)Ú    TypeGuardÚ PathRegistryzTypeGuard[RootRegistry]©ÚpathÚreturncCsdS©N©©r$r'r'úSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/orm/path_registry.pyÚis_root0sr*z!TypeGuard[AbstractEntityRegistry]cCsdSr&r'r(r'r'r)Ú    is_entity3sr+ú_InternalEntityType[Any]úMapperProperty[Any].Ú_SerializedPathcCs
t |¡Sr&)r"Ú deserializer(r'r'r)Ú_unreduce_pathPsr0Ú*r Ú_WILDCARD_TOKENZ _sa_defaultc@s†eZdZUdZdZdZdZdZdZdZ    de
d<de
d<de
d<d    e
d
<d e
d <de j j fgZd e
d<dddœdd„Zdddœdd„Zeddœdd„ƒZdddddœdd„Zdddddœdd„Zdcddd!ddœd"d#„Zd$dœd%d&„Zd$dœd'd(„Zed)d*d+œd,d-„ƒZed$d.d+œd/d-„ƒZed0dd+œd1d-„ƒZed2d3d+œd4d-„ƒZed5d6d+œd7d-„ƒZd8d9d+œd:d-„Zed$dœd;d<„ƒZd=dœd>d?„Zd@ddAœdBdC„ZddddDœdEdF„ZddœdGdH„ZeddIdJœdKdL„ƒZ edIddJœdMdN„ƒZ!dIdœdOdP„Z"edIddJœdQdR„ƒZ#eed@dSdAœdTdU„ƒƒZ$eedVdWdAœdXdU„ƒƒZ$ed2d3dAœdYdU„ƒZ$edddZœd[d\„ƒZ%dddœd]d^„Z&d)dœd_d`„Z'd)dœdadb„Z(d S)dr"aÜRepresent query load paths and registry functions.
 
    Basically represents structures like:
 
    (<User mapper>, "orders", <Order mapper>, "items", <Item mapper>)
 
    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'FÚboolÚ is_unnaturalÚ_PathRepresentationr$Ú natural_pathzOptional[PathRegistry]ÚparentÚ RootRegistryÚrootrÚ_cache_key_traversalr)Úotherr%cCsDz|dk    o|j|jkWStk
r>t dt|ƒ¡YdSXdS)Nú1Comparison of PathRegistry to %r is not supportedF©r$Ú_path_for_compareÚAttributeErrorrÚwarnÚtype©Úselfr;r'r'r)Ú__eq__…sÿÿzPathRegistry.__eq__cCsDz|dkp|j|jkWStk
r>t dt|ƒ¡YdSXdS)Nr<Tr=rBr'r'r)Ú__ne__sÿÿzPathRegistry.__ne__úOptional[_PathRepresentation]©r%cCs|jSr&r(©rCr'r'r)r>™szPathRegistry._path_for_comparezDict[Any, Any]ÚNone)Ú
attributesÚkeyÚvaluer%cCs"t d|||¡||||jf<dS)Nzset '%s' on path '%s' to '%s')ÚlogÚdebugr6©rCrJrKrLr'r'r)ÚsetszPathRegistry.setcCs&t d|||¡| ||jf|¡dS)Nz$setdefault '%s' on path '%s' to '%s')rMrNÚ
setdefaultr6rOr'r'r)rQ¡szPathRegistry.setdefaultNz Optional[Any]cCs"||jf}||kr||S|SdSr&)r6rOr'r'r)Úget§s
zPathRegistry.getÚintcCs
t|jƒSr&©Úlenr$rHr'r'r)Ú__len__°szPathRegistry.__len__cCst|ƒSr&)ÚidrHr'r'r)Ú__hash__³szPathRegistry.__hash__ÚstrÚ TokenRegistry©Úentityr%cCsdSr&r'©rCr\r'r'r)Ú __getitem__¶szPathRegistry.__getitem__Ú_PathElementTypecCsdSr&r'r]r'r'r)r^ºsÚslicecCsdSr&r'r]r'r'r)r^¾sr,ÚAbstractEntityRegistrycCsdSr&r'r]r'r'r)r^Âsr-Ú PropRegistrycCsdSr&r'r]r'r'r)r^ÈszEUnion[str, int, slice, _InternalEntityType[Any], MapperProperty[Any]]zaUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry]cCs
tƒ‚dSr&)ÚNotImplementedErrorr]r'r'r)r^Ìs cCs
t|jƒSr&rTrHr'r'r)ÚlengthÛszPathRegistry.lengthzJIterator[Tuple[_InternalEntityType[Any], Union[str, MapperProperty[Any]]]]ccsFtt|jƒ}tt|ƒ}tdt|ƒdƒD]}||||dfVq&dS)Nrrr)rÚ_OddPathRepresentationr$Ú_EvenPathRepresentationÚrangerU)rCZodd_pathZ    even_pathÚir'r'r)Úpairsßs 
zPathRegistry.pairsú Mapper[Any])Úmapperr%csFtt|jƒ‰‡fdd„tdtˆƒdƒDƒD]}|j |¡r*dSq*dS)Ncsg|] }ˆ|‘qSr'r'©Ú.0rh©Ú_m_pathr'r)Ú
<listcomp>ësz0PathRegistry.contains_mapper.<locals>.<listcomp>rrTF)rrer$rgrUrkÚisa)rCrkZ path_mapperr'rnr)Úcontains_mapperés
 " zPathRegistry.contains_mapper)rJrKr%cCs||jf|kSr&r()rCrJrKr'r'r)ÚcontainsñszPathRegistry.containscCst| ¡ffSr&)r0Ú    serializerHr'r'r)Ú
__reduce__ôszPathRegistry.__reduce__r.r#c
svtt|ƒ‰tt|ƒ‰tttdd„‡fdd„tdtˆƒdƒDƒDƒƒtdd„‡fdd„td    tˆƒdƒDƒDƒƒd
ƒƒS) Ncss(|] }|js|jr|jnt|ƒVqdSr&)Ú    is_mapperÚis_aliased_classÚclass_rY)rmÚmr'r'r)Ú    <genexpr>þsÿz/PathRegistry._serialize_path.<locals>.<genexpr>csg|] }ˆ|‘qSr'r'rlrnr'r)rpsz0PathRegistry._serialize_path.<locals>.<listcomp>rrcss$|]}t|ƒr|jnt|ƒVqdSr&)rrKrY)rmÚpr'r'r)rzsÿcsg|] }ˆ|‘qSr'r'rl)Ú_p_pathr'r)rpsrr&)rrerfÚlistÚzipÚtuplergrU)Úclsr$r')ror|r)Ú_serialize_path÷s
 
þþüûÿzPathRegistry._serialize_pathcs^dddœdd„‰ddddœdd„‰tt‡‡fdd    „|DƒŽƒ}|rZ|d
dkrZ|d d
…}|S) Nr)Úmclsr%cSs"|tjkrtj|ddStj|S©NT)Ú    configure)Ú    PathTokenÚ_internÚorm_baseÚ_inspect_mapped_class)r‚r'r'r)Ú_deserialize_mapper_token sÿûzAPathRegistry._deserialize_path.<locals>._deserialize_mapper_token)r‚rKr%cSsH|dkr dS|tjkr tj|Stj|dd}|dk    s:t‚|j|SdSrƒ)r…r†r‡rˆÚAssertionErrorÚattrs)r‚rKÚmpr'r'r)Ú_deserialize_key_tokens
 
 z>PathRegistry._deserialize_path.<locals>._deserialize_key_tokencs"g|]\}}ˆ|ƒˆ||ƒf‘qSr'r')rmr‚rK©rr‰r'r)rp!sýþz2PathRegistry._deserialize_path.<locals>.<listcomp>éÿÿÿÿr)rr©r€r$r{r'rŽr)Ú_deserialize_path
s    
 ûÿÿ  zPathRegistry._deserialize_pathcCs|j}| |¡Sr&)r$r)rCr$r'r'r)rt.szPathRegistry.serializecCs |dk    s t‚| |¡}| |¡Sr&)rŠr‘Úcoercerr'r'r)r/2s 
zPathRegistry.deserializeÚCachingEntityRegistrycCsdSr&r'©r€rkr'r'r)Ú
per_mapper8szPathRegistry.per_mapperúAliasedInsp[Any]ÚSlotsEntityRegistrycCsdSr&r'r”r'r'r)r•=scCs"|jrt|j|ƒSt|j|ƒSdSr&)rvr“r9r—r”r'r'r)r•Bs )Úrawr%cCs ddddœdd„}t|||jƒS)Nr"r_©ÚprevÚnext_r%cSs||Sr&r'©ršr›r'r'r)Ú_redMsz!PathRegistry.coerce.<locals>._red)rr9)r€r˜rr'r'r)r’KszPathRegistry.coercecCs ddddœdd„}t||j|ƒS)Nr"r_r™cSs||Sr&r'rœr'r'r)rTsz"PathRegistry.__add__.<locals>._red)rr$)rCr;rr'r'r)Ú__add__SszPathRegistry.__add__cCsdd dd„|jDƒ¡›dS)Nz    ORM Path[z -> css|]}t|ƒVqdSr&©rY)rmÚelemr'r'r)rzZsz'PathRegistry.__str__.<locals>.<genexpr>ú])Újoinr$rHr'r'r)Ú__str__YszPathRegistry.__str__cCs|jj›d|j›dS)Nú(ú))Ú    __class__Ú__name__r$rHr'r'r)Ú__repr__\szPathRegistry.__repr__)N))r§Ú
__module__Ú __qualname__Ú__doc__Ú    __slots__Úis_tokenr*Ú
has_entityÚ is_propertyr+Ú__annotations__rZExtendedInternalTraversalZdp_has_cache_key_listr:rDrEÚpropertyr>rPrQrRrVrXr r^rdrirrrsruÚ classmethodrr‘rtr/r•r’ržr£r¨r'r'r'r)r"Xsz
 
ÿ 
 
ÿ    
#c@s2eZdZUdZded<ded<dddœdd    „Zd
S) Ú CreatesTokenr'r3rwr*rYrZ)Útokenr%cCsJ| dt›¡rt||ƒS| dt›¡r6t|j|ƒSt d|›¡‚dS)Nú:zinvalid token: )Úendswithr2rZÚ_DEFAULT_TOKENr9rÚ ArgumentError)rCr´r'r'r)r´fs
 
 zCreatesToken.tokenN)r§r©rªr¬r°r´r'r'r'r)r³`s
r³c@sVeZdZdZdZdZdZZdZdZ    dZ
dZ dddœdd    „Z dd
œd d „Z esRe Zd S)r8zXRoot registry, defers to mappers so that
    paths are maintained per-root-mapper.
 
    r'TFrz,Union[TokenRegistry, AbstractEntityRegistry]r[cCs\|tjkr,trt|tƒst‚t|tj|ƒSz|jWStk
rVt    d|›ƒ‚YnXdS)Nz/invalid argument for RootRegistry.__getitem__: )
r…r†rÚ
isinstancerYrŠrZZ_path_registryr?Ú
IndexErrorr]r'r'r)Ú_getitems
ÿzRootRegistry._getitemrGcCs|Sr&r'rHr'r'r)Ú_truncate_recursiveŽsz RootRegistry._truncate_recursiveN)r§r©rªr«r¬Ú inherit_cacher$r6r®rwr*r4r»r¼rr^r'r'r'r)r8osr8c@sVeZdZUdZiZded<ddddœdd    „Zed
d œd d „ƒZe    dddœdd„ƒZ
dS)r…zcacheable string tokenzDict[str, PathToken]r†rzList[BindParameter[Any]]zTuple[Any, ...])rÚ
bindparamsr%cCs
t|ƒfSr&rŸ)rCrr¾r'r'r)Ú_gen_cache_keyszPathToken._gen_cache_keyrFrGcCsdSr&r'rHr'r'r)r>¢szPathToken._path_for_comparerY)Ústrvaluer%cCs.||jkr|j|St|ƒ|j|<}|SdSr&)r†r…)r€rÀÚresultr'r'r)Úintern¦s
 
zPathToken.internN) r§r©rªr«r†r°r¿r±r>r²rÂr'r'r'r)r…˜s
 r…c@sdeZdZUdZdZded<ded<dddœdd    „Zd
ZdZd d œd d„Z    dddœdd„Z
e s`e
Z dS)rZ)r´r7r$r6TrYr´r³r7)r7r´cCs6t |¡}||_||_|j|f|_|j|f|_dSr&)r…rÂr´r7r$r6)rCr7r´r'r'r)Ú__init__·s
 
zTokenRegistry.__init__FzIterator[PathRegistry]rGccs¤|j}t|ƒr|VdStr*t|tƒs*t‚|jsV|j ¡D]}t    |j||j
ƒVq:nJ|jršt d|j ƒj rš|Vt d|j ƒjD]}t    |j||j
ƒVq~n|VdS)Nr–)r7r*rr¹rarŠrwrkZiterate_to_rootrZr´rr\Z_is_with_polymorphicZ_with_polymorphic_entities)rCr7Zmp_entÚentr'r'r)Úgenerate_for_superclassesÃs.ÿþþÿ
z'TokenRegistry.generate_for_superclassesrr[c
Cs@z |j|WStk
r:}zt|›ƒ|‚W5d}~XYnXdSr&)r$Ú    TypeErrorrº)rCr\Úerrr'r'r)r»Ýs zTokenRegistry._getitemN) r§r©rªr¬r½r°rÃr®r­rÅr»rr^r'r'r'r)rZ¯s
rZc@szeZdZUdZdZdZded<ded<ded<d    dd
œd d „Zdd œdd„Ze    d    d œdd„ƒZ
dddœdd„Z e sve Z dS)rb) Úpropr7r$r6r®r\rkÚ_wildcard_path_loader_keyÚ_default_path_loader_keyÚ _loader_keyr4Tr-rÈzOptional[Mapper[Any]]rkz"Optional[_InternalEntityType[Any]]r\ra)r7rÈcCsdtd|dƒ}|}|jjr"d|_nd|_|jr4|jrF|j|j}}n„|jr˜|jr˜|j|jkr˜|d |j¡}|j|}|jr’|j|j}d|_qÊ|}n2|jrÊ|jrÊ|j|jk    rÊ|j |j¡rÊ|j|j}||_    ||_|j
|f|_
|j |f|_ |j |_ |jr*trt|tƒst‚|j|_|j|_n d|_d|_d|j
|j    jf|_|j    j|_d|j f|_dS)Nr,rTFÚloader)rr7r4rwZ_use_mapper_pathZwith_polymorphic_mappersZ_entity_for_mapperrkrqrÈr$r6Z_links_to_entityr®Z_is_relationshiprr¹rrŠr\Z_wildcard_tokenrÉrÊrË)rCr7rÈZinspZnatural_parentZsubclass_entityr'r'r)rÃüs^ ÿþ
ý
  ÿþÿý û 
 þ
zPropRegistry.__init__rGcCs\d}tt|jdd…ƒƒD]\}}||jkr|}q|dkr>|S| |jd|d …¡SdS)Nrrr)Ú    enumerateÚreversedr$rÈr’)rCZearliestrhr´r'r'r)r¼Vs
z PropRegistry._truncate_recursivecCs|jdk    st‚||jSr&)r\rŠrHr'r'r)Ú entity_pathaszPropRegistry.entity_pathz+Union[int, slice, _InternalEntityType[Any]]zDUnion[AbstractEntityRegistry, _PathElementType, _PathRepresentation]r[cCs&t|ttfƒr|j|St||ƒSdSr&)r¹rSr`r$r—r]r'r'r)r»fs
zPropRegistry._getitemN)r§r©rªr¬r½r¯r°rÃr¼r±rÏr»rr^r'r'r'r)rbçs
 Z rbc@s´eZdZUdZdZdZded<ded<ded<ded    <ddd
œd d „Zdd œdd„Ze    dd œdd„ƒZ
e    dd œdd„ƒZ e    dd œdd„ƒZ dd œdd„Z dddœdd„Zes°eZdS) ra)rKr7rwr$r\r6Tú!Union[RootRegistry, PropRegistry]r7r,rKr\r3rw©r7r\cCs„||_||_|j|_||_|j|f|_|jrx|js:|jrx|j |jdj¡r`|j|jf|_q€|j|jdjf|_n|j|_dS)Nr)    rKr7rwr\r$r4rkrqr6©rCr7r\r'r'r)rÄs
ÿ
zAbstractEntityRegistry.__init__rGcCs|j ¡|jSr&)r7r¼r\rHr'r'r)r¼¯sz*AbstractEntityRegistry._truncate_recursivecCstd|jdƒS)Nr,r)rr$rHr'r'r)Ú root_entity²sz"AbstractEntityRegistry.root_entityr"cCs|Sr&r'rHr'r'r)r϶sz"AbstractEntityRegistry.entity_pathrjcCs|jjSr&)r\rkrHr'r'r)rkºszAbstractEntityRegistry.mappercCsdS)NTr'rHr'r'r)Ú__bool__¾szAbstractEntityRegistry.__bool__rz:Union[_PathElementType, _PathRepresentation, PathRegistry]r[cCs@t|ttfƒr|j|S|tjkr2t|tj|ƒSt||ƒSdSr&)r¹rSr`r$r…r†rZrbr]r'r'r)r»Ás
 
 
zAbstractEntityRegistry._getitemN)r§r©rªr¬r®r+r°rÃr¼r±rÓrÏrkrÔr»rr^r'r'r'r)rars&
    +
rac@seZdZdZdS)r—TN)r§r©rªr½r'r'r'r)r—Ïsr—c@s*eZdZddœdd„Zdddœdd    „Zd
S) Ú_ERDictr“©ÚregistrycCs
||_dSr&rÖ)rCr×r'r'r)rÃÖsz_ERDict.__init__rrb)rKr%cCst|j|ƒ||<}|Sr&)rbr×)rCrKÚitemr'r'r)Ú __missing__Ùsz_ERDict.__missing__N)r§r©rªrÃrÙr'r'r'r)rÕÕsrÕcsVeZdZdZdZdddœ‡fdd„ Zdddd    œd
d „Zddd œd d„ZesNeZ    ‡Z
S)r“)Ú_cacheTrÐr,rÑcstƒ ||¡t|ƒ|_dSr&)ÚsuperrÃrÕrÚrÒ©r¦r'r)rÃçszCachingEntityRegistry.__init__r)rKÚdefaultr%cCs|j ||¡Sr&)rÚÚpop)rCrKrÝr'r'r)rÞïszCachingEntityRegistry.popr[cCs:t|ttfƒr|j|St|tƒr,t||ƒS|j|SdSr&)r¹rSr`r$r…rZrÚr]r'r'r)r»òs
 
 
 
zCachingEntityRegistry._getitem) r§r©rªr¬r½rÃrÞr»rr^Ú __classcell__r'r'rÜr)r“ßsr“cCsdSr&r'r(r'r'r)Úpath_is_entitysràzTypeGuard[PropRegistry]cCsdSr&r'r(r'r'r)Úpath_is_propertysrár¯)Nr«Ú
__future__rÚ    functoolsrÚ    itertoolsrÚloggingÚoperatorÚtypingrrrrr    r
r r r rrÚrr‡Ú_typingrrrZsqlrZ sql.cache_keyrrZ
interfacesrrkrZ relationshipsrrrZ sql.elementsrZ sql.visitorsrZ util.typingr r!r*r+Ú
attrgetterr.rYr_r5rerfÚ    getLoggerr§rMr0r2r°r·r"r³r8r9ZInspectionAttrr…rZrbrar—rÕr“ràrár'r'r'r)Ú<module>s†                              
 
ÿ
 
 
&8 ]