a
    •˜ëjBA  ã                ?   @  sX  U d Z ddlm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 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j!d!ed"�Z"ej#�r˜dd#lm$Z$ dd$lm%Z% dd%lm&Z& dd&e'dƒe(fdd'œd(d)d*d+d,d-d.d*d/d0œ	d1d2„Z)dnd(d3d*d,d4d*d(d5œd6d7„Z*d&dd8œd(d)d9d,d:d*d;d5œd<d=„Z+d(d)d*d*d(d>œd?d@„Z,d(d)dAd*d(dBœdCdD„Z-d(d)dEd)d*d(dFœdGdH„Z.d(d)d*d*d(d>œdIdJ„Z/d(d)d*d*dKdLœdMdN„Z0d(d)d*d(dOœdPdQ„Z1d(d)d*d(dOœdRdS„Z2d(d)d*d(dOœdTdU„Z3d(d)d*d*d(d>œdVdW„Z4d(d)d*d(dOœdXdY„Z5d(d)d*d*d*d(dZœd[d\„Z6d]d)d^d*d]d_œd`da„Z7d]d)d*dbd*d(dcœddde„Z8d(d)d*d*dbd*d(dfœdgdh„Z9e,e j:fe,e j:fe1e j:fe+e j:fe+e j:fe+e j:fe+e j:fe+e j:fe+e j:fe+e j:fe+e j:fe3e j:fe+e j:fe+e j:fe+e j:fe+e j:fe*e j:fe+e j:fe+e j:fe+e j:fe-e  ;diej<i¡fe-e  ;diej=i¡fe)e  ;djej>i¡fe)e  ;djej?i¡fe)e  ;djej@i¡fe)e  ;djejAi¡fe)e  ;djejBi¡fe)e  ;djejCi¡fe)e  ;djejDi¡fe)e  ;djejEi¡fe)e  ;djejFi¡fe)e  ;djejGi¡fe)e  ;djejHi¡fe)e  ;djejIi¡fe)e  ;djejJi¡fe)e  ;djejKi¡fe)e  ;djejLi¡fe)e  ;djejMi¡fe)e  ;djejNi¡fe)e  ;djejOi¡fe-e  ;diejPi¡fe-e  ;diejQi¡fe-e  ;diejRi¡fe-e  ;diejSi¡fe.e  ;djejTi¡fe.e  ;djejUi¡fe)e  ;djejVi¡fe)e  ;djejWi¡fe7e j:fe4e j:fe4e j:fe5e j:fe6e j:fe6e j:fe2e j:fe/e j:fe0e j:fe0e j:fe0e j:fe8e j:fe8e j:fe9e j:fdkœ>ZXdleYdm< dS )oz4Default implementation of SQL comparison operations.é    )ÚannotationsN)ÚAny)ÚCallable)ÚDict)ÚNoReturn)ÚOptional)ÚTuple)ÚType)ÚUnioné   )Ú	coercions)Ú	operators)Úroles)Útype_api)Úand_)ÚBinaryExpression)ÚClauseElement)ÚCollationClause)ÚCollectionAggregate)ÚExpressionClauseList)ÚFalse_)ÚNull)ÚOperatorExpression)Úor_)ÚTrue_)ÚUnaryExpression)ÚOperatorTypeé   )Úexc)ÚutilÚ_T)Úbound)ÚColumnElement)Ú	custom_op)Ú
