File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/__pycache__/util.cpython-310.pyc
o
���gֻ � @ s0 d Z ddlmZ ddlmZ ddlZddlmZ ddlZddlm Z ddlm
Z
ddlmZ dd lmZ dd
lm
Z
ddlmZ ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl m#Z# ddl$m%Z% dd l$m&Z& dd!l'm(Z( dd"l)m*Z* dd#l+m,Z, dd$l+m-Z- dd%l+m.Z. dd&l+m/Z/ dd'l+m0Z0 dd(l+m1Z1 dd)l+m2Z2 dd*l+m3Z3 dd+l+m4Z4 dd,l+m5Z5 dd-l+m6Z6 dd.l+m7Z7 dd/l+m8Z8 dd0l9m:Z: dd1l;m<Z< dd2l;m=Z= dd3l;m>Z> dd4l;m?Z? dd5l;m@Z@ dd6l;mAZA dd7l;mBZB dd8lmCZC d9d:lmDZD d9d;lmEZE d9d<lFmGZG d9d=lFmHZH ej�r�dd>lmIZI dd?lmJZJ dd@lmKZK ddAl+mLZL ddBl+mMZM ddCl;mNZN ddDl;mOZO ddEl;mPZP ddFlmQZQ ddGlmRZR ddHlmSZS d9dIlTmUZU d9dJlTmVZV d9dKlTmWZW d9dLlTmXZX d9dMlYmZZZ edNdOdP�Z[ d�d�dZd[�Z\d�d`da�Z]d�ddde�Z^d�didj�Z_d�dodp�Z`dqdqdqdqdqdr�d�d|d}�Zad�dd��Zbd�d�� Zcd�d�� Zdd�d�� Zed�d�d��Zfd�d�� Zgd�d�� Zhd�d�� Zid�d�d��Zjd�d�� Zkd�d�� ZlG d�d�� d��Zmd�d�� ZnG d�d�� d�em�ZoG d�d�� d�ep�ZqG d�d�� d�em�Zrd�d�d��Zs d�d�d�d��Zted�d�d���Zued�d�d���Zud�d�d��Zu qd�d�d��ZvG d�d�� d�ejw�ZxG d�d�� d�eH�ZyG d�d�� d�ex�Zz d�d�d�dƄZ{d�d�dȄZ|d�d�dЄZ}dS )�z;High level utilities which build upon other modules here.
� )�annotations)�dequeN)�chain)�AbstractSet)�Any)�Callable)�cast)�
Collection)�Dict)�Iterable)�Iterator)�List)�Optional)�overload)�Sequence)�Tuple)�
TYPE_CHECKING)�TypeVar)�Union� )� coercions)� operators)�roles)�visitors��is_text_clause)�_deep_annotate)�_deep_deannotate)�_shallow_annotate)�_expand_cloned)�
_from_objects)�HasCacheKey)�sort_tables)�
_find_columns)�_label_reference)�_textual_label_reference)�
BindParameter)�
ClauseElement)�ColumnClause)�
ColumnElement)�Grouping)�KeyedColumnElement)�Label)�NamedColumn)�Null)�UnaryExpression)�Column)�Alias)�
FromClause)�FromGrouping)�Join)�ScalarSelect)�
SelectBase)�TableClause)�_ET� )�exc)�util)�Literal)�Protocol)�_EquivalentColumnMap)�_LimitOffsetType)�_TypeEngineArgument)�BinaryExpression)�
TextClause)�_JoinTargetElement)�_SelectIterable)�
Selectable)�_TraverseCallableType)�ExternallyTraversible)�ExternalTraversal)�_AnyExecuteParams)�_AnyMultiExecuteParams)�_AnySingleExecuteParams)�_CoreSingleExecuteParams)�Row�_CE�ColumnElement[Any])�bound�ar2 �b�a_subset�Optional[FromClause]�consider_as_foreign_keys�(Optional[AbstractSet[ColumnClause[Any]]]�return�ColumnElement[bool]c C s t j| |||d�S )a Create a join condition between two tables or selectables.
e.g.::
join_condition(tablea, tableb)
would produce an expression along the lines of::
tablea.c.id == tableb.c.tablea_id
The join is determined based on the foreign key relationships
between the two selectables. If there are multiple ways
to join, or no way to join, an error is raised.
:param a_subset: An optional expression that is a sub-component
of ``a``. An attempt will be made to join to just this sub-component
first before looking at the full ``a`` construct, and if found
will be successful even if there are other ways to join to ``a``.
This allows the "right side" of a join to be passed thereby
providing a "natural join".
)rS rU )r4 �_join_condition)rQ rR rS rU � rZ �>/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/util.py�join_condition_ s �r\ �clauses�List[FromClause]�join_to� List[int]c C sD t t|��}g }t| �D ]\}}|D ]}|�|�r|�|� qq|S )a� Given a list of FROM clauses and a selectable,
return the first index and element from the list of
clauses which can be joined against the selectable. returns
None, None if no match is found.
e.g.::
clause1 = table1.join(table2)
clause2 = table4.join(table5)
join_to = table2.join(table3)
find_join_source([clause1, clause2], join_to) == clause1
)�listr � enumerate�is_derived_from�append)r] r_ �selectables�idx�i�f�srZ rZ r[ �find_join_source� s
��rj �Sequence[FromClause]� join_fromc C s� t t|��}g }t| �D ]\}}|D ]}|�|�r |�|� nqqt|�dkrNg }|D ]}| | }|D ]}tt|���t|��rH|�|� nq4q,|rN|S |S )z�Given a list of FROM clauses and a selectable,
return the indexes from the list of
clauses which is derived from the selectable.
r ) ra r rb rc rd �len�set�surface_selectables�intersection) r] rl re �liberal_idxrg rh ri �conservative_idxrf rZ rZ r[ �#find_left_clause_that_matches_given� s0
�� �
��rs rC �onclause�Optional[ColumnElement[Any]]c
s g }t t|��}t� �dkr|durd}t|�}nd}d}t� �D ]:\}}|�|g�D ]/} |rI|dus5J �t |j��| j��|�rH|� |� nq+|dusSt
�|| �rZ|� |� nq+q!t|�dkrwt tdd� � D �� ��� �fdd�|D �}|s�|dur�t
tt� ���S |S )a Given a list of FROM clauses, a selectable,
and optional ON clause, return a list of integer indexes from the
clauses list indicating the clauses that can be joined from.
The presence of an "onclause" indicates that at least one clause can
definitely be joined from; if the list of clauses is of length one
and the onclause is given, returns that index. If the list of clauses
is more than length one, and the onclause is given, attempts to locate
which clauses contain the same columns.
r NTFc S s g | ]}t |j��qS rZ )r �_hide_froms)�.0rh rZ rZ r[ �
<listcomp>� s z1find_left_clause_to_join_from.<locals>.<listcomp>c s g | ]
}� | �vr|�qS rZ rZ )rw rg �r] �toremoverZ r[ rx � s )rn r rm r# rb �
difference�c�union�
issupersetrd r4 � _can_joinr ra �range)
r] r_ rt rf re �resolve_ambiguity�cols_in_onclauserg rh ri rZ ry r[ �find_left_clause_to_join_from� s8
�
���r� �fn�OCallable[[BinaryExpression[Any], ColumnElement[Any], ColumnElement[Any]], None]�expr�Nonec s* g �d� ��fdd��t �|�� d�dS ) a� Produce a traversal of the given expression, delivering
column comparisons to the given function.
The function is of the form::
def my_fn(binary, left, right): ...
For each binary expression located which has a
comparison operator, the product of "left" and
"right" will be delivered to that function,
in terms of that binary.
Hence an expression like::
and_((a + b) == q + func.sum(e + f), j == r)
would have the traversal:
.. sourcecode:: text
a <eq> q
a <eq> e
a <eq> f
b <eq> q
b <eq> e
b <eq> f
j <eq> r
That is, every combination of "left" and
"right" that doesn't further contain
a binary comparison is passed as pairs.
�elementr'