o
    h<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/ 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)StrategizedProperty)Mapper)RelationshipProperty)AliasedInsp)_CacheKeyTraversalType)BindParameter)anon_map)_LiteralStar)	TypeGuardpathPathRegistryreturnTypeGuard[RootRegistry]c                 C     d S N r"   r(   r(   p/var/www/html/construction_image-detection-poc/venv/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]StrategizedProperty[Any]._SerializedPathc                 C  s
   t | S r'   )r#   deserializer)   r(   r(   r*   _unreduce_pathP      
r3   *r    _WILDCARD_TOKEN_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 )NrA   TrB   rG   r(   r(   r*   __ne__   rJ   zPathRegistry.__ne__Optional[_PathRepresentation]c                 C  s   | j S r'   r)   rH   r(   r(   r*   rC      s   zPathRegistry._path_for_compareindexintr/   c                 C  s
   | j | S r'   r)   )rH   rN   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;   rH   rQ   rS   rT   r(   r(   r*   set   s   zPathRegistry.setc                 C  s&   t d|| | ||| jf| d S )Nz$setdefault '%s' on path '%s' to '%s')rV   rW   
setdefaultr;   rX   r(   r(   r*   rZ      s   zPathRegistry.setdefaultNOptional[Any]c                 C  s   || j f}||v r|| S |S r'   )r;   rX   r(   r(   r*   get   s   
zPathRegistry.getc                 C  
   t | jS r'   lenr"   rM   r(   r(   r*   __len__   r4   zPathRegistry.__len__c                 C  s   t | S r'   )idrM   r(   r(   r*   __hash__      zPathRegistry.__hash__entity_StrPathTokenTokenRegistryc                 C  r&   r'   r(   rH   rd   r(   r(   r*   __getitem__      zPathRegistry.__getitem___PathElementTypec                 C  r&   r'   r(   rg   r(   r(   r*   rh      ri   slicec                 C  r&   r'   r(   rg   r(   r(   r*   rh      ri   AbstractEntityRegistryc                 C  r&   r'   r(   rg   r(   r(   r*   rh         r0   PropRegistryc                 C  r&   r'   r(   rg   r(   r(   r*   rh      rm   TUnion[_StrPathToken, int, slice, _InternalEntityType[Any], StrategizedProperty[Any]]aUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry]c                 C  s   t  r'   )NotImplementedErrorrg   r(   r(   r*   rh      s   c                 C  r]   r'   r^   rM   r(   r(   r*   length      
zPathRegistry.lengthOIterator[Tuple[_InternalEntityType[Any], Union[str, StrategizedProperty[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_   )rH   odd_path	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(   .0rz   _m_pathr(   r*   
<listcomp>       z0PathRegistry.contains_mapper.<locals>.<listcomp>r   r   TF)r   ru   r"   rw   r_   r|   isa)rH   r|   path_mapperr(   r   r*   contains_mapper   s   "zPathRegistry.contains_mapperc                 C  s   || j f|v S r'   r)   )rH   rQ   rS   r(   r(   r*   contains      zPathRegistry.containsc                 C  s   t |  ffS r'   )r3   	serializerM   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                   r~   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   rS   r   )r   pr(   r(   r*   r     s
    
c                   r~   r(   r(   r   )_p_pathr(   r*   r     r   r   r'   )r   ru   rv   listziptuplerw   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_tokenrS   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   rS   mpr(   r(   r*   _deserialize_key_token  s   


z>PathRegistry._deserialize_path.<locals>._deserialize_key_tokenc                   s"   g | ]\}}| ||fqS r(   r(   )r   r   rS   r   r   r(   r*   r   %  s    z2PathRegistry._deserialize_path.<locals>.<listcomp>r   )r   r   r$   r   )r   r   rS   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   )rH   r"   r(   r(   r*   r   2  s   
zPathRegistry.serializec                 C  s    |d usJ |  |}| |S r'   )r   coercer   r(   r(   r*   r2   6  s   

zPathRegistry.deserializeCachingEntityRegistryc                 C  r&   r'   r(   r   r|   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   D  s   rawc                 C  s   ddd}t ||| jS )	Nprevr#   next_rj   r$   c                 S     | | S r'   r(   r   r   r(   r(   r*   _redO  rc   z!PathRegistry.coerce.<locals>._redr   r#   r   rj   r$   r#   )r   r>   )r   r   r   r(   r(   r*   r   M  s   
zPathRegistry.coercec                 C  s   ddd}t ||j| S )	Nr   r#   r   rj   r$   c                 S  r   r'   r(   r   r(   r(   r*   r   V  rc   z"PathRegistry.__add__.<locals>._redr   )r   r"   )rH   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   )r   elemr(   r(   r*   r   \  s    z'PathRegistry.__str__.<locals>.<genexpr>])joinr"   rM   r(   r(   r*   __str__[  s   zPathRegistry.__str__c                 C  s   | j j d| jdS )N())	__class____name__r"   rM   r(   r(   r*   __repr__^  s   zPathRegistry.__repr__)r@   r   r$   r8   r$   rL   )rN   rO   r$   r/   )rQ   rR   rS   r   rT   r   r$   rU   r'   )rQ   rR   rS   r   rT   r[   r$   r   )r$   rO   )rd   re   r$   rf   )rd   rO   r$   rj   )rd   rk   r$   r:   )rd   r/   r$   rl   )rd   r0   r$   rn   )rd   ro   r$   rp   )r$   rt   )r|   r}   r$   r8   )rQ   rR   rS   r   r$   r8   )r$   r   )r"   r:   r$   r1   )r"   r1   r$   r:   )r$   r1   r"   r1   r$   r#   )r|   r}   r$   r   )r|   r   r$   r   )r|   r/   r$   rl   )r   r:   r$   r#   )r@   r#   r$   r#   )r$   r   )*r   
__module____qualname____doc__	__slots__is_tokenr+   
has_entityis_propertyr.   __annotations__r   ExtendedInternalTraversaldp_has_cache_key_listr?   rI   rK   propertyrC   rP   rY   rZ   r\   r`   rb   r   rh   rr   r{   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(   r8   r   r+   tokenre   r$   rf   c                 C  sF   | dt rt| |S | dt rt| j|S td| )N:zinvalid token: )endswithr6   rf   _DEFAULT_TOKENr>   r   ArgumentError)rH   r   r(   r(   r*   r   h  s
   
zCreatesToken.tokenN)r   re   r$   rf   )r   r   r   r   r   r   r(   r(   r(   r*   r   b  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(   TFrd   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   
isinstancere   rf   _path_registryrD   
IndexErrorrg   r(   r(   r*   _getitem  s   
zRootRegistry._getitemc                 C     | S r'   r(   rM   r(   r(   r*   _truncate_recursive  ri   z RootRegistry._truncate_recursiveN)rd   r   r$   r   )r$   r=   )r   r   r   r   r   inherit_cacher"   r;   r   r   r+   r9   r   r   r   rh   r(   r(   r(   r*   r=   q  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   )rH   r   r   r(   r(   r*   _gen_cache_key  s   
zPathToken._gen_cache_keyrL   c                 C  r&   r'   r(   rM   r(   r(   r*   rC     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   rC   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 )rf   )r   r<   r"   r;   Tre   r   r   r<   c                 C  s6   t |}|| _|| _|j|f | _|j|f | _d S r'   )r   r   r   r<   r"   r;   )rH   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   rl   r   r|   iterate_to_rootrf   r   r   rd   _is_with_polymorphic_with_polymorphic_entitiesrH   r<   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   rl   r|   r   rf   r   r   r   rd   r   r   r   r(   r(   r*   "_generate_natural_for_superclasses  s6   z0TokenRegistry._generate_natural_for_superclassesrd   r   c              
   C  s2   z| j | W S  ty } zt| |d }~ww r'   )r"   	TypeErrorr   )rH   rd   errr(   r(   r*   r     s   zTokenRegistry._getitemN)r<   r   r   re   )r$   r   )r$   r   rd   r   r$   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   rh   r(   r(   r(   r*   rf     s   
 



rf   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 )rn   )propr<   r"   r;   r   rd   r|   _wildcard_path_loader_key_default_path_loader_key_loader_keyr9   Tr0   r   zOptional[Mapper[Any]]r|   z"Optional[_InternalEntityType[Any]]rd   r<   rl   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<   r9   r8   r|   inheritsr   _use_mapper_pathwith_polymorphic_mappers_entity_for_mapperr   r   r"   r;   _links_to_entityr   _is_relationshipr   r   r   rd   _wildcard_tokenr   r   r   )rH   r<   r   inspnatural_parent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   )rH   earliestrz   r   r(   r(   r*   r   v  s   
z PropRegistry._truncate_recursivec                 C  s   | j d usJ | | j  S r'   )rd   rM   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   rO   rk   r"   r   rg   r(   r(   r*   r     s   

zPropRegistry._getitemN)r<   rl   r   r0   )r$   rn   r$   rl   )rd   r  r$   r  )r   r   r   r   r   r   r   r   r   r   r  r   r   rh   r(   r(   r(   r*   rn     s   
 

Z
rn   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 )%rl   )rS   r<   r   r"   rd   r;   T!Union[RootRegistry, PropRegistry]r<   r/   rS   rd   r8   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   )	rS   r<   r   rd   r"   r9   r|   r   r;   rH   r<   rd   r(   r(   r*   r     s   
zAbstractEntityRegistry.__init__r$   c                 C  s   | j  | j S r'   )r<   r   rd   rM   r(   r(   r*   r     s   z*AbstractEntityRegistry._truncate_recursivec                 C  s
   |  dS )Nr   )rP   rM   r(   r(   r*   root_entity  rs   z"AbstractEntityRegistry.root_entityr#   c                 C  r   r'   r(   rM   r(   r(   r*   r    r   z"AbstractEntityRegistry.entity_pathr}   c                 C  s   | j jS r'   )rd   r|   rM   r(   r(   r*   r|     s   zAbstractEntityRegistry.mapperc                 C  s   dS )NTr(   rM   r(   r(   r*   __bool__  ri   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   rO   rk   r"   r   r   rf   rn   rg   r(   r(   r*   r     s
   


zAbstractEntityRegistry._getitemNr<   r	  rd   r/   r  )r$   r/   )r$   r#   )r$   r}   )r$   r8   )rd   r   r$   r  )r   r   r   r   r   r.   r   r   r   r   r  r  r|   r  r   r   rh   r(   r(   r(   r*   rl     s*   
 	

.


rl   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  )rH   r  r(   r(   r*   r     r4   z_ERDict.__init__rS   r   r$   rn   c                 C  s   t | j| | |< }|S r'   )rn   r  )rH   rS   itemr(   r(   r*   __missing__  s   z_ERDict.__missing__N)r  r   )rS   r   r$   rn   )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	  rd   r/   c                   s   t  || t| | _d S r'   )superr   r  r  r
  r   r(   r*   r   
  s   zCachingEntityRegistry.__init__rS   r   defaultr$   c                 C  s   | j ||S r'   )r  pop)rH   rS   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   rO   rk   r"   r   rf   r  rg   r(   r(   r*   r     s
   



zCachingEntityRegistry._getitemr  )rS   r   r  r   r$   r   r   )r   r   r   r   r   r   r  r   r   rh   __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   _typingr   r   r   sqlr   sql.cache_keyr   r   
interfacesr   r|   r   relationshipsr   r   r   sql.elementsr   sql.visitorsr   util.typingr    r!   r+   r.   
attrgetterr1   r   re   rj   r:   ru   rv   	getLoggerr   rV   r3   r6   r   r   r#   r   r=   r>   InspectionAttrr   rf   rn   rl   r   r  r   r  r  r(   r(   r(   r*   <module>   s   





  &V `


