o
    !Zhd                     @  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/ dOd'd(Z0dPd*d+Z1n
e2d(Z0e2d+Z1ee
 Z3e4Z5ee5d,d-f Z6ee6d.f Z7ed, Z8eed-e4f  Z9e:e;Z<dQd0d1Z=d2Z>d3e?d4< d5Z@G d6d$ d$eZAG d7d8 d8eAZBG d9d: d:eBZCeC eA_DG d;d< d<ejEee4ZFG d=d> d>eAZGG d?d@ d@eAZHG dAdB dBeBZIG dCdD dDeIZJG dEdF dFee
e
f ZKG dGdH dHeIZLerqdPdIdJZMdRdLdMZNdS e2d+ZMe2dNZNdS )Sz@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pathPathRegistryreturnTypeGuard[RootRegistry]c                 C     d S N r"   r(   r(   S/var/www/html/lang_env/lib/python3.10/site-packages/sqlalchemy/orm/path_registry.pyis_root0       r+   !TypeGuard[AbstractEntityRegistry]c                 C  r&   r'   r(   r)   r(   r(   r*   	is_entity2   r,   r.   _InternalEntityType[Any]MapperProperty[Any]._SerializedPathc                 C  s
   t | S r'   )r#   deserializer)   r(   r(   r*   _unreduce_pathP      
