a
    [g<e                     @  s  U d Z ddlmZ ddlmZ ddlmZ ddl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 dd
l	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ erddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddlm'Z' ddlm(Z( ddl)m*Z* dd l+m,Z, dd!l-m.Z. dd"l-m/Z/ d#d$d%d&d'Z0d#d(d%d)d*Z1ne2d'Z0e2d*Z1ee
 Z3e4Z5ee5d+d,f Z6ee6d-f Z7ed+ Z8eed,e4f  Z9e:e;Z<d.d#d%d/d0Z=d1Z>d2e?d3< d4Z@G d5d# d#eZAG d6d7 d7eAZBG d8d9 d9eBZCeC eA_DG d:d; d;ejEee4ZFG d<d= d=eAZGG d>d? d?eAZHG d@dA dAeBZIG dBdC dCeIZJG dDdE dEee
e
f ZKG dFdG dGeIZLer d#d(d%dHdIZMd#dJd%dKdLZNne2d*ZMe2dMZNdS )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)StrategizedProperty)Mapper)RelationshipProperty)AliasedInsp)_CacheKeyTraversalType)BindParameter)anon_map)_LiteralStar)	TypeGuardPathRegistryzTypeGuard[RootRegistry]pathreturnc                 C  s   d S N r$   r'   r'   j/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/orm/path_registry.pyis_root0       r*   z!TypeGuard[AbstractEntityRegistry]c                 C  s   d S r&   r'   r(   r'   r'   r)   	is_entity2   r+   r,   _InternalEntityType[Any]StrategizedProperty[Any]._SerializedPathc                 C  s
   t | S r&   )r"   deserializer(   r'   r'   r)   _unreduce_pathP   s    r1   *r    _WILDCARD_TOKENZ_sa_defaultc                   @  s  e Zd ZU dZdZdZdZdZdZdZ	de
d< de
d< de
d< d	e
d
< de
d< dejjfgZde
d< dddddZdddddZeddddZdddddZddddd d!d"Zddddd d#d$Zdgddd&dd d'd(Zddd)d*Zddd+d,Zed-d.d/d0d1Zedd2d/d3d1Zed4dd/d5d1Zedd6d/d7d1Zed8d9d/d:d1Zd;d<d/d=d1Zeddd>d?Zd@ddAdBZdCddDdEdFZddddGdHdIZdddJdKZe ddLdMdNdOZ!e dLddMdPdQZ"dLddRdSZ#e dLd dMdTdUZ$ee dCdVdDdWdXZ%ee dYdZdDd[dXZ%e dd6dDd\dXZ%e dd d]d^d_Z&d d dd`daZ'dbddcddZ(dbddedfZ)d%S )hr"   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_pathzOptional[PathRegistry]parentRootRegistryrootr   _cache_key_traversalr   )otherr%   c                 C  sB   z|d uo| j |jkW S  ty<   tdt|  Y dS 0 d S )N1Comparison of PathRegistry to %r is not supportedFr$   _path_for_compareAttributeErrorr   warntypeselfr<   r'   r'   r)   __eq__   s    zPathRegistry.__eq__c                 C  sB   z|d u p| j |jkW S  ty<   tdt|  Y dS 0 d S )Nr=   Tr>   rC   r'   r'   r)   __ne__   s    zPathRegistry.__ne__Optional[_PathRepresentation]r%   c                 C  s   | j S r&   r(   rD   r'   r'   r)   r?      s    zPathRegistry._path_for_compareintr-   )indexr%   c                 C  s
   | j | S r&   r(   )rD   rK   r'   r'   r)   odd_element   s    zPathRegistry.odd_elementzDict[Any, Any]None)
