관리-도구
편집 파일: util.cpython-38.pyc
U -?�fͻ � @ s� 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�dQdQdRdSdTdU�dVdW�Z\dXdQdYdZ�d[d\�Z]d]dQdYd^�d_d`�Z^d]dadbdYdc�ddde�Z_dfdOdgdh�didj�Z`dkdkdkdkdkdl�dmdndndndndndodp�dqdr�Zadsdsdt�dudv�Zbdwdx� Zcdydz� Zdd{d|� ZedQd}dt�d~d�Zfd�d�� Zgd�d�� Zhd�d�� ZidQdQdnd��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�ZrdNd�dNd��d�d��Zsd�dRdRdRdRd��d�d��Zted�d�dnd�d��d�d���Zued�d�dnd�d��d�d���Zud�d�dnd�d��d�d��Zud�d�d��ZvG d�d�� d�ejw�ZxG d�d�� d�eH�ZyG d�d�� d�ex�Zzd�d�d�d�d�d��d�d��Z{d�d�dt�d�d��Z|d�d�d�d�d�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])�boundr2 zOptional[FromClause]z(Optional[AbstractSet[ColumnClause[Any]]]zColumnElement[bool])�a�b�a_subset�consider_as_foreign_keys�returnc 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 rT )r4 Z_join_condition)rQ rR rS rT � rV �C/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/util.py�join_condition_ s �rX zList[FromClause]z List[int])�clauses�join_torU c C sD t t|��}g }t| �D ]&\}}|D ]}|�|�r$|�|� q$q|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)rY rZ �selectables�idx�i�f�srV rV rW �find_join_source� s rd zSequence[FromClause])rY � join_fromrU c C s� t t|��}g }t| �D ]*\}}|D ]}|�|�r$|�|� qq$qt|�dkr�g }|D ]:}| | }|D ](}tt|���t|��rh|�|� qXqhqX|r�|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 ) r[ r r\ r] r^ �len�set�surface_selectables�intersection) rY re r_ Zliberal_idxra rb rc Zconservative_idxr` rV rV rW �#find_left_clause_that_matches_given� s( � rj rC �Optional[ColumnElement[Any]])rY rZ �onclauserU c s g }t t|��}t� �dkr2|dk r2d}t|�}nd}d}t� �D ]t\}}|�|g�D ]^} |r�|dk sjt�t |j��| j�� |�r�|� |� qBqV|dk s�t�|| �rV|� |� qBqVqBt|�dkr�t t dd� � D �� ��� �fdd�|D �}|�s|dk �rttt� ���S |S dS )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 rV )r Z_hide_froms)�.0rb rV rV rW � <listcomp>� s z1find_left_clause_to_join_from.<locals>.<listcomp>c s g | ]}� | �kr|�qS rV rV )rm ra �rY ZtoremoverV rW rn � s )rg r rf r# r\ � difference�AssertionError�c�union� issupersetr^ r4 Z _can_joinr r[ �range) rY rZ rl r` r_ Zresolve_ambiguityZcols_in_onclausera rb rc rV ro rW �find_left_clause_to_join_from� s2 �rv zOCallable[[BinaryExpression[Any], ColumnElement[Any], ColumnElement[Any]], None]�None)�fn�exprrU c s0 g �ddd�� ��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:: 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. r'