ó
H`¾Tc           @   së   d  Z  d d l m Z m Z d d l m Z d d l m Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z m Z m Z m Z d e j f d	 „  ƒ  YZ d
 S(   s5   Default implementation of SQL comparison operations.
i   (   t   exct   utili   (   t	   operators(   t   type_api(   t   BindParametert   True_t   False_t   BinaryExpressiont   Nullt   _const_exprt   _clause_element_as_exprt
   ClauseListt   ColumnElementt
   TextClauset   UnaryExpressiont   collatet   _is_literalt   _literal_as_textt   ClauseElementt   and_t   or_(   t
   SelectBaset   Aliast
   Selectablet   ScalarSelectt   _DefaultColumnComparatorc           B   sæ  e  Z d  Z e j d „  ƒ Z d „  Z d „  Z d „  Z d; e
 e j e f d „ Z e
 d; d „ Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z i) e f d 6e f d 6e f d 6e f d 6e f d 6e f d 6e f d 6e f d 6e f d 6e f d 6e f d 6e e j f d 6e e j f d 6e e j f d 6e e j f d 6e e j f d  6e e j f d! 6e e j  f d" 6e e j! f d# 6e e j" f d$ 6e e j# f d% 6e e j$ f d& 6e e j% f d' 6e e j& f d( 6e e' j( f d) 6e e' j) f d* 6e e' j* f d+ 6e e' j+ f d, 6e e j, f d- 6e e j- f d. 6e e j. f d/ 6e e j/ f d0 6e f d1 6e f d2 6e f d3 6e f d4 6e f d5 6e f d6 6e f d7 6e f d8 6e f d9 6Z d: „  Z0 RS(<   s   Defines comparison and math operations.

    See :class:`.ColumnOperators` and :class:`.Operators` for descriptions
    of all operations.

    c         C   s
   |  j  j S(   N(   t   exprt   type(   t   self(    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyR      s    c         O   s5   |  j  | j } | d |  |  j | | | d | Ž S(   Ni    i   (   R   t   __name__R   (   R   t   opt   othert   kwargst   o(    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   operate!   s    c      	   K   s:   |  j  | j } | d |  |  j | | d t | d | ŽS(   Ni    t   reversei   (   R   R   R   t   True(   R   R   R   R    R!   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   reverse_operate%   s    c         C   s   | | j  f S(   sð  evaluate the return type of <self> <op> <othertype>,
        and apply any adaptations to the given operator.

        This method determines the type of a resulting binary expression
        given two source types and an operator.   For example, two
        :class:`.Column` objects, both of the type :class:`.Integer`, will
        produce a :class:`.BinaryExpression` that also has the type
        :class:`.Integer` when compared via the addition (``+``) operator.
        However, using the addition operator with an :class:`.Integer`
        and a :class:`.Date` object will produce a :class:`.Date`, assuming
        "days delta" behavior by the database (in reality, most databases
        other than Postgresql don't accept this particular operation).

        The method returns a tuple of the form <operator>, <type>.
        The resulting operator and type will be those applied to the
        resulting :class:`.BinaryExpression` as the final operator and the
        right-hand side of the expression.

        Note that only a subset of operators make usage of
        :meth:`._adapt_expression`,
        including math operators and user-defined operators, but not
        boolean comparison or special SQL keywords like MATCH or BETWEEN.

        (   R   (   R   R   t   other_comparator(    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _adapt_expression*   s    c         K   sf  t  | | t t t f ƒ rý | t j t j f k rw t  | t t t f ƒ rw t | t	 | ƒ | d t
 j d | d | ƒS| t j t j f k r± t | t | ƒ t j d t j ƒS| t j t j f k rë t | t | ƒ t j d t j ƒSt j d ƒ ‚ n |  j | | | ƒ } | r=t | | | d t
 j d | d | ƒSt | | | d t
 j d | d | ƒSd  S(   Nt   type_t   negatet	   modifierssM   Only '=', '!=', 'is_()', 'isnot()' operators can be used with None/True/False(   t
   isinstanceR   R   R   R   t   eqt   net   boolR   R   R   t   BOOLEANTYPEt   is_R	   t   isnotR    t   ArgumentErrort   _check_literal(   R   R   R   t   objR)   R#   t   _python_is_typesR    (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _boolean_compareE   s<    			
	
		c   	      K   s{   |  j  | | | ƒ } | r+ | | } } n | | } } | d  k re | j j | | j ƒ \ } } n  t | | | d | ƒS(   NR(   (   R3   t   Nonet
   comparatorR'   R   (	   R   R   R   R4   R#   t   result_typet   kwt   leftt   right(    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _binary_operates   s    	c         K   sE   | t  j k r t | | ƒ S| t  j k r8 t | | ƒ St ƒ  ‚ d  S(   N(   R   R   R   t   NotImplementedError(   R   R   R   R   R:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _conjunction_operate‚   s
    c         K   s
   | | ƒ S(   N(    (   R   R   R   t   fnR:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _scalarŠ   s    c         K   s´  t  | ƒ } t | t ƒ r4 |  j | | | d | ƒSt | t ƒ re |  j | | | j ƒ  d | | St | t t f ƒ r– |  j | | | d | | St | t ƒ r» t	 j
 d | ƒ ‚ n  g  } x| | D]t } t | ƒ st | t j ƒ s/t	 j
 d | ƒ ‚ q/n* | d  k rt ƒ  } n | j | | ƒ } | j | ƒ qÈ Wt | ƒ d k r‰t j d | ƒ | t j k r|| | k S| | k Sn  |  j | | t | Œ  j d | ƒ d | ƒS(   NR)   s>   in_() accepts either a list of expressions or a selectable: %ri    sÈ   The IN-predicate on "%s" was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.  Consider alternative strategies for improved performance.t   against(   R
   R+   R   R6   R   t	   as_scalarR   R   R   R    t   InvalidRequestErrorR   R   t   ColumnOperatorsR7   R   t   _bind_paramt   appendt   lenR   t   warnt   in_opR   t
   self_group(   R   R   R   t   seq_or_selectablet	   negate_opR:   t   argsR!   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _in_impl   sF    

	
c         O   s   t  d | j ƒ ‚ d  S(   Ns1   Operator '%s' is not supported on this expression(   R>   R   (   R   R   R   t   argR:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _unsupported_implÊ   s    c         K   s$   t  | d ƒ r | j S| j ƒ  Sd S(   s%   See :meth:`.ColumnOperators.__inv__`.t   negation_clauseN(   t   hasattrRR   t   _negate(   R   R   R   R:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt	   _inv_implÎ   s    c         K   s   t  | d t j ƒS(   s%   See :meth:`.ColumnOperators.__neg__`.t   operator(   R   R   t   neg(   R   R   R   R:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt	   _neg_implÕ   s    c         K   s+   |  j  | t j |  j | t j | ƒ |  S(   s#   See :meth:`.ColumnOperators.match`.(   R6   R   t   match_opR3   (   R   R   R   R   R:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _match_implÙ   s
    	c         K   s   t  | d t j d | j ƒS(   s&   See :meth:`.ColumnOperators.distinct`.RV   R(   (   R   R   t   distinct_opR   (   R   R   R   R:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _distinct_implá   s    c         K   sy   t  | t |  j | t j | ƒ |  j | t j | ƒ d t j d t d t ƒ| d | t j k ri t j n t j d | ƒS(   s%   See :meth:`.ColumnOperators.between`.RV   t   groupt   group_contentsR)   R*   (   R   R   R3   R   R   t   Falset
   between_opt   notbetween_op(   R   R   R   t   cleftt   crightR:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _between_implæ   s    		c         K   s   t  | | ƒ S(   N(   R   (   R   R   R   R   R:   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   _collate_implõ   s    R   R   t   invt   addt   mult   subt   divt   modt   truedivt	   custom_opt	   concat_opt   ltt   leR-   t   gtt   geR,   t   like_opt   ilike_opt
   notlike_opt   notilike_opt   contains_opt   startswith_opt   endswith_opt   desc_opt   asc_opt   nullsfirst_opt   nullslast_opRJ   t   notin_opR0   R1   R   RY   R[   R`   Ra   RW   t   getitemt   lshiftt   rshiftc         C   sÚ   t  | t t f ƒ rO t  | t ƒ rK | j j rK | j ƒ  } | j | _ n  | St | d ƒ rm | j ƒ  } n! t  | t	 j
 j ƒ rŽ | j } n  t  | t t f ƒ r­ | j ƒ  St  | t t f ƒ sÒ | j | | ƒ S| Sd  S(   Nt   __clause_element__(   R+   R   R   R   R   t   _isnullt   _cloneRS   R‚   R   t
   TypeEnginet
   ComparatorR   R   R   RC   RF   (   R   R   RV   R   (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyR3   &  s    
N(1   R   t
   __module__t   __doc__R   t   memoized_propertyR   R"   R%   R'   R7   R_   t   NoneTypeR.   R6   R=   R?   RA   RO   RQ   RU   RX   RZ   R\   Rd   Re   R   Rr   Rq   R,   Rp   Ro   R-   Ru   Rv   Rs   Rt   t   notcontains_opt   notstartswith_opt   notendswith_opR   t   _create_desct   _create_asct   _create_nullsfirstt   _create_nullslastR~   RJ   R0   R1   R3   (    (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyR      sz   			-			=							


















N(   Rˆ   t    R    R   R   R   t   elementsR   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   t
   selectableR   R   R   R   RE   R   (    (    (    sg   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/default_comparator.pyt   <module>	   s   p"