attributeskeyvaluer%   c                 C  s"   t d|| | |||| jf< d S )Nzset '%s' on path '%s' to '%s')logdebugr7   rD   rN   rO   rP   r'   r'   r)   set   s    zPathRegistry.setc                 C  s&   t d|| | ||| jf| d S )Nz$setdefault '%s' on path '%s' to '%s')rQ   rR   
setdefaultr7   rS   r'   r'   r)   rU      s    zPathRegistry.setdefaultNzOptional[Any]c                 C  s"   || j f}||v r|| S |S d S r&   )r7   rS   r'   r'   r)   get   s    
zPathRegistry.getc                 C  s
   t | jS r&   lenr$   rI   r'   r'   r)   __len__   s    zPathRegistry.__len__c                 C  s   t | S r&   )idrI   r'   r'   r)   __hash__   s    zPathRegistry.__hash___StrPathTokenTokenRegistryentityr%   c                 C  s   d S r&   r'   rD   r_   r'   r'   r)   __getitem__   s    zPathRegistry.__getitem___PathElementTypec                 C  s   d S r&   r'   r`   r'   r'   r)   ra      s    slicec                 C  s   d S r&   r'   r`   r'   r'   r)   ra      s    AbstractEntityRegistryc                 C  s   d S r&   r'   r`   r'   r'   r)   ra      s    r.   PropRegistryc                 C  s   d S r&   r'   r`   r'   r'   r)   ra      s    zTUnion[_StrPathToken, int, slice, _InternalEntityType[Any], StrategizedProperty[Any]]zaUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry]c                 C  s
   t  d S r&   )NotImplementedErrorr`   r'   r'   r)   ra      s    c                 C  s
   t | jS r&   rW   rI   r'   r'   r)   length   s    zPathRegistry.lengthzOIterator[Tuple[_InternalEntityType[Any], Union[str, StrategizedProperty[Any]]]]c                 c  sF   t t| j}t t|}tdt|dD ]}|| ||d  fV  q&d S )Nr   r   r   )r   _OddPathRepresentationr$   _EvenPathRepresentationrangerX   )rD   Zodd_pathZ	even_pathir'   r'   r)   pairs   s    
zPathRegistry.pairsMapper[Any])mapperr%   c                   sF   t t| j  fddtdt dD D ]}|j|r* dS q*dS )Nc                   s   g | ]} | qS r'   r'   .0rk   _m_pathr'   r)   
<listcomp>   r+   z0PathRegistry.contains_mapper.<locals>.<listcomp>r   r   TF)r   rh   r$   rj   rX   rn   isa)rD   rn   Zpath_mapperr'   rq   r)   contains_mapper   s
    "zPathRegistry.contains_mapper)rN   rO   r%   c                 C  s   || j f|v S r&   r(   )rD   rN   rO   r'   r'   r)   contains   s    zPathRegistry.containsc                 C  s   t |  ffS r&   )r1   	serializerI   r'   r'   r)   
__reduce__   s    zPathRegistry.__reduce__r/   r#   c              
     sv   t t| t t|tttdd  fddtdt dD D tdd fddtd	tdD D d
 S )Nc                 s  s(   | ] }|j s|jr|jnt|V  qd S r&   )	is_mapperis_aliased_classclass_str)rp   mr'   r'   r)   	<genexpr>  s   z/PathRegistry._serialize_path.<locals>.<genexpr>c                   s   g | ]} | qS r'   r'   ro   rq   r'   r)   rs     r+   z0PathRegistry._serialize_path.<locals>.<listcomp>r   r   c                 s  s$   | ]}t |r|jnt|V  qd S r&   )r   rO   r|   )rp   pr'   r'   r)   r~     s   c                   s   g | ]} | qS r'   r'   ro   )_p_pathr'   r)   rs     r+   r   r&   )r   rh   ri   listziptuplerj   rX   )clsr$   r'   )rr   r   r)   _serialize_path   s    

zPathRegistry._serialize_pathc                   s^   ddddddddddd t t fdd	|D  }|rZ|d
 d u rZ|dd
 }|S )Nr   )mclsr%   c                 S  s"   | t jvrtj| ddS t j|  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   rO   r%   c                 S  sH   |d u rd S |t jv r t j| S tj| dd}|d us:J |j| S d S r   )r   r   r   r   attrs)r   rO   mpr'   r'   r)   _deserialize_key_token  s    

