HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/__pycache__/path_registry.cpython-310.pyc
o

���g<e�@s�UdZddlmZddlmZddlmZddlZddlZddl	m
Z
ddl	mZddl	mZdd	l	m
Z
dd
l	mZddl	mZddl	mZdd
l	mZddl	mZddl	mZddl	mZddlmZddlmZddlmZddlmZddlmZddlmZer�ddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddlm'Z'ddlm(Z(ddl)m*Z*dd l+m,Z,dd!l-m.Z.dd"l-m/Z/dOd'd(�Z0dPd*d+�Z1n
e�2d(�Z0e�2d+�Z1ee
Z3e4Z5ee5d,d-fZ6ee6d.fZ7ed,Z8eed-e4fZ9e�:e;�Z<dQd0d1�Z=d2Z>d3e?d4<d5Z@Gd6d$�d$e�ZAGd7d8�d8eA�ZBGd9d:�d:eB�ZCeC�eA_DGd;d<�d<ejEee4�ZFGd=d>�d>eA�ZGGd?d@�d@eA�ZHGdAdB�dBeB�ZIGdCdD�dDeI�ZJGdEdF�dFee
e
f�ZKGdGdH�dHeI�ZLe�rqdPdIdJ�ZMdRdLdM�ZNdSe�2d+�ZMe�2dN�ZNdS)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]cC�dS�N��r"r(r(�G/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/path_registry.py�is_root0�r+�!TypeGuard[AbstractEntityRegistry]cCr&r'r(r)r(r(r*�	is_entity2r,r.�_InternalEntityType[Any]�StrategizedProperty[Any].�_SerializedPathcCs
t�|�Sr')r#�deserializer)r(r(r*�_unreduce_pathP�
r3�*r �_WILDCARD_TOKEN�_sa_defaultc@s�eZdZUdZdZdZdZdZdZdZ	de
d<de
d<de
d<d	e
d
<de
d<dejj
fgZd
e
d<dgdd�Zdgdd�Zedhdd��Zdidd�Zdjd#d$�Zdjd%d&�Z	'dkdld)d*�Zdmd+d,�Zdmd-d.�Zednd2d3��Zedod5d3��Zedpd7d3��Zedqd9d3��Zedrd<d3��Zdsd?d3�Zedmd@dA��ZdtdCdD�ZdudGdH�ZdvdIdJ�ZdwdKdL�Ze dxdNdO��Z!e dydPdQ��Z"dzdRdS�Z#e d{dTdU��Z$ee d|dWdX���Z%ee d}d[dX���Z%e d~d\dX��Z%e dd^d_��Z&d�d`da�Z'd�dcdd�Z(d�dedf�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_pathzOptional[PathRegistry]�parent�RootRegistry�rootr�_cache_key_traversal�otherrr$cCs>z|duo
|j|jkWStyt�dt|��YdSw)N�1Comparison of PathRegistry to %r is not supportedF�r"�_path_for_compare�AttributeErrorr�warn�type��selfr@r(r(r*�__eq__�����zPathRegistry.__eq__cCs>z|dup
|j|jkWStyt�dt|��YdSw)NrATrBrGr(r(r*�__ne__�rJzPathRegistry.__ne__�Optional[_PathRepresentation]cCs|jSr'r)�rHr(r(r*rC�szPathRegistry._path_for_compare�index�intr/cCs
|j|Sr'r))rHrNr(r(r*�odd_element�r4zPathRegistry.odd_element�
attributes�Dict[Any, Any]�key�value�NonecCs"t�d|||�||||jf<dS)Nzset '%s' on path '%s' to '%s')�log�debugr;�rHrQrSrTr(r(r*�set�szPathRegistry.setcCs&t�d|||�|�||jf|�dS)Nz$setdefault '%s' on path '%s' to '%s')rVrW�
setdefaultr;rXr(r(r*rZ�szPathRegistry.setdefaultN�
Optional[Any]cCs||jf}||vr
||S|Sr')r;rXr(r(r*�get�s
zPathRegistry.getcC�
t|j�Sr'��lenr"rMr(r(r*�__len__�r4zPathRegistry.__len__cCst|�Sr')�idrMr(r(r*�__hash__��zPathRegistry.__hash__�entity�
_StrPathToken�
TokenRegistrycCr&r'r(�rHrdr(r(r*�__getitem__��zPathRegistry.__getitem__�_PathElementTypecCr&r'r(rgr(r(r*rh�ri�slicecCr&r'r(rgr(r(r*rh�ri�AbstractEntityRegistrycCr&r'r(rgr(r(r*rh��r0�PropRegistrycCr&r'r(rgr(r(r*rh�rm�TUnion[_StrPathToken, int, slice, _InternalEntityType[Any], StrategizedProperty[Any]]�aUnion[TokenRegistry, _PathElementType, _PathRepresentation, PropRegistry, AbstractEntityRegistry]cCst��r')�NotImplementedErrorrgr(r(r*rh�scCr]r'r^rMr(r(r*�length��
zPathRegistry.length�OIterator[Tuple[_InternalEntityType[Any], Union[str, StrategizedProperty[Any]]]]ccsH�tt|j�}tt|�}tdt|�d�D]
}||||dfVqdS)Nrrr)r�_OddPathRepresentationr"�_EvenPathRepresentation�ranger_)rH�odd_path�	even_path�ir(r(r*�pairs�s�
�zPathRegistry.pairs�mapper�Mapper[Any]csFtt|j���fdd�tdt��d�D�D]}|j�|�r dSqdS)Nc�g|]}�|�qSr(r(��.0rz��_m_pathr(r*�
<listcomp>��z0PathRegistry.contains_mapper.<locals>.<listcomp>rrTF)rrur"rwr_r|�isa)rHr|�path_mapperr(r�r*�contains_mapper�s"�zPathRegistry.contains_mappercCs||jf|vSr'r))rHrQrSr(r(r*�contains��zPathRegistry.containscCst|��ffSr')r3�	serializerMr(r(r*�
__reduce__�r�zPathRegistry.__reduce__r1c
svtt|��tt|��tttdd��fdd�tdt��d�D�D��tdd��fdd�td	t��d�D�D��d
��S)Ncss*�|]}|js
|jr
|jnt|�VqdSr')�	is_mapper�is_aliased_class�class_�str)r��mr(r(r*�	<genexpr>s
��
�z/PathRegistry._serialize_path.<locals>.<genexpr>cr~r(r(rr�r(r*r�r�z0PathRegistry._serialize_path.<locals>.<listcomp>rrcss&�|]}t|�r|jnt|�VqdSr')rrSr�)r��pr(r(r*r�s
��
�cr~r(r(r)�_p_pathr(r*r�r�rr')rrurv�list�zip�tuplerwr_)�clsr"r()r�r�r*�_serialize_path�s

�����zPathRegistry._serialize_pathcsPd
dd��ddd��tt��fd	d
�|D���}|r&|ddur&|dd�}|S)N�mclsrr$cSs"|tjvrtj|dd�Stj|S�NT)�	configure)�	PathToken�_intern�orm_base�_inspect_mapped_class)r�r(r(r*�_deserialize_mapper_tokens