TypeEngineF)Ú	negate_opÚreverseÚ_python_is_typesÚresult_typezColumnElement[Any]r   r   zOptional[OperatorType]ÚboolzTuple[Type[Any], ...]zOptional[TypeEngine[bool]]zOperatorExpression[bool])	ÚexprÚopÚobjr%   r&   r'   r(   ÚkwargsÚreturnc                K  sl  |d u rt j}t||tttf ƒ�r"|tjtjfv rdt|t	ttfƒrdt
j| t tj|¡||||d�S |tjtjfv r”t
j| t tj|¡||||d�S | jr°tjtj||| d�}np|tjtjfv rât
j| t tj|¡tjtj|d�S |tjtjfv �rt
j| t tj|¡tjtj|d�S t d¡‚ntjtj||| d�}|�rRt
j|| ||||d�S t
j| |||||d�S d S )N)Útype_ÚnegateÚ	modifiers)ÚelementÚoperatorr*   )r0   r/   z~Only '=', '!=', 'is_()', 'is_not()', 'is_distinct_from()', 'is_not_distinct_from()' operators can be used with None/True/False)r   ÚBOOLEANTYPEÚ
isinstancer   r   r   r   ÚeqÚner)   r   Ú_construct_for_opr   Úexpectr   ZConstExprRoleÚis_distinct_fromÚis_not_distinct_fromZ_is_collection_aggregateÚis_Úis_notr   ÚArgumentErrorÚBinaryElementRole)r*   r+   r,   r%   r&   r'   r(   r-   © r@   ú`/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/sqlalchemy/sql/default_comparator.pyÚ_boolean_compare2   sŠ    
ÿúþú
ÿûûÿ
ÿú	úrB   zcustom_op[Any]zOptional[TypeEngine[Any]])r*   r+   r,   r&   r(   Úkwr.   c                 K  s<   |d u r"|j r|j }n|jr"tj}t| ||f||dœ|¤ŽS )N©r&   r(   )Úreturn_typeZis_comparisonr   r4   Ú_binary_operate)r*   r+   r,   r&   r(   rC   r@   r@   rA   Ú_custom_op_operate�   s    ÿÿÿrG   rD   zroles.BinaryElementRole[Any]zOptional[TypeEngine[_T]]zOperatorExpression[_T]c          	      K  s^   t jtj|| |d�}|r$||  }}n
| | }}|d u rJ|j ||j¡\}}tj|||||d�S )N©r*   r3   )r/   r1   )r   r9   r   r?   Z
comparatorZ_adapt_expressionr   r8   )	r*   r+   r,   r&   r(   rC   Zcoerced_objÚleftÚrightr@   r@   rA   rF   £   s    	
ÿ
ÿ
ÿrF   )r*   r+   ÚotherrC   r.   c                 K  s2   |t ju rt| |ƒS |t ju r(t| |ƒS tƒ ‚d S ©N)r   r   r   ÚNotImplementedError©r*   r+   rK   rC   r@   r@   rA   Ú_conjunction_operate¿   s
    