z>PathRegistry._deserialize_path.<locals>._deserialize_key_tokenc                   s"   g | ]\}}| ||fqS r'   r'   )rp   r   rO   r   r   r'   r)   rs   %  s   z2PathRegistry._deserialize_path.<locals>.<listcomp>r   )r   r   r   r$   r   r'   r   r)   _deserialize_path  s    	
zPathRegistry._deserialize_pathc                 C  s   | j }| |S r&   )r$   r   )rD   r$   r'   r'   r)   rw   2  s    zPathRegistry.serializec                 C  s    |d usJ |  |}| |S r&   )r   coercer   r'   r'   r)   r0   6  s    
zPathRegistry.deserializeCachingEntityRegistryc                 C  s   d S r&   r'   r   rn   r'   r'   r)   
per_mapper<  s    zPathRegistry.per_mapperAliasedInsp[Any]SlotsEntityRegistryc                 C  s   d S r&   r'   r   r'   r'   r)   r   @  s    c                 C  s"   |j rt| j|S t| j|S d S r&   )ry   r   r:   r   r   r'   r'   r)   r   D  s    )rawr%   c                 C  s    dddddd}t ||| jS )Nr"   rb   prevnext_r%   c                 S  s   | | S r&   r'   r   r   r'   r'   r)   _redO  s    z!PathRegistry.coerce.<locals>._red)r   r:   )r   r   r   r'   r'   r)   r   M  s    zPathRegistry.coercec                 C  s    dddddd}t ||j| S )Nr"   rb   r   c                 S  s   | | S r&   r'   r   r'   r'   r)   r   V  s    z"PathRegistry.__add__.<locals>._red)r   r$   )rD   r<   r   r'   r'   r)   __add__U  s    zPathRegistry.__add__r|   c                 C  s   dd dd | jD  dS )Nz	ORM Path[z -> c                 s  s   | ]}t |V  qd S r&   r|   )rp   elemr'   r'   r)   r~   \  r+   z'PathRegistry.__str__.<locals>.<genexpr>])joinr$   rI   r'   r'   r)   __str__[  s    zPathRegistry.__str__c                 C  s   | j j d| jdS )N())	__class____name__r$   rI   r'   r'   r)   __repr__^  s    zPathRegistry.__repr__)N)*r   
__module____qualname____doc__	__slots__is_tokenr*   
has_entityis_propertyr,   __annotations__r   ZExtendedInternalTraversalZdp_has_cache_key_listr;   rE   rF   propertyr?   rL   rT   rU   rV   rY   r[   r   ra   rg   rl   ru   rv   rx   classmethodr   r   rw   r0   r   r   r   r   r   r'   r'   r'   r)   r"   X   s|   



 	
#c                   @  s2   e Zd ZU dZded< ded< ddddd	Zd
S )CreatesTokenr'   r4   rz   r*   r\   r]   )tokenr%   c                 C  sJ   | dt rt| |S | dt r6t| j|S td| d S )N:zinvalid token: )endswithr3   r]   _DEFAULT_TOKENr:   r   ArgumentError)rD   r   r'   r'   r)   r   h  s
    
zCreatesToken.tokenN)r   r   r   r   r   r   r'   r'   r'   r)   r   b  s   
r   c                   @  sV   e Zd ZdZdZdZd ZZdZdZ	dZ
dZddddd	Zd d
ddZesReZdS )r9   zXRoot registry, defers to mappers so that
    paths are maintained per-root-mapper.

    r'   TFr   z,Union[TokenRegistry, AbstractEntityRegistry]r^   c                 C  sZ   |t jv r,trt|tsJ t| t j| S z|jW S  tyT   td| Y n0 d S )Nz/invalid argument for RootRegistry.__getitem__: )	r   r   r   