���zAPathRegistry._deserialize_path.<locals>._deserialize_mapper_tokenrScSsD|durdS|tjvrtj|Stj|dd�}|dusJ�|j|Sr�)r�r�r�r��attrs)r�rS�mpr(r(r*�_deserialize_key_tokens


z>PathRegistry._deserialize_path.<locals>._deserialize_key_tokencs"g|]
\}}�|��||�f�qSr(r()r�r�rS�r�r�r(r*r�%s���z2PathRegistry._deserialize_path.<locals>.<listcomp>���r)r�rr$r)r�rrSrr$r)r�r�r�r"r�r(r�r*�_deserialize_paths

	
���zPathRegistry._deserialize_pathcCs|j}|�|�Sr')r"r�)rHr"r(r(r*r�2s
zPathRegistry.serializecCs |dusJ�|�|�}|�|�Sr')r��coercer�r(r(r*r26s

zPathRegistry.deserialize�CachingEntityRegistrycCr&r'r(�r�r|r(r(r*�
per_mapper<�zPathRegistry.per_mapper�AliasedInsp[Any]�SlotsEntityRegistrycCr&r'r(r�r(r(r*r�@r�cCs|jr	t|j|�St|j|�Sr')r�r�r>r�r�r(r(r*r�Ds�rawcCsddd�}t|||j�S)	N�prevr#�next_rjr$cS�||Sr'r(�r�r�r(r(r*�_redOrcz!PathRegistry.coerce.<locals>._red�r�r#r�rjr$r#)rr>)r�r�r�r(r(r*r�Ms
zPathRegistry.coercecCsddd�}t||j|�S)	Nr�r#r�rjr$cSr�r'r(r�r(r(r*r�Vrcz"PathRegistry.__add__.<locals>._redr�)rr")rHr@r�r(r(r*�__add__Us
zPathRegistry.__add__r�cCsdd�dd�|jD���d�S)Nz	ORM Path[z -> css�|]}t|�VqdSr'�r�)r��elemr(r(r*r�\s�z'PathRegistry.__str__.<locals>.<genexpr>�])�joinr"rMr(r(r*�__str__[szPathRegistry.__str__cCs|jj�d|j�d�S)N�(�))�	__class__�__name__r"rMr(r(r*�__repr__^szPathRegistry.__repr__)r@rr$r8�r$rL)rNrOr$r/)rQrRrSrrTrr$rUr')rQrRrSrrTr[r$r)r$rO)rdrer$rf)rdrOr$rj)rdrkr$r:)rdr/r$rl)rdr0r$rn)rdror$rp)r$rt)r|r}r$r8)rQrRrSrr$r8)r$r)r"r:r$r1)r"r1r$r:)r$r1�r"r1r$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?rIrK�propertyrCrPrYrZr\r`rbrrhrrr{r�r�r��classmethodr�r�r�r2r�r�r�r�r�r(r(r(r*r#Xs~

