
    -h@                     x   S r SSKJr  SSKrSSKJr  SSKJr  SSKJr  SS	KJ	r	  SS
K
Jr  SSKJr  \R                  " \5      rS rSrSr " S S\5      r " S S\5      r\" 5       \l         " S S\R.                  \\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\5      rg)z@Path tracking utilities, representing mapper graph traversals.

    )chainN   )base   )exc)
inspection)util)visitors)HasCacheKeyc                 ,    [         R                  U 5      $ N)PathRegistrydeserializepaths    qC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/orm/path_registry.py_unreduce_pathr      s    ##D))    *_sa_defaultc                   D   \ rS rSrSrSrSrSrS\R                  R                  4/rS rS r\S 5       rS	 rS
 rSS jrS rS r\S 5       rS rS rS rS r\S 5       r\S 5       r\S 5       r\S 5       rS r\S 5       r \S 5       r!\S 5       r"S r#S r$S r%Sr&g) r       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.

 Fr   c                      US L=(       a    U R                   UR                  :H  $ ! [         a%    [        R                  " S[        U5      -  5         gf = f)N1Comparison of PathRegistry to %r is not supportedFr   _path_for_compareAttributeErrorr	   warntypeselfothers     r   __eq__PathRegistry.__eq__C   sU    	$Me6M6M)MM 	IIC;  	   #& ,AAc                      US L =(       d    U R                   UR                  :g  $ ! [         a%    [        R                  " S[        U5      -  5         gf = f)Nr   Tr   r!   s     r   __ne__PathRegistry.__ne__M   sT    	D=HDII1H1H$HH 	IIC;  	r&   c                     U R                   $ r   r   r"   s    r   r   PathRegistry._path_for_compareW   s    yyr   c                 P    [         R                  SX U5        X1X R                  4'   g )Nzset '%s' on path '%s' to '%s')logdebugnatural_pathr"   
attributeskeyvalues       r   setPathRegistry.set[   s$    		13eD/4C**+,r   c                 l    [         R                  SX U5        UR                  X R                  4U5        g )Nz$setdefault '%s' on path '%s' to '%s')r.   r/   
setdefaultr0   r1   s       r   r8   PathRegistry.setdefault_   s,    		8#UKs$5$56>r   Nc                 2    X R                   4nX!;   a  X   $ U$ r   )r0   r1   s       r   getPathRegistry.getc   s#    %%&?"Lr   c                 ,    [        U R                  5      $ r   lenr   r+   s    r   __len__PathRegistry.__len__j   s    499~r   c                     [        U 5      $ r   )idr+   s    r   __hash__PathRegistry.__hash__m   s    $xr   c                 ,    [        U R                  5      $ r   r>   r+   s    r   lengthPathRegistry.lengthp   s    499~r   c              #   x   #    U R                   n[        S[        U5      S5       H  nX   XS-      4v   M     g 7fNr   r   r   )r   ranger?   )r"   r   is      r   pairsPathRegistry.pairst   s8     yyq#d)Q'A'4A;&& (s   8:c                     [        S[        U R                  5      S5       Vs/ s H  o R                  U   PM     sn H%  nUR                  R	                  U5      (       d  M%    g   gs  snf )Nr   r   TF)rK   r?   r   mapperisa)r"   rP   rL   path_mappers       r   contains_mapperPathRegistry.contains_mappery   sZ    273tyy>12MN2MQIIaL2MNK!!%%f-- O 	 Os   A(c                 "    X R                   4U;   $ r   r   )r"   r2   r3   s      r   containsPathRegistry.contains   s    YY:--r   c                 0    [         U R                  5       44$ r   )r   	serializer+   s    r   
__reduce__PathRegistry.__reduce__   s     0222r   c                    [        [        [        S[        U5      S5       Vs/ s H  o!U   PM	     sn Vs/ s H<  nUR                  (       d  UR
                  (       a  UR                  O
[        U5      PM>     sn[        S[        U5      S5       Vs/ s H1  nX   R                  (       a  X   R                  O[        X   5      PM3     snS /-   5      5      $ s  snf s  snf s  snf rJ   )
listziprK   r?   	is_mapperis_aliased_classclass_stris_propertyr3   )clsr   rL   ms       r   _serialize_pathPathRegistry._serialize_path   s     05QD	1/EF/E!1g/EFF "#0B0BAHHQOF #1c$i33 %)G$7$7DGKKc$'lJ3 &	

 	
 Gs   CAC8C$c                     S nS n[        [        U VVs/ s H  u  pEU" U5      U" XE5      4PM     snn6 5      nU(       a  US   c  USS nU$ s  snnf )Nc                 z    U [         R                  ;  a  [        R                  " U SS9$ [         R                  U    $ NT)	configure)	PathToken_internorm_base_inspect_mapped_class)mclss    r   _deserialize_mapper_tokenAPathRegistry._deserialize_path.<locals>._deserialize_mapper_token   s>    
 y000 ..ttD
 &&t,r   c                     Uc  g U[         R                  ;   a  [         R                  U   $ [        R                  " U SS9R                  U   $ rj   )rl   rm   rn   ro   attrs)rp   r3   s     r   _deserialize_key_token>PathRegistry._deserialize_path.<locals>._deserialize_key_token   sM    {	))) ((--55D% r   r   )tupler   )rd   r   rq   ru   rp   r3   ps          r   _deserialize_pathPathRegistry._deserialize_path   sw    		  &*
 &*	 2$7.t9 &*

 2!BAs   Ac           	         UR                  5        VVs/ s H*  u  p4[        U[        5      (       d  M  US   U;   d  M'  X44PM,     snn VVVs/ s H  u  u  pVnXPR                  U5      4U4PM     snnn$ s  snnf s  snnnf )Nr   )items
isinstancerx   rf   )rd   dict_tokenskvr3   r   r4   s           r   serialize_context_dict#PathRegistry.serialize_context_dict   s     "KKM')DAa' ,-aDFN )'
'"U &&t,-u5'
 	
'
s   A5A5A5#A;c                 D   ^  [         R                  " U 4S jU 5       5      $ )Nc              3   j   >#    U  H(  u  u  pnU[        TR                  U5      5      4U4v   M*     g 7fr   )rx   rz   ).0r3   r   r4   rd   s       r   	<genexpr>8PathRegistry.deserialize_context_dict.<locals>.<genexpr>   s9       
&0"U 5..t456>&0s   03)r	   OrderedDict)rd   
serializeds   ` r   deserialize_context_dict%PathRegistry.deserialize_context_dict   s#      
&0 
 
 	
r   c                 <    U R                   nU R                  U5      $ r   )r   rf   )r"   r   s     r   rY   PathRegistry.serialize   s    yy##D))r   c                 N    Uc  g U R                  U5      nU R                  U5      $ r   )rz   coerce)rd   r   ry   s      r   r   PathRegistry.deserialize   s(    <!!$'zz!}r   c                 |    UR                   (       a  [        U R                  U5      $ [        U R                  U5      $ r   )r_   CachingEntityRegistryrootSlotsEntityRegistry)rd   rP   s     r   
per_mapperPathRegistry.per_mapper   s-    (6::&sxx88r   c                 F    [         R                  " S XR                  5      $ )Nc                 
    X   $ r   r   prevnexts     r   <lambda>%PathRegistry.coerce.<locals>.<lambda>       djr   )r	   reducer   )rd   raws     r   r   PathRegistry.coerce   s    {{8#xxHHr   c                     UR                  S[        -   5      (       a  [        X5      $ UR                  S[        -   5      (       a  [        U R                  U5      $ [
        R                  " SU-  5      e)N:zinvalid token: %s)endswith_WILDCARD_TOKENTokenRegistry_DEFAULT_TOKENr   r   ArgumentError)r"   tokens     r   r   PathRegistry.token   s]    >>#/00 --^^C.011 E22##$7%$?@@r   c                 H    [         R                  " S UR                  U 5      $ )Nc                 
    X   $ r   r   r   s     r   r   &PathRegistry.__add__.<locals>.<lambda>   r   r   )r	   r   r   r!   s     r   __add__PathRegistry.__add__   s    {{8%**dKKr   c                 R    U R                   R                  < SU R                  < S3$ )N())	__class____name__r   r+   s    r   __repr__PathRegistry.__repr__   s    >>22DII>>r   r   )'r   
__module____qualname____firstlineno____doc__	__slots__is_tokenis_rootr
   ExtendedInternalTraversaldp_has_cache_key_list_cache_key_traversalr$   r(   propertyr   r5   r8   r;   r@   rD   rG   rM   rS   rV   rZ   classmethodrf   rz   r   r   rY   r   r   r   r   r   r   __static_attributes__r   r   r   r   r       s:   2 IHG 
33IIJ  5?  '
.3 
 
 ! !F 
 
 
 
*   9 9 I IAL?r   r   c                   6    \ rS rSrSrSrS=rrSrSr	Sr
S rSrg)RootRegistry   zPRoot registry, defers to mappers so that
paths are maintained per-root-mapper.

Tr   Fc                 h    U[         R                  ;   a  [         R                  U   $ UR                  $ r   )rl   rm   _path_registryr"   entitys     r   __getitem__RootRegistry.__getitem__   s-    Y&&&$$V,,(((r   N)r   r   r   r   r   inherit_cacher   r0   
has_entityr`   r   r   r   r   r   r   r   r      s-    
 MD<JG)r   r   c                   B    \ rS rSrSr0 rS r\S 5       r\	S 5       r
Srg)rl   i  zcacheable string tokenc                     [        U 5      4$ r   rb   )r"   anon_map
bindparamss      r   _gen_cache_keyPathToken._gen_cache_key  s    D	|r   c                     g r   r   r+   s    r   r   PathToken._path_for_compare  s    r   c                 v    XR                   ;   a  U R                   U   $ [        U5      =U R                   U'   nU$ r   )rm   rl   )rd   strvalueresults      r   internPathToken.intern  s8    {{";;x((-6x-@@CKK!FMr   r   N)r   r   r   r   r   rm   r   r   r   r   r   r   r   r   r   rl   rl     s7     G    r   rl   c                   6    \ rS rSrSrSrS rSrSrS r	S r
Srg	)
r   i  )r   parentr   r0   Tc                     [         R                  U5      nX l        Xl        UR                  U4-   U l        UR
                  U4-   U l        g r   )rl   r   r   r   r   r0   )r"   r   r   s      r   __init__TokenRegistry.__init__"  sC      '
KK5(*	"//5(:r   Fc              #   l  #    U R                   R                  (       dv  U R                   R                  (       d[  U R                   R                  R	                  5        H2  n[        U R                   R                   U   U R                  5      v   M4     g U R                   R                  (       a  U R                   R                  R                  (       a[  U v   U R                   R                  R                   H2  n[        U R                   R                   U   U R                  5      v   M4     g U v   g 7fr   )
r   r`   r   rP   iterate_to_rootr   r   r   _is_with_polymorphic_with_polymorphic_entities)r"   ents     r   generate_for_superclasses'TokenRegistry.generate_for_superclasses.  s     {{++DKK4G4G{{))99;#DKK$6$6s$;TZZHH < KK((""77J{{))DD#DKK$6$6s$;TZZHH E Js   D2D4c                     [        5       er   )NotImplementedErrorr   s     r   r   TokenRegistry.__getitem__<  s    !##r   )r0   r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s'    ;IM; JH$r   r   c                       \ rS rSrSrSrS rS r\R                  S 5       r
\R                  S 5       r\S 5       r\S	 5       rS
 rSrg)PropRegistryi@  FTc                 
   [         R                  " US   5      nUnUR                  (       a  UR                  (       a  UR                  UR                     =pGOUR                  (       a  UR
                  (       a|  UR                  UR
                  ;   ab  US   R                  UR                  5      nUR                  U   nUR                  (       a!  UR                  UR                     nSU l        OUnO~UR                  (       am  UR                  (       a\  UR                  UR                  LaC  UR                  R                  UR                  5      (       a  UR                  UR                     nX l
        Xl        UR                  U4-   U l        UR                  U4-   U l        SUR                  U R                  R                  -   4U l        U R                  R                  U l        SU R                  4U l        g )Nrw   Tloader)r   inspectr`   _use_mapper_pathr   with_polymorphic_mappers_entity_for_mapperrP   is_unnaturalrQ   propr   r0   _wildcard_token_wildcard_path_loader_key_default_path_loader_key_loader_key)r"   r   r   inspnatural_parentsubclass_entitys         r   r   PropRegistry.__init__D  s    !!&*-$$(=(=&,mmDKK&@@F^!!--t<<<$Rj;;DKKHO]]?3F@ }}!'/E/E!F$(!!'!!%%;;,,#]]4;;7N	KK4')	*774'A KK$))333*
& )-		(J(J%$d&7&78r   c                 F    SR                  S U R                   5       5      $ )Nz -> c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   )r   elems     r   r   'PropRegistry.__str__.<locals>.<genexpr>  s     ;3t99s   )joinr   r+   s    r   __str__PropRegistry.__str__  s    {{;;;;r   c                 .    U R                   R                  $ r   )r   _links_to_entityr+   s    r   r   PropRegistry.has_entity  s    yy)))r   c                 .    U R                   R                  $ r   )r   r   r+   s    r   r   PropRegistry.entity      yyr   c                 .    U R                   R                  $ r   )r   rP   r+   s    r   rP   PropRegistry.mapper  r  r   c                     X R                      $ r   )r   r+   s    r   entity_pathPropRegistry.entity_path  s    KK  r   c                 l    [        U[        [        45      (       a  U R                  U   $ [	        X5      $ r   )r~   intslicer   r   r   s     r   r   PropRegistry.__getitem__  s-    fsEl++99V$$&t44r   )r   r   r   r   r0   r   r   r   N)r   r   r   r   r   r   r   r  r	   memoized_propertyr   r   r   rP   r  r   r   r   r   r   r   r   @  sy    LMF9P< 
* * 
        ! !5r   r   c                   R    \ rS rSrSrSrS r\S 5       r\S 5       r	S r
\
rS rS	rg
)AbstractEntityRegistryi  r   Tc                    X l         Xl        UR                  U l        X l        UR                  U4-   U l        UR                  (       a  U R                  (       d  UR
                  (       a  UR                  R                  UR                  S   R                  5      (       a   UR                  UR                  4-   U l        g UR                  UR                  S   R                  4-   U l        g U R                  U l        g )Nrw   )	r3   r   r`   r   r   r   rP   rQ   r0   )r"   r   r   s      r   r   AbstractEntityRegistry.__init__  s     & 7 7KK6)+	 ;;D11V5H5H }}  !4!4R!8!?!?@@$*$7$76==:J$J!$*$7$7''+22; %! !%		Dr   c                     U $ r   r   r+   s    r   r  "AbstractEntityRegistry.entity_path  s    r   c                 V    [         R                  " U R                  5      R                  $ r   )r   r   r   rP   r+   s    r   rP   AbstractEntityRegistry.mapper  s    !!$++.555r   c                     g)NTr   r+   s    r   __bool__AbstractEntityRegistry.__bool__  s    r   c                     [        U[        [        45      (       a  U R                  U   $ U[        R
                  ;   a  [        U [        R
                  U   5      $ [        X5      $ r   )r~   r  r  r   rl   rm   r   r   r   s     r   r   "AbstractEntityRegistry.__getitem__  sS    fsEl++99V$$y((( y'8'8'@AA--r   )r   r`   r3   r0   r   r   N)r   r   r   r   r   r   r   r   r  rP   r   __nonzero__r   r   r   r   r   r  r    sK    IJ&*P   6 6 K.r   r  c                       \ rS rSrSrSrSrg)r   i  T)r3   r   r`   r   r   r0   r   N)r   r   r   r   r   r   r   r   r   r   r   r     s     MIr   r   c                   $    \ rS rSrSrS rS rSrg)r   i  Tc                     [        U[        [        45      (       a  U R                  U   $ [        R                  X5      $ r   )r~   r  r  r   dictr   r   s     r   r   !CachingEntityRegistry.__getitem__  s3    fsEl++99V$$##D11r   c                 $    [        X5      =X'   nU$ r   )r   )r"   r3   items      r   __missing__!CachingEntityRegistry.__missing__  s    '22	Dr   r   N)r   r   r   r   r   r   r,  r   r   r   r   r   r     s     M2r   r   ) r   	itertoolsr   logging r   rn   r   r   r	   sqlr
   sql.traversalsr   	getLoggerr   r.   r   r   r   r   r   r   InspectionAttrrb   rl   r   r   r  r   r(  r   r   r   r   <module>r5     s           (!* N?; N?b)< )( !N ''c * $L  $Fc5< c5L@.\ @.F0 2D r   