isinstancer\   r]   Z_path_registryr@   
IndexErrorr`   r'   r'   r)   _getitem  s    
zRootRegistry._getitemrH   c                 C  s   | S r&   r'   rI   r'   r'   r)   _truncate_recursive  s    z RootRegistry._truncate_recursiveN)r   r   r   r   r   inherit_cacher$   r7   r   rz   r*   r5   r   r   r   ra   r'   r'   r'   r)   r9   q  s   r9   c                   @  sV   e Zd ZU dZi Zded< dddddd	Zed
dddZe	dd dddZ
dS )r   zcacheable string tokenzDict[str, PathToken]r   r   zList[BindParameter[Any]]zTuple[Any, ...])r   
bindparamsr%   c                 C  s
   t | fS r&   r   )rD   r   r   r'   r'   r)   _gen_cache_key  s    zPathToken._gen_cache_keyrG   rH   c                 C  s   d S r&   r'   rI   r'   r'   r)   r?     s    zPathToken._path_for_comparer|   )strvaluer%   c                 C  s.   || j v r| j | S t| | j |< }|S d S r&   )r   r   )r   r   resultr'   r'   r)   intern  s    

zPathToken.internN)r   r   r   r   r   r   r   r   r?   r   r   r'   r'   r'   r)   r     s   
r   c                   @  sr   e Zd ZU dZdZded< ded< ddddd	Zd
ZdZddddZ	ddddZ
dddddZesneZdS )r]   )r   r8   r$   r7   Tr\   r   r   r8   )r8   r   c                 C  s6   t |}|| _|| _|j|f | _|j|f | _d S r&   )r   r   r   r8   r$   r7   )rD   r8   r   r'   r'   r)   __init__  s
    
zTokenRegistry.__init__FzIterator[PathRegistry]rH   c                 c  s   | j }t|r| V  d S tr*t|ts*J |jsV|j D ]}t|j | | j	V  q:nJ|jrt
d|jjr| V  t
d|jjD ]}t|j | | j	V  q~n| V  d S Nr   )r8   r*   r   r   rd   rz   rn   iterate_to_rootr]   r   r   r_   _is_with_polymorphic_with_polymorphic_entitiesrD   r8   Zmp_ententr'   r'   r)   generate_for_superclasses  s,    
z'TokenRegistry.generate_for_superclasseszIterator[_PathRepresentation]c                 c  s   | j }t|r| jV  d S tr,t|ts,J |j D ]}t|j | | j	jV  q6|j
rtd|jjr| jV  td|jjD ]}t|j | | j	jV  q|n| jV  d S r   )r8   r*   r7   r   r   rd   rn   r   r]   r   rz   r   r_   r   r   r   r'   r'   r)   "_generate_natural_for_superclasses  s,    
z0TokenRegistry._generate_natural_for_superclassesr   r^   c              
   C  sB   z| j | W S  ty< } zt| |W Y d }~n
d }~0 0 d S r&   )r$   	TypeErrorr   )rD   r_   errr'   r'   r)   r     s    zTokenRegistry._getitemN)r   r   r   r   r   r   r   r   r   r   r   r   r   ra   r'   r'   r'   r)   r]     s   
r]   c                   @  sz   e Zd ZU dZdZdZded< ded< ded< d	dd
ddZd dddZe	d	dddZ
dddddZesveZdS )re   )propr8   r$   r7   r   r_   rn   _wildcard_path_loader_key_default_path_loader_key_loader_keyr5   Tr.   r   zOptional[Mapper[Any]]rn   z"Optional[_InternalEntityType[Any]]r_   rd   )r8   r   c                 C  sd  t d|d }|}|jjp$t|jj| _|jr4|jrF|j|j  }}n|jr|jr|j|jv r|d 	|j}|j| }|jr|j|j }d| _q|}n2|jr|jr|j|jur|j
|jr|j|j }|| _|| _|j|f | _|j|f | _|j| _|jr*trt|tsJ |j| _|j| _nd | _d | _d|j| jj f| _| jj| _d| jf| _d S )Nr-   r   Tloader)r   r8   r5   r4   rn   Zinheritsrz   Z_use_mapper_pathZwith_polymorphic_mappersZ_entity_for_mapperrt   r   r$   r7   Z_links_to_entityr   Z_is_relationshipr   r   r   r_   Z_wildcard_tokenr   r   r   )rD   r8   r   ZinspZnatural_parentZsubclass_entityr'   r'   r)   r     s^    


 

zPropRegistry.__init__rH   c                 C  s\   d }t t| jd d D ]\}}|| ju r|}q|d u r>| S | | jd|d   S d S )Nr   r   r   )	enumeratereversedr$   r   r   )rD   Zearliestrk   r   r'   r'   r)   r   v  s    
z PropRegistry._truncate_recursivec                 C  s   | j d usJ | | j  S r&   )r_   rI   r'   r'   r)   entity_path  s    zPropRegistry.entity_pathz+Union[int, slice, _InternalEntityType[Any]]zDUnion[AbstractEntityRegistry, _PathElementType, _PathRepresentation]r^   c                 C  s&   t |ttfr| j| S t| |S d S r&   )r   rJ   rc   r$   r   r`   r'   r'   r)   r     s    
zPropRegistry._getitemN)r   r   r   r   r   r   r   r   r   r   r   r   r   ra   r'   r'   r'   r)   re     s   
Zre   c                   @  s   e Zd ZU dZdZdZded< ded< ded< ded	< ddd
ddZd dddZe	ddddZ
e	ddddZe	ddddZddddZdddddZeseZdS ) rd   )rO   r8   rz   r$   r_   r7   T!Union[RootRegistry, PropRegistry]r8   r-   rO   r_   r4   rz   r8   r_   c                 C  s   || _ || _|j| _|| _|j|f | _|jrx| js:|jrx|j|jd jr`|j|jf | _q|j|jd jf | _n| j| _d S )Nr   )	rO   r8   rz   r_   r$   r5   rn   rt   r7   rD   r8   r_   r'   r'   r)   r     s    

zAbstractEntityRegistry.__init__rH   c                 C  s   | j  | j S r&   )r8   r   r_   rI   r'   r'   r)   r     s    z*AbstractEntityRegistry._truncate_recursivec                 C  s
   |  dS )Nr   )rL   rI   r'   r'   r)   root_entity  s    z"AbstractEntityRegistry.root_entityr"   c                 C  s   | S r&   r'   rI   r'   r'   r)   r     s    z"AbstractEntityRegistry.entity_pathrm   c                 C  s   | j jS r&   )r_   rn   rI   r'   r'   r)   rn     s    zAbstractEntityRegistry.mapperc                 C  s   dS )NTr'   rI   r'   r'   r)   __bool__  s    zAbstractEntityRegistry.__bool__r   z:Union[_PathElementType, _PathRepresentation, PathRegistry]r^   c                 C  s@   t |ttfr| j| S |tjv r2t| tj| S t| |S d S r&   )r   rJ   rc   r$   r   r   r]   re   r`   r'   r'   r)   r     s
    

