
    ؄_5                     `   d Z ddlmZ ddlZddlmZ ddlmZ ddlmZ dd	lm	Z	  ej
        e          Zd
 ZdZdZ G d de          Z G d de          Z e            e_         G d de          Z G d de          Z G d de          Z G d de          Z G d dee          ZdS )z@Path tracking utilities, representing mapper graph traversals.

    )chainN   )class_mapper   )exc)
inspection)utilc                 6    t                               |           S N)PathRegistrydeserializepaths    a/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/orm/path_registry.py_unreduce_pathr      s    ##D)))    *_sa_defaultc                   $   e Zd ZdZdZdZdZd Zd Zd Z	d Z
dd	Zd
 Zed             Zd Zd Zd Zd Zed             Zed             Zed             Zed             Zd Zed             Zed             Zed             Zd Zd Zd ZdS )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.

     Fc                     	 |d uo| j         |j         k    S # t          $ r( t          j        dt	          |          z             Y dS w xY w)N1Comparison of PathRegistry to %r is not supportedFr   AttributeErrorr	   warntypeselfothers     r   __eq__zPathRegistry.__eq__>   si    	$@ej)@@ 	 	 	IC;;    55	    .AAc                     	 |d u p| j         |j         k    S # t          $ r( t          j        dt	          |          z             Y dS w xY w)Nr   Tr   r   s     r   __ne__zPathRegistry.__ne__H   sh    	D=;DI$;; 	 	 	IC;;    44	r!   c                 X    t                               d|| |           |||| j        f<   d S )Nzset '%s' on path '%s' to '%s')logdebugnatural_pathr   
attributeskeyvalues       r   setzPathRegistry.setR   s3    		13eDDD/4
C*+,,,r   c                 z    t                               d|| |           |                    || j        f|           d S )Nz$setdefault '%s' on path '%s' to '%s')r%   r&   
setdefaultr'   r(   s       r   r.   zPathRegistry.setdefaultV   s?    		8#tUKKKsD$56>>>>>r   Nc                 0    || j         f}||v r||         S |S r   )r'   r(   s       r   getzPathRegistry.getZ   s)    D%&*c?"Lr   c                 *    t          | j                  S r   lenr   r   s    r   __len__zPathRegistry.__len__a   s    49~~r   c                 *    t          | j                  S r   r2   r4   s    r   lengthzPathRegistry.lengthd   s    49~~r   c              #      K   | j         }t          dt          |          d          D ]}||         ||dz            fV  d S )Nr   r   r   )r   ranger3   )r   r   is      r   pairszPathRegistry.pairsh   sX      yq#d))Q'' 	' 	'Aq'4A;&&&&&	' 	'r   c                       fdt          dt           j                  d          D             D ]!}|j        r|                    |          r dS "dS )Nc                 *    g | ]}j         |         S r   r   ).0r:   r   s     r   
<listcomp>z0PathRegistry.contains_mapper.<locals>.<listcomp>n   s    NNNQDIaLNNNr   r   r   TF)r9   r3   r   	is_mapperisa)r   mapperpath_mappers   `  r   contains_mapperzPathRegistry.contains_mapperm   se    NNNN%3ty>>12M2MNNN 	 	K$ )@)@ tt5r   c                     || j         f|v S r   r   )r   r)   r*   s      r   containszPathRegistry.containst   s    TY:--r   c                 :    t           |                                 ffS r   )r   	serializer4   s    r   
__reduce__zPathRegistry.__reduce__w   s     0 0222r   c                     t          t          d fdt          dt                    d          D             D             fdt          dt                    d          D             d gz                       S )Nc                     g | ]	}|j         
S r   )class_)r>   ms     r   r?   z0PathRegistry._serialize_path.<locals>.<listcomp>~   s    MMMaMMMr   c                      g | ]
}|         S r   r   r>   r:   r   s     r   r?   z0PathRegistry._serialize_path.<locals>.<listcomp>~   s    #L#L#LDG#L#L#Lr   r   r   c                 *    g | ]}|         j         S r   )r*   rO   s     r   r?   z0PathRegistry._serialize_path.<locals>.<listcomp>   s    ===a===r   r   )listzipr9   r3   )clsr   s    `r   _serialize_pathzPathRegistry._serialize_pathz   s    MM#L#L#L#LU1c$ii5K5K#L#L#LMMM====eAs4yy!&<&<===F 
 
 	
r   c                 n    t          t          d |D                        }|r|d         
|dd         }|S )Nc                 n    g | ]2\  }}t          |          |t          |          j        |         nd f3S r   )r   attrs)r>   mclsr*   s      r   r?   z2PathRegistry._deserialize_path.<locals>.<listcomp>   s[        "c %T**? %T**055!	  r   r   )tupler   rS   r   ps      r   _deserialize_pathzPathRegistry._deserialize_path   s[      &*  

 
  	2!B$Ar   c                 ^      fdfd|                                 D             D             S )Nc                 N    g | ]!\  \  }}}|                     |          f|f"S r   )rT   r>   r*   r   r+   rS   s       r   r?   z7PathRegistry.serialize_context_dict.<locals>.<listcomp>   sI     
 
 
