U
    cc+                  5   @   s  d 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ejefddfddZd6ddZd7ddZdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Z d-d. Z!d/d0 Z"d1d2 Z#d3d4 Z$efefefefefefefefefefefefe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j-feej.feej/feej0feej1feej2feej3feej4feej5feej6feej7feej8feej9feej:feej;feej<feej=fe"fefefe fe!fe!fefefefefefe#fe#fe$fd54Z>dS )8z5Default implementation of SQL comparison operations.
   )	coercions)	operators)roles)type_api)and_)BinaryExpression)
ClauseListcollate)CollectionAggregate)False_)Null)or_)True_)UnaryExpression   )exc)utilNFc           	      K   s^  |d krt j}t||tttf r|tjtjfkrbt|t	ttfrbt
| ttj|||||dS |tjtjfkrt
| ttj|||||dS |rtjtj||| d}nl|tjtjfkrt
| ttj|tjtj|dS |tjtjfkrt
| ttj|tjtj|dS tdntjtj||| d}|rFt
|| ||||dS t
| |||||dS d S )N)type_negate	modifiers)elementoperatorexpr)r   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neboolr   r   expectr   ZConstExprRoleis_distinct_fromis_not_distinct_fromis_is_notr   ArgumentErrorBinaryElementRole)	r   opobjr   reverseZ_python_is_typesZ_any_all_exprresult_typekwargs r+   E/tmp/pip-unpacked-wheel-8u86ls_i/sqlalchemy/sql/default_comparator.py_boolean_compare   s                     r-   c                 K   s<   |d kr"|j r|j }n|jr"tj}t| ||f||d|S )N)r(   r)   )return_typeZis_comparisonr   r   _binary_operate)r   r&   r'   r(   r)   kwr+   r+   r,   _custom_op_operates   s       r1   c                 K   s\   t jtj|| |d}|r$||  }}n
| | }}|d krJ|j||j\}}t|||||dS )Nr   r   )r   r   )r   r   r   r%   Z
comparatorZ_adapt_expressionr   )r   r&   r'   r(   r)   r0   leftrightr+   r+   r,   r/      s       
 r/   c                 K   s2   |t jkrt| |S |t jkr(t| |S t d S N)r   r   r   NotImplementedErrorr   r&   otherr0   r+   r+   r,   _conjunction_operate   s
    



r9   c                 K   s   || S r5   r+   )r   r&   fnr0   r+   r+   r,   _scalar   s    r;   c                 K   sD   t jtj|| |d}d|jkr,|jd \}}t| ||fd|i|S )Nr2   Zin_opsr   )r   r   r   ZInElementRoleZ_annotationsr-   )r   r&   Zseq_or_selectableZ	negate_opr0   r+   r+   r,   _in_impl   s"       
  r<   c                 K   sd   t | jtjs,t | jtjrPt | jjtjrPtjtj	|| |d}t
| ||f|S t| ||f| d S )Nr2   )r   typer   Z	INDEXABLEZTypeDecoratorimplr   r   r   r%   r/   _unsupported_implr7   r+   r+   r,   _getitem_impl   s       r@   c                 O   s   t d|j d S )Nz1Operator '%s' is not supported on this expression)r6   __name__)r   r&   argr0   r+   r+   r,   r?      s    r?   c                 K   s   t | dr| jS |  S dS )z%See :meth:`.ColumnOperators.__inv__`.negation_clauseN)hasattrrC   Z_negater   r&   r0   r+   r+   r,   	_inv_impl   s    
rF   c                 K   s   t | tj| jdS )z%See :meth:`.ColumnOperators.__neg__`.r   r   )r   r   negr=   rE   r+   r+   r,   	_neg_impl   s    rI   c              	   K   sB   t | tjtjtj|| tjdftj|tjkr2tj	ntjd|S )z#See :meth:`.ColumnOperators.match`.r2   )r)   r   )
r-   r   match_opr   r   r   r%   r   Z	MATCHTYPEnot_match_opr7   r+   r+   r,   _match_impl   s"    	rL   c                 K   s   t | tj| jdS )z&See :meth:`.ColumnOperators.distinct`.rG   )r   r   distinct_opr=   rE   r+   r+   r,   _distinct_impl   s
      rN   c              
   K   sX   t | ttjtj|| tjdtjtj|| tjdtjddd||tjkrLtj	ntj|dS )z%See :meth:`.ColumnOperators.between`.r2   F)r   groupZgroup_contents)r   r   )
r   r   r   r   r   r%   r   r   
between_opnot_between_op)r   r&   ZcleftZcrightr0   r+   r+   r,   _between_impl   s2    rR   c                 K   s
   t | |S r5   r	   r7   r+   r+   r,   _collate_impl  s    rS   c                 K   sJ   |d k	rt jtj|| tjd}t| ||f||tjkr:tjntjd|S )Nr2   )flagsr   )	r   r   r   r%   r   regexp_replace_opr-   regexp_match_opnot_regexp_match_op)r   r&   patternrT   r0   r+   r+   r,   _regexp_match_impl
  s&    rY   c                 K   sN   t jtj|| tjd}|d k	r4t jtj|| tjd}t| ||f||d|S )Nr2   )replacementrT   )r   r   r   r%   r   rU   r/   )r   r&   rX   rZ   rT   r0   r+   r+   r,   _regexp_replace_impl  s.       r[   )4r   r   invaddmulsubdivmodtruedivZ	custom_opZjson_path_getitem_opZjson_getitem_opZ	concat_opZany_opZall_opltler   gtger   r    r!   like_opilike_opnot_like_opnot_ilike_opZcontains_opZstartswith_opZendswith_opZdesc_opZasc_opZnulls_first_opZnulls_last_opin_op	not_in_opr"   r#   r
   rJ   rK   rM   rP   rQ   rH   getitemlshiftrshiftcontainsrV   rW   rU   )FN)FN)?__doc__ r   r   r   r   elementsr   r   r   r
   r   r   r   r   r   r   r   r   ZNoneTyper   r-   r1   r/   r9   r;   r<   r@   r?   rF   rI   rL   rN   rR   rS   rY   r[   Z_create_anyZ_create_allrf   re   r   rd   rc   r   r!   r    ri   rj   rg   rh   Znot_contains_opZnot_startswith_opZnot_endswith_opZ_create_descZ_create_ascZ_create_nulls_firstZ_create_nulls_lastrl   rk   r"   r#   Zoperator_lookupr+   r+   r+   r,   <module>   s   
U

	