zAbstractEntityRegistry._getitemN)r   r   r   r   r   r,   r   r   r   r   r   r   rn   r   r   r   ra   r'   r'   r'   r)   rd     s&   
	.
rd   c                   @  s   e Zd ZdZdS )r   TN)r   r   r   r   r'   r'   r'   r)   r     s   r   c                   @  s*   e Zd ZddddZddddd	Zd
S )_ERDictr   registryc                 C  s
   || _ d S r&   r   )rD   r   r'   r'   r)   r     s    z_ERDict.__init__r   re   )rO   r%   c                 C  s   t | j| | |< }|S r&   )re   r   )rD   rO   itemr'   r'   r)   __missing__  s    z_ERDict.__missing__N)r   r   r   r   r   r'   r'   r'   r)   r     s   r   c                      sV   e Zd ZdZdZddd fddZdddd	d
dZdddddZesNeZ	  Z
S )r   )_cacheTr   r-   r   c                   s   t  || t| | _d S r&   )superr   r   r   r   r   r'   r)   r   
  s    zCachingEntityRegistry.__init__r   )rO   defaultr%   c                 C  s   | j ||S r&   )r   pop)rD   rO   r   r'   r'   r)   r     s    zCachingEntityRegistry.popr^   c                 C  s:   t |ttfr| j| S t |tr,t| |S | j| S d S r&   )r   rJ   rc   r$   r   r]   r   r`   r'   r'   r)   r     s
    


zCachingEntityRegistry._getitem)r   r   r   r   r   r   r   r   r   ra   __classcell__r'   r'   r   r)   r     s   r   c                 C  s   d S r&   r'   r(   r'   r'   r)   path_is_entity#  s    r   zTypeGuard[PropRegistry]c                 C  s   d S r&   r'   r(   r'   r'   r)   path_is_property'  r+   r   r   )Or   
__future__r   	functoolsr   	itertoolsr   loggingoperatortypingr   r   r   r   r	   r
   r   r   r   r   r    r   r   Z_typingr   r   r   sqlr   Zsql.cache_keyr   r   Z
interfacesr   rn   r   Zrelationshipsr   r   r   Zsql.elementsr   Zsql.visitorsr   Zutil.typingr    r!   r*   r,   
attrgetterr/   r|   r\   rb   r6   rh   ri   	getLoggerr   rQ   r1   r3   r   r   r"   r   r9   r:   ZInspectionAttrr   r]   re   rd   r   r   r   r   r   r'   r'   r'   r)   <module>   s   



  &V `