"dU 3&&t,,-u5
 
 
r   c                 \    g | ](\  }}t          |t                    r|d          v $||f)S )r   )
isinstancerZ   )r>   kvtokenss      r   r?   z7PathRegistry.serialize_context_dict.<locals>.<listcomp>   sJ     ' ' 'Aqa''' -.aDFNN A,:NNr   )items)rS   dict_re   s   ` `r   serialize_context_dictz#PathRegistry.serialize_context_dict   sZ    
 
 
 
' ' ' '!KKMM' ' '
 
 
 	
r   c                 D     t          j         fd|D                       S )Nc              3   p   K   | ]0\  \  }}}|t                              |                    f|fV  1d S r   )rZ   r]   r`   s       r   	<genexpr>z8PathRegistry.deserialize_context_dict.<locals>.<genexpr>   s_        
  
"dU 5..t44556> 
  
  
  
  
  
r   )r	   OrderedDict)rS   
serializeds   ` r   deserialize_context_dictz%PathRegistry.deserialize_context_dict   s>      
  
  
  
&0 
  
  
 
 
 	
r   c                 :    | j         }|                     |          S r   )r   rT   )r   r   s     r   rH   zPathRegistry.serialize   s    y##D)))r   c                 ^    |d S |                      |          }|                     |          S r   )r]   coercer[   s      r   r   zPathRegistry.deserialize   s/    <4!!$''zz!}}r   c                 d    |j         rt          | j        |          S t          | j        |          S r   )r@   CachingEntityRegistryrootSlotsEntityRegistry)rS   rB   s     r   
per_mapperzPathRegistry.per_mapper   s1     	9(6:::&sx888r   c                 :    t          j        d || j                  S )Nc                     | |         S r   r   prevnexts     r   <lambda>z%PathRegistry.coerce.<locals>.<lambda>   
    d4j r   )r	   reducert   )rS   raws     r   rq   zPathRegistry.coerce   s    {88#sxHHHr   c                     |                     dt          z             rt          | |          S |                     dt          z             rt          | j        |          S t          j        d|z            )N:zinvalid token: %s)endswith_WILDCARD_TOKENTokenRegistry_DEFAULT_TOKENrt   r   ArgumentError)r   tokens     r   r   zPathRegistry.token   so    >>#/00 	A u---^^C.011 	A E222#$7%$?@@@r   c                 :    t          j        d |j        |           S )Nc                     | |         S r   r   ry   s     r   r|   z&PathRegistry.__add__.<locals>.<lambda>   r}   r   )r	   r~   r   r   s     r   __add__zPathRegistry.__add__   s    {88%*dKKKr   c                 0    | j         j        d| j        dS )N())	__class____name__r   r4   s    r   __repr__zPathRegistry.__repr__   s    >222DIII>>r   r   )r   
__module____qualname____doc__	__slots__is_tokenis_rootr    r#   r,   r.   r0   r5   propertyr7   r;   rD   rF   rI   classmethodrT   r]   rh   rn   rH   r   rv   rq   r   r   r   r   r   r   r   r      s        2 IHG    5 5 5? ? ?        X' ' '
  . . .3 3 3 
 
 [
   [$ 
 
 [
 
 
 [
* * *   [ 9 9 [9 I I [IA A AL L L? ? ? ? ?r   r   c                   ,    e Zd ZdZdxZZdZdZdZd Z	dS )RootRegistryzXRoot registry, defers to mappers so that
    paths are maintained per-root-mapper.

    r   FTc                     |j         S r   )_path_registryr   entitys     r   __getitem__zRootRegistry.__getitem__   s    $$r   N)
r   r   r   r   r   r'   
has_entityis_aliased_classr   r   r   r   r   r   r      sI         
 D<JG% % % % %r   r   c                   ,    e Zd ZdZd ZdZdZd Zd ZdS )r   r   parentr   r'   c                 b    || _         || _        |j        |fz   | _        |j        |fz   | _        d S r   r   )r   r   r   s      r   __init__zTokenRegistry.__init__   s8    
K5(*	"/5(:r   FTc              #     K   | j         j        sV| j         j        sJ| j         j                                        D ])}t          | j         j         |         | j                  V  *d S | j         j        rR| j         j        j        rA| V  | j         j        j	        D ])}t          | j         j         |         | j                  V  *d S | V  d S r   )
r   r   r   rB   iterate_to_rootr   r   r   _is_with_polymorphic_with_polymorphic_entities)r   ents     r   generate_for_superclassesz'TokenRegistry.generate_for_superclasses   s      {+ 	DK4G 	{)99;; I I#DK$6s$;TZHHHHHHI I K(	"7	 JJJ{)D I I#DK$6s$;TZHHHHHHI I JJJJJr   c                     t                      r   )NotImplementedErrorr   s     r   r   zTokenRegistry.__getitem__   s    !###r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r      sR        ;I; ; ; JH  $ $ $ $ $r   r   c                       e Zd ZdZd Zd Zej        d             Zej        d             Z	e
d             Ze
d             Zd Zd	S )
PropRegistryFc                    t          j        |d                   }|}|j        r|j        r|j        |j                 x}}n|j        rf|j        r_|j        |j        v rQ|d                             |j                  }|j        |         }|j        r|j        |j                 }d| _        nP|}nM|j        rF|j        r?|j        |j        ur1|j        	                    |j                  r|j        |j                 }|| _
        || _        |j        |fz   | _        |j        |fz   | _        d|j        | j
        j        z   f| _        | j
        j        | _        d| j        f| _        d S )NrY   Tloader)r   inspectr   _use_mapper_pathr   with_polymorphic_mappers_entity_for_mapperrB   is_unnaturalrA   propr   r'   _wildcard_token_wildcard_path_loader_key_default_path_loader_key_loader_key)r   r   r   inspnatural_parentsubclass_entitys         r   r   zPropRegistry.__init__  s    !&*--$ 4	8(= 4	8&,mDK&@@F^^!2	8-2	8 t<<<$Rj;;DKHHO]?3F@ } (!'/E!F$(!!!'!	8%	8 ; ,, $]4;7N	K4')	*74'A K$)33*