rO   z2Callable[[ColumnElement[Any]], ColumnElement[Any]])r*   r+   ÚfnrC   r.   c                 K  s   || ƒS rL   r@   )r*   r+   rP   rC   r@   r@   rA   Ú_scalarÊ   s    rQ   r   )r*   r+   Úseq_or_selectabler%   rC   r.   c                 K  sD   t jtj|| |d�}d|jv r,|jd \}}t| ||fd|i|¤ŽS )NrH   Zin_opsr%   )r   r9   r   ZInElementRoleZ_annotationsrB   )r*   r+   rR   r%   rC   r@   r@   rA   Ú_in_implÓ   s    
ÿ
ÿÿÿrS   c                 K  sl   t | jtjƒs,t | jtjƒrTt | jjtjƒrTtjtj	|| |d�}t
| ||fi |¤ŽS t| ||fi |¤Ž d S )NrH   )r5   Útyper   Z	INDEXABLEZTypeDecoratorZimpl_instancer   r9   r   r?   rF   Ú_unsupported_implrN   r@   r@   rA   Ú_getitem_implå   s    ÿþý
ÿrV   r   )r*   r+   ÚargrC   r.   c                 O  s   t d|j ƒ‚d S )Nz1Operator '%s' is not supported on this expression)rM   Ú__name__)r*   r+   rW   rC   r@   r@   rA   rU   õ   s    ÿrU   )r*   r+   rC   r.   c                 K  s   t | dƒr| jS |  ¡ S dS )z%See :meth:`.ColumnOperators.__inv__`.Únegation_clauseN)ÚhasattrrY   Z_negate©r*   r+   rC   r@   r@   rA   Ú	_inv_implý   s    
r\   c                 K  s   t | tj| jd�S )z%See :meth:`.ColumnOperators.__neg__`.©r3   r/   )r   r   ÚnegrT   r[   r@   r@   rA   Ú	_neg_impl
  s    r_   c                 K  s   t | tj| jd�S )z)See :meth:`.ColumnOperators.bitwise_not`.r]   )r   r   Úbitwise_not_oprT   r[   r@   r@   rA   Ú_bitwise_not_impl  s    
ÿra   c              	   K  sB   t | tjtjtj|| tjd�ftj|tju r2tj	ntjdœ|¤ŽS )z#See :meth:`.ColumnOperators.match`.rH   )r(   r%   )
rB   r   Úmatch_opr   r9   r   r?   r   Z	MATCHTYPEÚnot_match_oprN   r@   r@   rA   Ú_match_impl  s"    üý	ÿóñrd   c                 K  s   t | tj| jd�S )z&See :meth:`.ColumnOperators.distinct`.r]   )r   r   Údistinct_oprT   r[   r@   r@   rA   Ú_distinct_impl3  s    
ÿrf   )r*   r+   ÚcleftÚcrightrC   r.   c                 K  s\   t | tjtjtjtjt	j
|| tjd�tjt	j
|| tjd�dd�||tju rPtjntj|d�S )z%See :meth:`.ColumnOperators.between`.rH   F©Úgroup©r0   r1   )r   r   Ú_construct_for_listr   r   r   ÚNULLTYPEr   r9   r   r?   Ú
between_opÚnot_between_op)r*   r+   rg   rh   rC   r@   r@   rA   Ú_between_impl<  s2    üüñÿçrp   zColumnElement[str]Ústr)r*   r+   Ú	collationrC   r.   c                 K  s   t  | |¡S rL   )r   Z_create_collation_expression)r*   r+   rr   rC   r@   r@   rA   Ú_collate_impla  s    rs   zOptional[str])r*   r+   ÚpatternÚflagsrC   r.   c                 K  s*   t | tjtj|| tjd�|tjd|id�S )NrH   ru   rk   )r   r   r9   r   r?   r   Úcomma_opÚnot_regexp_match_op)r*   r+   rt   ru   rC   r@   r@   rA   Ú_regexp_match_implg  s    üörx   )r*   r+   rt   Úreplacementru   rC   r.   c                 K  sL   t | tjtjtjtjt	j
|| tjd�tjt	j
|| tjd�dd�|d|id�S )NrH   Fri   ru   )r1   )r   r   rl   r   rv   r   rm   r   r9   r   r?   )r*   r+   rt   ry   ru   rC   r@   r@   rA   Ú_regexp_replace_impl|  s,    üüñìrz   rP   r%   )>r   r   ÚinvÚaddÚmulÚsubÚdivÚmodZbitwise_xor_opZbitwise_or_opZbitwise_and_opr`   Zbitwise_lshift_opZbitwise_rshift_opÚtruedivÚfloordivr#   Zjson_path_getitem_opZjson_getitem_opZ	concat_opZany_opZall_opÚltÚler7   ÚgtÚger6   r:   r;   Úlike_opÚilike_opÚnot_like_opÚnot_ilike_opZcontains_opZicontains_opZstartswith_opZistartswith_opZendswith_opZiendswith_opZdesc_opZasc_opZnulls_first_opZnulls_last_opÚin_opÚ	not_in_opr<   r=   Zcollaterb   rc   re   rn   ro   r^   ÚgetitemÚlshiftÚrshiftÚcontainsZregexp_match_oprw   Zregexp_replace_opz„Dict[str, Tuple[Callable[..., ColumnElement[Any]], util.immutabledict[str, Union[OperatorType, Callable[..., ColumnElement[Any]]]]]]Úoperator_lookup)FN)ZÚ__doc__Ú
__future__r   Útypingr   r   r   r   r   r   r	   r
   Ú r   r   r   r   Úelementsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ÚTypeVarr    ÚTYPE_CHECKINGr"   r#   r$   rT   r)   rB   rG   rF   rO   rQ   rS   rV   rU   r\   r_   ra   rd   rf   rp   rs   rx   rz   Ú
EMPTY_DICTZimmutabledictZ_create_anyZ_create_allr†   r…   r6   r„   rƒ   r7   r;   r:   r‰   rŠ   r‡   rˆ   Znot_contains_opZnot_icontains_opZnot_startswith_opZnot_istartswith_opZnot_endswith_opZnot_iendswith_opZ_create_descZ_create_ascZ_create_nulls_firstZ_create_nulls_lastrŒ   r‹   r<   r=   r‘   Ú__annotations__r@   r@   r@   rA   Ú<module>   sN  
ø"b  ûú	
	%+þþþþþþþþþþþþþþþþþþþþþþ€ø