o
    E6dDg                     @  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
 Z3ee4d,d-f Z5ee5d.f Z6ed, Z7eed-e4f  Z8e9e:Z;dQd0d1Z<d2Z=d3e>d4< d5Z?G d6d$ d$eZ@G d7d8 d8e@ZAG d9d: d:eAZBeB e@_CG d;d< d<ejDee4ZEG d=d> d>e@ZFG d?d@ d@e@ZGG dAdB dBeAZHG dCdD dDeHZIG dEdF dFee
e
f ZJG dGdH dHeHZKerodPdIdJZLdRdLdMZMdS e2d+ZLe2dNZMd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(   sC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/orm/path_registry.pyis_root0      r+   !TypeGuard[AbstractEntityRegistry]c                 C  r&   r'   r(   r)   r(   r(   r*   	is_entity3   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< dcddZdcddZeddddZdeddZded d!Z	"dfdgd$d%Zdhd'd(Zdhd)d*Zedid.d/Zedjd1d/Zedkd3d/Zedld6d/Zedmd9d/Zdnd<d/Zedhd=d>Zdod@dAZdpdDdEZdqdFdGZdrdHdIZedsdKdLZ edtdMdNZ!dudOdPZ"edvdQdRZ#eedwdTdUZ$eedxdXdUZ$edydYdUZ$edzd[d\Z%d{d]d^Z&d|d_d`Z'd|dadb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
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   rM   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')rR   rS   
setdefaultr:   rT   r(   r(   r*   rV      s   zPathRegistry.setdefaultNOptional[Any]c                 C  s   || j f}||v r|| S |S r'   )r:   rT   r(   r(   r*   get   s   
zPathRegistry.getintc                 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strTokenRegistryc                 C  r&   r'   r(   rG   ra   r(   r(   r*   __getitem__      zPathRegistry.__getitem___PathElementTypec                 C  r&   r'   r(   rd   r(   r(   r*   re      rf   slicec                 C  r&   r'   r(   rd   r(   r(   r*   re      rf   r/   AbstractEntityRegistryc                 C  r&   r'   r(   rd   r(   r(   r*   re      s   r0   PropRegistryc                 C  r&   r'   r(   rd   r(   r(   r*   re      rf   EUnion[str, int, slice, _InternalEntityType[Any], MapperProperty[Any]]aUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry]c                 C  s   t  r'   )NotImplementedErrorrd   r(   r(   r*   re      s   c                 C  rZ   r'   r[   rL   r(   r(   r*   length   s   
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(   .0rs   _m_pathr(   r*   
<listcomp>       z0PathRegistry.contains_mapper.<locals>.<listcomp>r   r   TF)r   rp   r"   rr   r\   ru   isa)rG   ru   Zpath_mapperr(   rz   r*   contains_mapper   s   "zPathRegistry.contains_mapperc                 C  s   || j f|v S r'   r)   )rG   rM   rO   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_rb   )ry   mr(   r(   r*   	<genexpr>   s
    
z/PathRegistry._serialize_path.<locals>.<genexpr>c                   rw   r(   r(   rx   rz   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   rO   rb   )ry   pr(   r(   r*   r     s
    
c                   rw   r(   r(   rx   )_p_pathr(   r*   r|     r}   r   r'   )r   rp   rq   listziptuplerr   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_tokenrO   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   rO   mpr(   r(   r*   _deserialize_key_token  s   


z>PathRegistry._deserialize_path.<locals>._deserialize_key_tokenc                   s"   g | ]\}}| ||fqS r(   r(   )ry   r   rO   r   r   r(   r*   r|   !  s    z2PathRegistry._deserialize_path.<locals>.<listcomp>r   )r   r   r$   r   )r   r   rO   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   .  s   
zPathRegistry.serializec                 C  s    |d usJ |  |}| |S r'   )r   coercer   r(   r(   r*   r2   2  s   

zPathRegistry.deserializeCachingEntityRegistryc                 C  r&   r'   r(   r   ru   r(   r(   r*   
per_mapper8     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_rg   r$   c                 S     | | S r'   r(   r   r   r(   r(   r*   _redM  r`   z!PathRegistry.coerce.<locals>._redr   r#   r   rg   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   rg   r$   c                 S  r   r'   r(   r   r(   r(   r*   r   T  r`   z"PathRegistry.__add__.<locals>._redr   )r   r"   )rG   r?   r   r(   r(   r*   __add__S  s   
zPathRegistry.__add__c                 C  s   dd dd | jD  dS )Nz	ORM Path[z -> c                 s  s    | ]}t |V  qd S r'   rb   )ry   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   rO   r   rP   r   r$   rQ   r'   )rM   rN   rO   r   rP   rW   r$   r   )r$   rY   )ra   rb   r$   rc   )ra   rY   r$   rg   )ra   rh   r$   r9   )ra   r/   r$   ri   )ra   r0   r$   rj   )ra   rk   r$   rl   )r$   ro   )ru   rv   r$   r7   )rM   rN   rO   r   r$   r7   )r$   r   )r"   r9   r$   r1   )r"   r1   r$   r9   )r$   r1   r"   r1   r$   r#   )ru   rv   r$   r   )ru   r   r$   r   )ru   r/   r$   ri   )r   r9   r$   r#   )r?   r#   r$   r#   )r$   rb   ))r   
__module____qualname____doc__	__slots__is_tokenr+   
has_entityis_propertyr.   __annotations__r   ZExtendedInternalTraversalZdp_has_cache_key_listr>   rH   rJ   propertyrB   rU   rV   rX   r]   r_   r   re   rn   rt   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+   tokenrb   r$   rc   c                 C  sF   | dt rt| |S | dt rt| j|S td| )N:zinvalid token: )endswithr6   rc   _DEFAULT_TOKENr=   r   ArgumentError)rG   r   r(   r(   r*   r   f  s
   
zCreatesToken.tokenN)r   rb   r$   rc   )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(   TFra   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   
isinstancerb   rc   Z_path_registryrC   
IndexErrorrd   r(   r(   r*   _getitem  s   
zRootRegistry._getitemc                 C     | S r'   r(   rL   r(   r(   r*   _truncate_recursive  r,   z RootRegistry._truncate_recursiveN)ra   r   r$   r   )r$   r<   )r   r   r   r   r   inherit_cacher"   r:   r   r   r+   r8   r   r   r   re   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     rf   zPathToken._path_for_comparestrvaluerb   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   rb   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 )rc   )r   r;   r"   r:   Trb   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   ri   r   ru   iterate_to_rootrc   r   r   ra   _is_with_polymorphic_with_polymorphic_entitiesrG   r;   Zmp_ent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   ri   ru   r   rc   r   r   r   ra   r   r   r   r(   r(   r*   "_generate_natural_for_superclasses  s6   z0TokenRegistry._generate_natural_for_superclassesra   r   c              
   C  s2   z| j | W S  ty } zt| |d }~ww r'   )r"   	TypeErrorr   )rG   ra   errr(   r(   r*   r     s   zTokenRegistry._getitemN)r;   r   r   rb   )r$   r   )r$   r   ra   r   r$   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   re   r(   r(   r(   r*   rc     s   
 



rc   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 )rj   )propr;   r"   r:   r   ra   ru   _wildcard_path_loader_key_default_path_loader_key_loader_keyr8   Tr0   r   zOptional[Mapper[Any]]ru   z"Optional[_InternalEntityType[Any]]ra   r;   ri   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   ru   Zinheritsr   Z_use_mapper_pathZwith_polymorphic_mappersZ_entity_for_mapperr~   r   r"   r:   Z_links_to_entityr   Z_is_relationshipr   r   r   ra   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earliestrs   r   r(   r(   r*   r   s  s   
z PropRegistry._truncate_recursivec                 C  s   | j d usJ | | j  S r'   )ra   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   rY   rh   r"   r   rd   r(   r(   r*   r     s   

zPropRegistry._getitemN)r;   ri   r   r0   )r$   rj   r$   ri   )ra   r   r$   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   re   r(   r(   r(   r*   rj     s   
 

Y
rj   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 )%ri   )rO   r;   r   r"   ra   r:   T!Union[RootRegistry, PropRegistry]r;   r/   rO   ra   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   )	rO   r;   r   ra   r"   r8   ru   r~   r:   rG   r;   ra   r(   r(   r*   r     s   
zAbstractEntityRegistry.__init__r$   c                 C  s   | j  | j S r'   )r;   r   ra   rL   r(   r(   r*   r     s   z*AbstractEntityRegistry._truncate_recursivec                 C  s   t d| jd S )Nr/   r   )r   r"   rL   r(   r(   r*   root_entity  s   z"AbstractEntityRegistry.root_entityr#   c                 C  r   r'   r(   rL   r(   r(   r*   r     rf   z"AbstractEntityRegistry.entity_pathrv   c                 C  s   | j jS r'   )ra   ru   rL   r(   r(   r*   ru     s   zAbstractEntityRegistry.mapperc                 C  s   dS )NTr(   rL   r(   r(   r*   __bool__  r,   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   rY   rh   r"   r   r   rc   rj   rd   r(   r(   r*   r     s
   


zAbstractEntityRegistry._getitemNr;   r   ra   r/   r   )r$   r/   )r$   r#   )r$   rv   )r$   r7   )ra   r   r$   r   )r   r   r   r   r   r.   r   r   r   r   r   r   ru   r   r   r   re   r(   r(   r(   r*   ri     s*   
 	

.


ri   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__rO   r   r$   rj   c                 C  s   t | j| | |< }|S r'   )rj   r   )rG   rO   itemr(   r(   r*   __missing__  s   z_ERDict.__missing__N)r   r   )rO   r   r$   rj   )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   ra   r/   c                   s   t  || t| | _d S r'   )superr   r   r   r   r   r(   r*   r     s   zCachingEntityRegistry.__init__rO   r   defaultr$   c                 C  s   | j ||S r'   )r   pop)rG   rO   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   rY   rh   r"   r   rc   r   rd   r(   r(   r*   r     s
   



zCachingEntityRegistry._getitemr   )rO   r   r   r   r$   r   r   )r   r   r   r   r   r   r   r   r   re   __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  )Nr   
__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   ru   r   Zrelationshipsr   r   r   Zsql.elementsr   Zsql.visitorsr   Zutil.typingr    r!   r+   r.   
attrgetterr1   rb   rg   r9   rp   rq   	getLoggerr   rR   r3   r6   r   r   r#   r   r<   r=   ZInspectionAttrr   rc   rj   ri   r   r   r   r  r  r(   r(   r(   r*   <module>   s   





  
&V `