r3   *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< dgddZdgddZedhddZdiddZdjd#d$Zdjd%d&Z	'dkdld)d*Zdmd+d,Zdmd-d.Zednd2d3Zedod5d3Zedpd7d3Zedqd9d3Zedrd<d3Zdsd?d3Zedmd@dAZdtdCdDZdudGdHZdvdIdJZdwdKdLZe dxdNdOZ!e dydPdQZ"dzdRdSZ#e d{dTdUZ$ee d|dWdXZ%ee d}d[dXZ%e d~d\dXZ%e dd^d_Z&dd`daZ'ddcddZ(ddedf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.

    r(   Fboolis_unnatural_PathRepresentationr"   natural_pathzOptional[PathRegistry]parentRootRegistryrootr   _cache_key_traversalotherr   r$   c                 C  s>   z|d uo
| j |jkW S  ty   tdt|  Y dS w )N1Comparison of PathRegistry to %r is not supportedFr"   _path_for_compareAttributeErrorr   warntypeselfr?   r(   r(   r*   __eq__      zPathRegistry.__eq__c                 C  s>   z|d u p
| j |jkW S  ty   tdt|  Y dS w )Nr@   TrA   rF   r(   r(   r*   __ne__   rI   zPathRegistry.__ne__Optional[_PathRepresentation]c                 C  s   | j S r'   r)   rG   r(   r(   r*   rB      s   zPathRegistry._path_for_compareindexintr/   c                 C  s
   | j | S r'   r)   )rG   rM   r(   r(   r*   odd_element   r4   zPathRegistry.odd_element
attributesDict[Any, Any]keyvalueNonec                 C  s"   t d|| | |||| jf< d S )Nzset '%s' on path '%s' to '%s')logdebugr:   rG   rP   rR   rS   r(   r(   r*   set   s   zPathRegistry.setc                 C  s&   t d|| | ||| jf| d S )Nz$setdefault '%s' on path '%s' to '%s')rU   rV   
setdefaultr:   rW   r(   r(   r*   rY      s   zPathRegistry.setdefaultNOptional[Any]c                 C  s   || j f}||v r|| S |S r'   )r:   rW   r(   r(   r*   get   s   
zPathRegistry.getc                 C  
   t | jS r'   lenr"   rL   r(   r(   r*   __len__   r4   zPathRegistry.__len__c                 C  s   t | S r'   )idrL   r(   r(   r*   __hash__      zPathRegistry.__hash__entity_StrPathTokenTokenRegistryc                 C  r&   r'   r(   rG   rc   r(   r(   r*   __getitem__      zPathRegistry.__getitem___PathElementTypec                 C  r&   r'   r(   rf   r(   r(   r*   rg      rh   slicec                 C  r&   r'   r(   rf   r(   r(   r*   rg      rh   AbstractEntityRegistryc                 C  r&   r'   r(   rf   r(   r(   r*   rg      s   r0   PropRegistryc                 C  r&   r'   r(   rf   r(   r(   r*   rg      rh   OUnion[_StrPathToken, int, slice, _InternalEntityType[Any], MapperProperty[Any]]aUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry]c                 C  s   t  r'   )NotImplementedErrorrf   r(   r(   r*   rg      s   c                 C  r\   r'   r]   rL   r(   r(   r*   length      
zPathRegistry.lengthJIterator[Tuple[_InternalEntityType[Any], Union[str, MapperProperty[Any]]]]c                 c  sH    t t| j}t t|}tdt|dD ]}|| ||d  fV  qd S )Nr   r   r   )r   _OddPathRepresentationr"   _EvenPathRepresentationranger^   )rG   Zodd_pathZ	even_pathir(   r(   r*   pairs   s   
zPathRegistry.pairsmapperMapper[Any]c                   sF   t t| j  fddtdt dD D ]}|j|r  dS qdS )Nc                      g | ]} | qS r(   r(   .0rv   _m_pathr(   r*   
<listcomp>       z0PathRegistry.contains_mapper.<locals>.<listcomp>r   r   TF)r   rs   r"   ru   r^   rx   isa)rG   rx   Zpath_mapperr(   r}   r*   contains_mapper   s   "zPathRegistry.contains_mapperc                 C  s   || j f|v S r'   r)   )rG   rP   rR   r(   r(   r*   contains      zPathRegistry.containsc                 C  s   t |  ffS r'   )r3   	serializerL   r(   r(   r*   
__reduce__   r   zPathRegistry.__reduce__r1   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)r|   mr(   r(   r*   	<genexpr>   s
    
z/PathRegistry._serialize_path.<locals>.<genexpr>c                   rz   r(   r(   r{   r}   r(   r*   r     r   z0PathRegistry._serialize_path.<locals>.<listcomp>r   r   c                 s  s&    | ]}t |r|jnt|V  qd S r'   )r   rR   r   )r|   pr(   r(   r*   r     s
    
c                   rz   r(   r(   r{   )_p_pathr(   r*   r     r   r   r'   )r   rs   rt   listziptupleru   r^   )clsr"   r(   )r~   r   r*   _serialize_path   s   

zPathRegistry._serialize_pathc                   sP   dddddd t t fd	d
|D  }|r&|d d u r&|dd }|S )Nmclsr   r$   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_tokenrR   c                 S  sD   |d u rd S |t jv rt j| S tj| dd}|d usJ |j| S r   )r   r   r   r   attrs)r   rR   mpr(   r(   r*   _deserialize_key_token  s   


z>PathRegistry._deserialize_path.<locals>._deserialize_key_tokenc                   s"   g | ]\}}| ||fqS r(   r(   )r|   r   rR   r   r   r(   r*   r   #  s    z2PathRegistry._deserialize_path.<locals>.<listcomp>r   )r   r   r$   r   )r   r   rR   r   r$   r   )r   r   r   r"   r   r(   r   r*   _deserialize_path  s   

	
zPathRegistry._deserialize_pathc                 C  s   | j }| |S r'   )r"   r   )rG   r"   r(   r(   r*   r   0  s   
zPathRegistry.serializec                 C  s    |d usJ |  |}| |S r'   )r   coercer   r(   r(   r*   r2   4  s   

zPathRegistry.deserializeCachingEntityRegistryc                 C  r&   r'   r(   r   rx   r(   r(   r*   
per_mapper:     zPathRegistry.per_mapperAliasedInsp[Any]SlotsEntityRegistryc                 C  r&   r'   r(   r   r(   r(   r*   r   >  r   c                 C  s   |j r	t| j|S t| j|S r'   )r   r   r=   r   r   r(   r(   r*   r   B  s   rawc                 C  s   ddd}t ||| jS )	Nprevr#   next_ri   r$   c                 S     | | S r'   r(   r   r   r(   r(   r*   _redM  rb   z!PathRegistry.coerce.<locals>._redr   r#   r   ri   r$   r#   )r   r=   )r   r   r   r(   r(   r*   r   K  s   
zPathRegistry.coercec                 C  s   ddd}t ||j| S )	Nr   r#   r   ri   r$   c                 S  r   r'   r(   r   r(   r(   r*   r   T  rb   z"PathRegistry.__add__.<locals>._redr   )r   r"   )rG   r?   r   r(   r(   r*   __add__S  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   )r|   elemr(   r(   r*   r   Z  s    z'PathRegistry.__str__.<locals>.<genexpr>])joinr"   rL   r(   r(   r*   __str__Y  s   zPathRegistry.__str__c                 C  s   | j j d| jdS )N())	__class____name__r"   rL   r(   r(   r*   __repr__\  s   zPathRegistry.__repr__)r?   r   r$   r7   r$   rK   )rM   rN   r$   r/   )rP   rQ   rR   r   rS   r   r$   rT   r'   )rP   rQ   rR   r   rS   rZ   r$   r   )r$   rN   )rc   rd   r$   re   )rc   rN   r$   ri   )rc   rj   r$   r9   )rc   r/   r$   rk   )rc   r0   r$   rl   )rc   rm   r$   rn   )r$   rr   )rx   ry   r$   r7   )rP   rQ   rR   r   r$   r7   )r$   r   )r"   r9   r$   r1   )r"   r1   r$   r9   )r$   r1   r"   r1   r$   r#   )rx   ry   r$   r   )rx   r   r$   r   )rx   r/   r$   rk   )r   r9   r$   r#   )r?   r#   r$   r#   )r$   r   )*r   
__module____qualname____doc__	__slots__is_tokenr+   
has_entityis_propertyr.   __annotations__r   ZExtendedInternalTraversalZdp_has_cache_key_listr>   rH   rJ   propertyrB   rO   rX   rY   r[   r_   ra   r   rg   rp   rw   r   r   r   classmethodr   r   r   r2   r   r   r   r   r   r(   r(   r(   r*   r#   X   s~   
 








	







#

c                   @  s,   e Zd ZU dZded< ded< dd	d
ZdS )CreatesTokenr(   r7   r   r+   tokenrd   r$   re   c                 C  sF   | dt rt| |S | dt rt| j|S td| )N:zinvalid token: )endswithr6   re   _DEFAULT_TOKENr=   r   ArgumentError)rG   r   r(   r(   r*   r   f  s
   
zCreatesToken.tokenN)r   rd   r$   re   )r   r   r   r   r   r   r(   r(   r(   r*   r   `  s
   
 r   c                   @  sP   e Zd ZdZdZdZd ZZdZdZ	dZ
dZdd	d
ZdddZes&eZdS dS )r<   zXRoot registry, defers to mappers so that
    paths are maintained per-root-mapper.

    r(   TFrc   r   r$   ,Union[TokenRegistry, AbstractEntityRegistry]c                 C  sR   |t jv rtrt|tsJ t| t j| S z|jW S  ty(   td| w )Nz/invalid argument for RootRegistry.__getitem__: )	r   r   r   
isinstancerd   re   Z_path_registryrC   
IndexErrorrf   r(   r(   r*   _getitem  s   
zRootRegistry._getitemc                 C     | S r'   r(   rL   r(   r(   r*   _truncate_recursive  rh   z RootRegistry._truncate_recursiveN)rc   r   r$   r   )r$   r<   )r   r   r   r   r   inherit_cacher"   r:   r   r   r+   r8   r   r   r   rg   r(   r(   r(   r*   r<   o  s    

r<   c                   @  sD   e Zd ZU dZi Zded< dd	d
ZedddZe	dddZ
dS )r   zcacheable string tokenzDict[str, PathToken]r   r   
bindparamsList[BindParameter[Any]]r$   Tuple[Any, ...]c                 C  s
   t | fS r'   r   )rG   r   r   r(   r(   r*   _gen_cache_key  s   
zPathToken._gen_cache_keyrK   c                 C  r&   r'   r(   rL   r(   r(   r*   rB     r   zPathToken._path_for_comparestrvaluer   c                 C  s*   || j v r
| j | S t| | j |< }|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   r   r   r   rB   r   r   r(   r(   r(   r*   r     s   
 
r   c                   @  sb   e Zd ZU dZdZded< ded< dddZd	ZdZdddZ	dddZ
dddZes/eZdS dS )re   )r   r;   r"   r:   Trd   r   r   r;   c                 C  s6   t |}|| _|| _|j|f | _|j|f | _d S r'   )r   r   r   r;   r"   r:   )rG   r;   r   r(   r(   r*   __init__  s
   
zTokenRegistry.__init__Fr$   Iterator[PathRegistry]c                 c  s    | j }t|r| V  d S trt|tsJ |js-|j D ]}t|j | | j	V  qd S |jrPt
d|jjrP| V  t
d|jjD ]}t|j | | j	V  qAd S | V  d S Nr   )r;   r+   r   r   rk   r   rx   iterate_to_rootre   r   r   rc   _is_with_polymorphic_with_polymorphic_entitiesrG   r;   Zmp_entZentr(   r(   r*   generate_for_superclasses  s8   
z'TokenRegistry.generate_for_superclasses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  q|j
rOtd|jjrO| jV  td|jjD ]}t|j | | j	jV  q?d S | jV  d S r   )r;   r+   r:   r   r   rk   rx   r   re   r   r   r   rc   r   r   r   r(   r(   r*   "_generate_natural_for_superclasses  s6   z0TokenRegistry._generate_natural_for_superclassesrc   r   c              
   C  s2   z| j | W S  ty } zt| |d }~ww r'   )r"   	TypeErrorr   )rG   rc   errr(   r(   r*   r     s   zTokenRegistry._getitemN)r;   r   r   rd   )r$   r   )r$   r   rc   r   r$   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   rg   r(   r(   r(   r*   re     s   
 



re   c                   @  sj   e Zd ZU dZdZdZded< ded< ded< dddZdddZe	dddZ
dddZes3eZdS dS )rl   )propr;   r"   r:   r   rc   rx   _wildcard_path_loader_key_default_path_loader_key_loader_keyr8   Tr0   r   zOptional[Mapper[Any]]rx   z"Optional[_InternalEntityType[Any]]rc   r;   rk   c                 C  s^  t d|d }|}|jjpt|jj| _|jr|jr#|j|j  }}nB|jrL|jrL|j|jv rL|d 	|j}|j| }|jrI|j|j }d| _n|}n|jre|jre|j|jure|j
|jre|j|j }|| _|| _|j|f | _|j|f | _|j| _|jrtrt|tsJ |j| _|j| _nd | _d | _d|j| jj f| _| jj| _d| jf| _d S )Nr/   r   Tloader)r   r;   r8   r7   rx   Zinheritsr   Z_use_mapper_pathZwith_polymorphic_mappersZ_entity_for_mapperr   r   r"   r:   Z_links_to_entityr   Z_is_relationshipr   r   r   rc   Z_wildcard_tokenr   r   r   )rG   r;   r   ZinspZnatural_parentZsubclass_entityr(   r(   r*   r     sZ   

 

zPropRegistry.__init__r$   c                 C  sX   d }t t| jd d D ]\}}|| ju r|}q|d u r| S | | jd|d   S )Nr   r   r   )	enumeratereversedr"   r   r   )rG   Zearliestrv   r   r(   r(   r*   r   s  s   
z PropRegistry._truncate_recursivec                 C  s   | j d usJ | | j  S r'   )rc   rL   r(   r(   r*   entity_path~  s   
zPropRegistry.entity_path+Union[int, slice, _InternalEntityType[Any]]DUnion[AbstractEntityRegistry, _PathElementType, _PathRepresentation]c                 C  s"   t |ttfr| j| S t| |S r'   )r   rN   rj   r"   r   rf   r(   r(   r*   r     s   

zPropRegistry._getitemN)r;   rk   r   r0   )r$   rl   r$   rk   )rc   r   r$   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   rg   r(   r(   r(   r*   rl     s   
 

Y
rl   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ZdddZe	d ddZ
e	d!ddZe	d"ddZd#ddZd$ddZesJeZdS dS )%rk   )rR   r;   r   r"   rc   r:   T!Union[RootRegistry, PropRegistry]r;   r/   rR   rc   r7   r   c                 C  s   || _ || _|j| _|| _|j|f | _|jr>| js|jr>|j|jd jr1|j|jf | _d S |j|jd jf | _d S | j| _d S )Nr   )	rR   r;   r   rc   r"   r8   rx   r   r:   rG   r;   rc   r(   r(   r*   r     s   
zAbstractEntityRegistry.__init__r$   c                 C  s   | j  | j S r'   )r;   r   rc   rL   r(   r(   r*   r     s   z*AbstractEntityRegistry._truncate_recursivec                 C  s
   |  dS )Nr   )rO   rL   r(   r(   r*   root_entity  rq   z"AbstractEntityRegistry.root_entityr#   c                 C  r   r'   r(   rL   r(   r(   r*   r     r   z"AbstractEntityRegistry.entity_pathry   c                 C  s   | j jS r'   )rc   rx   rL   r(   r(   r*   rx     s   zAbstractEntityRegistry.mapperc                 C  s   dS )NTr(   rL   r(   r(   r*   __bool__  rh   zAbstractEntityRegistry.__bool__r   :Union[_PathElementType, _PathRepresentation, PathRegistry]c                 C  s<   t |ttfr| j| S |tjv rt| tj| S t| |S r'   )r   rN   rj   r"   r   r   re   rl   rf   r(   r(   r*   r     s
   


zAbstractEntityRegistry._getitemNr;   r   rc   r/   r   )r$   r/   )r$   r#   )r$   ry   )r$   r7   )rc   r   r$   r   )r   r   r   r   r   r.   r   r   r   r   r   r   rx   r   r   r   rg   r(   r(   r(   r*   rk     s*   
 	

.


rk   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Zdd	d
ZdS )_ERDictregistryr   c                 C  s
   || _ d S r'   )r   )rG   r   r(   r(   r*   r     r4   z_ERDict.__init__rR   r   r$   rl   c                 C  s   t | j| | |< }|S r'   )rl   r   )rG   rR   itemr(   r(   r*   __missing__  s   z_ERDict.__missing__N)r   r   )rR   r   r$   rl   )r   r   r   r   r   r(   r(   r(   r*   r     s    
r   c                      sJ   e Zd ZdZdZd fddZdddZdddZes!eZ	  Z
S   Z
S )r   )_cacheTr;   r   rc   r/   c                   s   t  || t| | _d S r'   )superr   r   r   r   r   r(   r*   r     s   zCachingEntityRegistry.__init__rR   r   defaultr$   c                 C  s   | j ||S r'   )r   pop)rG   rR   r  r(   r(   r*   r    r   zCachingEntityRegistry.popc                 C  s6   t |ttfr| j| S t |trt| |S | j| S r'   )r   rN   rj   r"   r   re   r   rf   r(   r(   r*   r     s
   



zCachingEntityRegistry._getitemr   )rR   r   r  r   r$   r   r   )r   r   r   r   r   r   r  r   r   rg   __classcell__r(   r(   r   r*   r     s    

r   c                 C  r&   r'   r(   r)   r(   r(   r*   path_is_entity   r   r  TypeGuard[PropRegistry]c                 C  r&   r'   r(   r)   r(   r(   r*   path_is_property$  r,   r  r   )r"   r#   r$   r%   )r"   r#   r$   r-   r   )r"   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   rx   r   Zrelationshipsr   r   r   Zsql.elementsr   Zsql.visitorsr   Zutil.typingr    r!   r+   r.   
attrgetterr1   r   rd   ri   r9   rs   rt   	getLoggerr   rU   r3   r6   r   r   r#   r   r<   r=   ZInspectionAttrr   re   rl   rk   r   r   r   r  r  r(   r(   r(   r*   <module>   s   





  
&V `