& )-	(J%$di0r   c                 J    d                     d | j        D                       S )Nz -> c              3   4   K   | ]}t          |          V  d S r   )str)r>   elems     r   rk   z'PropRegistry.__str__.<locals>.<genexpr>J  s(      ;;3t99;;;;;;r   )joinr   r4   s    r   __str__zPropRegistry.__str__I  s%    {{;;;;;;;;r   c                 ,    t          | j        d          S )NrB   )hasattrr   r4   s    r   r   zPropRegistry.has_entityL  s    ty(+++r   c                     | j         j        S r   )r   rB   r4   s    r   r   zPropRegistry.entityP  s    yr   c                     | j         S r   r   r4   s    r   rB   zPropRegistry.mapperT  s
    {r   c                     | | j                  S r   r   r4   s    r   entity_pathzPropRegistry.entity_pathX  s    DK  r   c                 t    t          |t          t          f          r| j        |         S t	          | |          S r   )rb   intslicer   ru   r   s     r   r   zPropRegistry.__getitem__\  s5    fsEl++ 	59V$$&tV444r   N)r   r   r   r   r   r   r	   memoized_propertyr   r   r   rB   r   r   r   r   r   r   r      s        LF1 F1 F1P< < < 
, , , 
        X ! ! X!5 5 5 5 5r   r   c                   X    e Zd ZdZdZd Zed             Zed             Zd Z	e	Z
d ZdS )	AbstractEntityRegistryr   Tc                 p   || _         || _        |j        | _        || _        |j        |fz   | _        |j        rq| j        s|j        rc|j                            |j        d         j                  r|j        |j        fz   | _        d S |j        |j        d         j        fz   | _        d S | j        | _        d S )NrY   )	r*   r   r   r   r   r   rB   rA   r'   )r   r   r   s      r   r   zAbstractEntityRegistry.__init__h  s     & 7K6)+	 ; 
	*D1 
	*V5H 
	* }  !4R!8!?@@ $*$76=:J$J!!!$*$7'+2; %!!! !%	Dr   c                     | S r   r   r4   s    r   r   z"AbstractEntityRegistry.entity_path  s    r   c                 >    t          j        | j                  j        S r   )r   r   r   rB   r4   s    r   rB   zAbstractEntityRegistry.mapper  s    !$+..55r   c                     dS )NTr   r4   s    r   __bool__zAbstractEntityRegistry.__bool__  s    tr   c                 t    t          |t          t          f          r| j        |         S t	          | |          S r   )rb   r   r   r   r   r   s     r   r   z"AbstractEntityRegistry.__getitem__  s5    fsEl++ 	.9V$$f---r   N)r   r   r   r   r   r   r   r   rB   r   __nonzero__r   r   r   r   r   r   c  s        IJ* * *@   X 6 6 X6   K. . . . .r   r   c                       e Zd ZdZdS )ru   )r*   r   r   r   r   r'   N)r   r   r   r   r   r   r   ru   ru     s        IIIr   ru   c                       e Zd Zd Zd ZdS )rs   c                     t          |t          t          f          r| j        |         S t                              | |          S r   )rb   r   r   r   dictr   r   s     r   r   z!CachingEntityRegistry.__getitem__  s;    fsEl++ 	29V$$##D&111r   c                 0    t          | |          x| |<   }|S r   )r   )r   r*   items      r   __missing__z!CachingEntityRegistry.__missing__  s    'c222S	Dr   N)r   r   r   r   r   r   r   r   rs   rs     s2        2 2 2    r   rs   )r   	itertoolsr   loggingbaser    r   r   r	   	getLoggerr   r%   r   r   r   objectr   r   rt   r   r   r   ru   r   rs   r   r   r   <module>r      s                                   g!!* * * k? k? k? k? k?6 k? k? k?\% % % % %< % % % !LNN $ $ $ $ $L $ $ $>b5 b5 b5 b5 b5< b5 b5 b5J6. 6. 6. 6. 6.\ 6. 6. 6.r    0       2D     r   