�






�
	







#

c@s,eZdZUdZded<ded<dd	d
�ZdS)
�CreatesTokenr(r8r�r+�tokenrer$rfcCsF|�dt���r
t||�S|�dt���rt|j|�St�d|����)N�:zinvalid token: )�endswithr6rf�_DEFAULT_TOKENr>r�
ArgumentError)rHr�r(r(r*r�hs

zCreatesToken.tokenN)r�rer$rf)r�r�r�r�r�r�r(r(r(r*r�bs

r�c@sPeZdZdZdZdZdZZdZdZ	dZ
dZdd	d
�Zddd�Z
es&eZd
Sd
S)r=zXRoot registry, defers to mappers so that
    paths are maintained per-root-mapper.

    r(TFrdrr$�,Union[TokenRegistry, AbstractEntityRegistry]cCsR|tjvrtrt|t�sJ�t|tj|�Sz|jWSty(td|����w)Nz/invalid argument for RootRegistry.__getitem__: )	r�r�r�
isinstancererf�_path_registryrD�
IndexErrorrgr(r(r*�_getitem�s
��zRootRegistry._getitemcC�|Sr'r(rMr(r(r*�_truncate_recursive�riz RootRegistry._truncate_recursiveN)rdrr$r�)r$r=)r�r�r�r�r��
inherit_cacher"r;r�r�r+r9r�r�rrhr(r(r(r*r=qs

�r=c@sDeZdZUdZiZded<dd	d
�Zeddd
��Ze	ddd��Z
dS)r�zcacheable string tokenzDict[str, PathToken]r�r�
bindparams�List[BindParameter[Any]]r$�Tuple[Any, ...]cCs
t|�fSr'r�)rHrr�r(r(r*�_gen_cache_key�s
zPathToken._gen_cache_keyrLcCr&r'r(rMr(r(r*rC�r�zPathToken._path_for_compare�strvaluer�cCs*||jvr
|j|St|�|j|<}|Sr')r�r�)r�r��resultr(r(r*�intern�s

zPathToken.internN)rrr�r�r$r�r�)r�r�r$r�)r�r�r�r�r�r�r�r�rCr�r�r(r(r(r*r��s

r�c@sbeZdZUdZdZded<ded<ddd�Zd	ZdZddd
�Z	ddd�Z
ddd�Zes/eZ
dSdS)rf)r�r<r"r;Trer�r�r<cCs6t�|�}||_||_|j|f|_|j|f|_dSr')r�r�r�r<r"r;)rHr<r�r(r(r*�__init__�s

zTokenRegistry.__init__Fr$�Iterator[PathRegistry]ccs��|j}t|�r
|VdStrt|t�sJ�|js-|j��D]}t|j||j	�VqdS|jrPt
d|j�jrP|Vt
d|j�j
D]}t|j||j	�VqAdS|VdS�Nr�)r<r+rr�rlr�r|�iterate_to_rootrfr�rrd�_is_with_polymorphic�_with_polymorphic_entities�rHr<�mp_ent�entr(r(r*�generate_for_superclasses�s8��������
z'TokenRegistry.generate_for_superclasses�Iterator[_PathRepresentation]ccs��|j}t|�r|jVdStrt|t�sJ�|j��D]
}t|j||j	�jVq|j
rOtd|j�j
rO|jVtd|j�jD]
}t|j||j	�jVq?dS|jVdSr�)r<r+r;rr�rlr|r�rfr�r�rrdr�r�r�r(r(r*�"_generate_natural_for_superclasses�s6��������z0TokenRegistry._generate_natural_for_superclassesrdrc
Cs2z|j|WSty}zt|��|�d}~wwr')r"�	TypeErrorr�)rHrd�errr(r(r*r��s��zTokenRegistry._getitemN)r<r�r�re)r$r�)r$r��rdrr$r)r�r�r�r�r�r�r�r�r�r�r�r�rrhr(r(r(r*rf�s




