U a<@s dZddlmZddlZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z eeZd d ZdZdZGddde ZGdddeZee_Gddde eZGdddeZGdddeZGdddeZGdddeZGdddeeZdS) z@Path tracking utilities, representing mapper graph traversals. )chainN) class_mapper)exc) inspection)util)visitors) HasCacheKeycCs t|SN) PathRegistry deserializepathr]C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\orm\path_registry.py_unreduce_pathsr*Z _sa_defaultc@seZdZdZdZdZdZdejj fgZ ddZ ddZ d d Z d d Zd4ddZddZddZeddZddZddZddZddZeddZed d!Zed"d#Zed$d%Zd&d'Zed(d)Zed*d+Zed,d-Z d.d/Z!d0d1Z"d2d3Z#d S)5r 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. rFrcCsDz|dk o|j|jkWStk r>tdt|YdSXdS)N1Comparison of PathRegistry to %r is not supportedFrAttributeErrorrwarntypeselfotherrrr__eq__CszPathRegistry.__eq__cCsDz|dkp|j|jkWStk r>tdt|YdSXdS)NrTrrrrr__ne__MszPathRegistry.__ne__cCs"td|||||||jf<dS)Nzset '%s' on path '%s' to '%s')logdebug natural_pathr attributeskeyvaluerrrsetWszPathRegistry.setcCs&td||||||jf|dS)Nz$setdefault '%s' on path '%s' to '%s')rr setdefaultr r!rrrr&[szPathRegistry.setdefaultNcCs"||jf}||kr||S|SdSr )r r!rrrget_s zPathRegistry.getcCs t|jSr lenrrrrr__len__fszPathRegistry.__len__cCst|Sr )idr*rrr__hash__iszPathRegistry.__hash__cCs t|jSr r(r*rrrlengthlszPathRegistry.lengthccs6|j}tdt|dD]}||||dfVqdS)Nrrr)rranger))rrirrrpairspszPathRegistry.pairscs@fddtdtjdDD]}|jr ||r dSq dS)Ncsg|]}j|qSrr.0r0r*rr vsz0PathRegistry.contains_mapper..rrTF)r/r)r is_mapperisa)rmapperZ path_mapperrr*rcontains_mapperus$zPathRegistry.contains_mappercCs||jf|kSr r)rr"r#rrrcontains|szPathRegistry.containscCst|ffSr )r serializer*rrr __reduce__szPathRegistry.__reduce__csRttddfddtdtdDDfddtdtdDdgS)NcSsg|] }|jqSr)class_)r3mrrrr4sz0PathRegistry._serialize_path..csg|] }|qSrrr2rrrr4srrcsg|]}|jqSr)r#r2rrrr4sr)listzipr/r))clsrrrr_serialize_paths &"zPathRegistry._serialize_pathcCs6ttdd|D}|r2|ddkr2|dd}|S)NcSs2g|]*\}}t||dk r(t|j|ndfqSr )rattrs)r3mclsr#rrrr4s z2PathRegistry._deserialize_path..r)tuplerr@rprrr_deserialize_paths  zPathRegistry._deserialize_pathcs$fddfdd|DDS)Ncs&g|]\\}}}||f|fqSr)rAr3r#rr$r@rrr4s z7PathRegistry.serialize_context_dict..cs.g|]&\}}t|tr|dkr||fqS)r) isinstancerE)r3kv)tokensrrr4s )items)r@Zdict_rNr)r@rNrserialize_context_dicts   z#PathRegistry.serialize_context_dictcstfdd|DS)Nc3s,|]$\\}}}|t|f|fVqdSr )rErHrIrJrr s z8PathRegistry.deserialize_context_dict..)r OrderedDict)r@Z serializedrrJrdeserialize_context_dictsz%PathRegistry.deserialize_context_dictcCs|j}||Sr )rrA)rrrrrr:szPathRegistry.serializecCs |dkr dS||}||Sr )rHcoercerFrrrr s zPathRegistry.deserializecCs"|jrt|j|St|j|SdSr )r5CachingEntityRegistryrootSlotsEntityRegistry)r@r7rrr per_mappers zPathRegistry.per_mappercCstdd||jS)NcSs||Sr rprevnextrrrz%PathRegistry.coerce..)rreducerV)r@rawrrrrTszPathRegistry.coercecCsD|dtrt||S|dtr2t|j|Std|dS)N:zinvalid token: %s)endswith_WILDCARD_TOKEN TokenRegistry_DEFAULT_TOKENrVr ArgumentError)rtokenrrrrfs   zPathRegistry.tokencCstdd|j|S)NcSs||Sr rrYrrrr\r]z&PathRegistry.__add__..)rr^rrrrr__add__szPathRegistry.__add__cCsd|jj|jfS)Nz%s(%r)) __class____name__rr*rrr__repr__szPathRegistry.__repr__)N)$ri __module__ __qualname____doc__ __slots__is_tokenis_rootr ZExtendedInternalTraversalZdp_has_cache_key_listZ_cache_key_traversalrrr%r&r'r+r-propertyr.r1r8r9r; classmethodrArHrPrSr:r rXrTrfrgrjrrrrr sJ            r c@s0eZdZdZdZdZZdZdZdZ ddZ dS) RootRegistryzXRoot registry, defers to mappers so that paths are maintained per-root-mapper. TrFcCs|jSr )Z_path_registryrentityrrr __getitem__szRootRegistry.__getitem__N) rirkrlrm inherit_cacherr has_entityis_aliased_classrprvrrrrrssrsc@s(eZdZdZiZddZeddZdS) PathTokenzcacheable string tokencCs t|fSr str)rZanon_mapZ bindparamsrrr_gen_cache_keyszPathToken._gen_cache_keycCs.||jkr|j|St||j|<}|SdSr )_internrz)r@Zstrvalueresultrrrinterns  zPathToken.internN)rirkrlrmr~r}rrrrrrrrzs rzc@s4eZdZdZdZddZdZdZddZdd Z d S) rc)rfparentrr TcCs6t|}||_||_|j|f|_|j|f|_dSr )rzrrfrrr )rrrfrrr__init__s  zTokenRegistry.__init__Fccs|jjs:|jjs:|jjD]}t|jj||jVqnF|jjrz|jjjrz|V|jjj D]}t|jj||jVq\n|VdSr ) rryrpr7Ziterate_to_rootrcrfruZ_is_with_polymorphicZ_with_polymorphic_entities)rentrrrgenerate_for_superclasses sz'TokenRegistry.generate_for_superclassescCs tdSr )NotImplementedErrorrtrrrrvszTokenRegistry.__getitem__N) rirkrlrnrwrrxrorrvrrrrrcsrcc@s`eZdZdZdZddZddZejddZ ejd d Z e d d Z e d dZ ddZdS) PropRegistryFTcCs t|d}|}|jr|jr0|j|j}}n|jr|jr|j|jkr|d|j}|j|}|jr||j|j}d|_q|}n2|jr|jr|j|jk r|j |jr|j|j}||_ ||_|j |f|_ |j |f|_ d|j |j j f|_|j j|_d|j f|_dS)NrDTloader)rinspectryZ_use_mapper_pathrZwith_polymorphic_mappersZ_entity_for_mapperr7 is_unnaturalr6proprr Z_wildcard_tokenZ_wildcard_path_loader_keyZ_default_path_loader_keyZ _loader_key)rrrZinspZnatural_parentZsubclass_entityrrrr!sH        zPropRegistry.__init__cCsddd|jDS)Nz -> css|]}t|VqdSr r{)r3elemrrrrQjsz'PropRegistry.__str__..)joinrr*rrr__str__iszPropRegistry.__str__cCs t|jdS)Nr7)hasattrrr*rrrrxlszPropRegistry.has_entitycCs|jjSr )rr7r*rrrrupszPropRegistry.entitycCs|jSr rur*rrrr7tszPropRegistry.mappercCs ||jSr rr*rrr entity_pathxszPropRegistry.entity_pathcCs&t|ttfr|j|St||SdSr )rKintslicerrWrtrrrrv|s zPropRegistry.__getitem__N)rirkrlrrwrrrZmemoized_propertyrxrurqr7rrvrrrrrsH    rc@sHeZdZdZdZddZeddZeddZd d Z e Z d d Z d S)AbstractEntityRegistryrTcCs||_||_|j|_||_|j|f|_|jrx|js:|jrx|j|jdjr`|j|jf|_q|j|jdjf|_n|j|_dS)NrD) r#rryrurrr7r6r )rrrurrrrs zAbstractEntityRegistry.__init__cCs|Sr rr*rrrrsz"AbstractEntityRegistry.entity_pathcCst|jjSr )rrrur7r*rrrr7szAbstractEntityRegistry.mappercCsdS)NTrr*rrr__bool__szAbstractEntityRegistry.__bool__cCs&t|ttfr|j|St||SdSr )rKrrrrrtrrrrvs z"AbstractEntityRegistry.__getitem__N) rirkrlrnrxrrqrr7r __nonzero__rvrrrrrs(  rc@seZdZdZdZdS)rWT)r#rryrurr N)rirkrlrwrnrrrrrWsrWc@s eZdZdZddZddZdS)rUTcCs(t|ttfr|j|St||SdSr )rKrrrdictrvrtrrrrvs z!CachingEntityRegistry.__getitem__cCst||||<}|Sr )r)rr#itemrrr __missing__sz!CachingEntityRegistry.__missing__N)rirkrlrwrvrrrrrrUsrU)rm itertoolsrloggingbaserrrrZsqlr Zsql.traversalsr getLoggerrirrrbrdr rsrVr|rzrcrrrWrrUrrrrs,        6#fA