�rfc@sjeZdZUdZdZdZded<ded<ded<ddd�Zddd�Ze	ddd��Z
ddd�Zes3eZ
dSdS)rn)�propr<r"r;r�rdr|�_wildcard_path_loader_key�_default_path_loader_key�_loader_keyr9Tr0r�zOptional[Mapper[Any]]r|z"Optional[_InternalEntityType[Any]]rdr<rlcCs^td|d�}|}|jjpt|jj�|_|jr|jr#|j|j}}nB|jrL|jrL|j|jvrL|d�	|j�}|j|}|jrI|j|j}d|_n|}n|jre|jre|j|jure|j�
|j�re|j|j}||_||_|j|f|_|j
|f|_
|j|_|jr�tr�t|t�s�J�|j|_|j|_nd|_d|_d|j
|jjf|_|jj|_d|j
f|_dS)Nr/r�T�loader)rr<r9r8r|�inheritsr��_use_mapper_path�with_polymorphic_mappers�_entity_for_mapperr�r�r"r;�_links_to_entityr��_is_relationshiprr�rrd�_wildcard_tokenr�r�r�)rHr<r��insp�natural_parent�subclass_entityr(r(r*r�sZ
���
 ����
�
zPropRegistry.__init__r$cCsXd}tt|jdd���D]\}}||jur|}q
|dur|S|�|jd|d��S)Nr�rr)�	enumerate�reversedr"r�r�)rH�earliestrzr�r(r(r*r�vs
�z PropRegistry._truncate_recursivecCs|jdusJ�||jSr')rdrMr(r(r*�entity_path�s
zPropRegistry.entity_path�+Union[int, slice, _InternalEntityType[Any]]�DUnion[AbstractEntityRegistry, _PathElementType, _PathRepresentation]cCs"t|ttf�r|j|St||�Sr')r�rOrkr"r�rgr(r(r*r��s

zPropRegistry._getitemN)r<rlr�r0)r$rn�r$rl)rdrr$r)r�r�r�r�r�r�r�r�r�r�rr�rrhr(r(r(r*rns



Z
�rnc@s�eZdZUdZdZdZded<ded<ded<ded	<dd
d�Zdd
d�Ze	d dd��Z
e	d!dd��Ze	d"dd��Zd#dd�Z
d$dd�ZesJeZdSdS)%rl)rSr<r�r"rdr;T�!Union[RootRegistry, PropRegistry]r<r/rSrdr8r�cCs�||_||_|j|_||_|j|f|_|jr>|js|jr>|j�|jdj�r1|j|jf|_dS|j|jdjf|_dS|j|_dS)Nr�)	rSr<r�rdr"r9r|r�r;�rHr<rdr(r(r*r��s
�zAbstractEntityRegistry.__init__r$cCs|j��|jSr')r<r�rdrMr(r(r*r��sz*AbstractEntityRegistry._truncate_recursivecCs
|�d�S)Nr)rPrMr(r(r*�root_entity�rsz"AbstractEntityRegistry.root_entityr#cCr�r'r(rMr(r(r*r�r�z"AbstractEntityRegistry.entity_pathr}cCs|jjSr')rdr|rMr(r(r*r|�szAbstractEntityRegistry.mappercCsdS)NTr(rMr(r(r*�__bool__�rizAbstractEntityRegistry.__bool__r�:Union[_PathElementType, _PathRepresentation, PathRegistry]cCs<t|ttf�r|j|S|tjvrt|tj|�St||�Sr')r�rOrkr"r�r�rfrnrgr(r(r*r��s



zAbstractEntityRegistry._getitemN�r<r	rdr/r)r$r/)r$r#)r$r})r$r8)rdrr$r
)r�r�r�r�r�r.r�r�r�r�rrr|rr�rrhr(r(r(r*rl�s*
	

.


�rlc@seZdZdZdS)r�TN)r�r�r�r�r(r(r(r*r��sr�c@s eZdZddd�Zd
d	d
�ZdS)�_ERDict�registryr�cCs
||_dSr')r)rHrr(r(r*r��r4z_ERDict.__init__rSrr$rncCst|j|�||<}|Sr')rnr)rHrS�itemr(r(r*�__missing__�sz_ERDict.__missing__N)rr�)rSrr$rn)r�r�r�r�rr(r(r(r*r�s
rcsJeZdZdZdZd�fdd�Zdd
d�Zddd�Zes!eZ	�Z
S�Z
S)r�)�_cacheTr<r	rdr/cst��||�t|�|_dSr')�superr�rrr
�r�r(r*r�
szCachingEntityRegistry.__init__rSr�defaultr$cCs|j�||�Sr')r�pop)rHrSrr(r(r*rr�zCachingEntityRegistry.popcCs6t|ttf�r|j|St|t�rt||�S|j|Sr')r�rOrkr"r�rfrrgr(r(r*r�s




zCachingEntityRegistry._getitemr)rSrrrr$rr�)r�r�r�r�r�r�rr�rrh�
__classcell__r(r(rr*r�s

�r�cCr&r'r(r)r(r(r*�path_is_entity#r�r�TypeGuard[PropRegistry]cCr&r'r(r)r(r(r*�path_is_property'r,rr�)r"r#r$r%)r"r#r$r-r�)r"r#r$r)Or��
__future__r�	functoolsr�	itertoolsr�logging�operator�typingrrrrr	r
rrr
rr�rr��_typingrrr�sqlr�
sql.cache_keyrr�
interfacesrr|r�
relationshipsrrr�sql.elementsr�sql.visitorsr�util.typingr r!r+r.�
attrgetterr1r�rerjr:rurv�	getLoggerr�rVr3r6r�r�r#r�r=r>�InspectionAttrr�rfrnrlr�rr�rrr(r(r(r*�<module>s�


�


&V`