B
    .`@              j   @   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lmZ ddlmZ ddlmZ ddlmZ ejr
ddlmZ neZG dd deZG dd deZG dd deZeeeehZeeeeee
hZdd Zd d! Z d"d# Z!e d$d% Z"d&d' Z#d(d) Z$d*d+ Z%d,d- Z&e d.d/ Z'e d0d1 Z(e d2d3 Z)e d4d5 Z*d6d7 Z+d8d9 Z,e dd;d<Z-e dd=d>Z.e dd?d@Z/e ddAdBZ0e ddDdEZ1e ddFdGZ2e dHdI Z3e dJdK Z4dLdM Z5dNdO Z6dPdQ Z7dRdS Z8e ddTdUZ9e ddVdWZ:e ddXdYZ;e ddZd[Z<e dd\d]Z=e dd^d_Z>e d`da Z?e dbdc Z@ddde ZAe dfdg ZBe dhdi ZCdjdk ZDdldm ZEdndo ZFdpdq ZGdrds ZHdtdu ZIdvdw ZJdxdy ZKdzd{ ZLd|d} ZMd~d ZNdd ZOe	e%e&eefZPdd ZQeeee
eee
eiZRdd ZSeTeEeegUeegZVeVTeeJeKgZWejXdddZYejXdddZZejXdddZ[e!de"de6de7dedeJdeKdedededededededeEdeDde?de@de/de0de-de.de3de4de)de*dedede'de(deBdeCdededede
de1de2de5de	de%de&dededeAdeFdeGde+de#de$deYdeZeZe[e[i5Z\dd Z]d:S )z*Defines operators used in SQL expressions.    )add)and_)contains)eq)ge)getitem)gt)inv)le)lshift)lt)mod)mul)ne)neg)or_)rshift)sub)truediv   )util)divc               @   sP   e Zd ZdZdZdd Zdd Zdd ZdddZdddZ	dd Z
dd ZdS )	Operatorsa  Base of comparison and logical operators.

    Implements base methods
    :meth:`~sqlalchemy.sql.operators.Operators.operate` and
    :meth:`~sqlalchemy.sql.operators.Operators.reverse_operate`, as well as
    :meth:`~sqlalchemy.sql.operators.Operators.__and__`,
    :meth:`~sqlalchemy.sql.operators.Operators.__or__`,
    :meth:`~sqlalchemy.sql.operators.Operators.__invert__`.

    Usually is used via its most common subclass
    :class:`.ColumnOperators`.

     c             C   s   |  t|S )a-  Implement the ``&`` operator.

        When used with SQL expressions, results in an
        AND operation, equivalent to
        :func:`_expression.and_`, that is::

            a & b

        is equivalent to::

            from sqlalchemy import and_
            and_(a, b)

        Care should be taken when using ``&`` regarding
        operator precedence; the ``&`` operator has the highest precedence.
        The operands should be enclosed in parenthesis if they contain
        further sub expressions::

            (a == 2) & (b == 4)

        )operater   )selfotherr   r   G/home/dcms/DCMS/lib/python3.7/site-packages/sqlalchemy/sql/operators.py__and__;   s    zOperators.__and__c             C   s   |  t|S )a)  Implement the ``|`` operator.

        When used with SQL expressions, results in an
        OR operation, equivalent to
        :func:`_expression.or_`, that is::

            a | b

        is equivalent to::

            from sqlalchemy import or_
            or_(a, b)

        Care should be taken when using ``|`` regarding
        operator precedence; the ``|`` operator has the highest precedence.
        The operands should be enclosed in parenthesis if they contain
        further sub expressions::

            (a == 2) | (b == 4)

        )r   r   )r   r   r   r   r   __or__S   s    zOperators.__or__c             C   s
   |  tS )a  Implement the ``~`` operator.

        When used with SQL expressions, results in a
        NOT operation, equivalent to
        :func:`_expression.not_`, that is::

            ~a

        is equivalent to::

            from sqlalchemy import not_
            not_(a)

        )r   r	   )r   r   r   r   
__invert__k   s    zOperators.__invert__r   FNc                s    t ||||  fdd}|S )a!  Produce a generic operator function.

        e.g.::

          somecolumn.op("*")(5)

        produces::

          somecolumn * 5

        This function can also be used to make bitwise operators explicit. For
        example::

          somecolumn.op('&')(0xff)

        is a bitwise AND of the value in ``somecolumn``.

        :param operator: a string which will be output as the infix operator
          between this element and the expression passed to the
          generated function.

        :param precedence: precedence to apply to the operator, when
         parenthesizing expressions.  A lower number will cause the expression
         to be parenthesized when applied against another operator with
         higher precedence.  The default value of ``0`` is lower than all
         operators except for the comma (``,``) and ``AS`` operators.
         A value of 100 will be higher or equal to all operators, and -100
         will be lower than or equal to all operators.

        :param is_comparison: if True, the operator will be considered as a
         "comparison" operator, that is which evaluates to a boolean
         true/false value, like ``==``, ``>``, etc.  This flag should be set
         so that ORM relationships can establish that the operator is a
         comparison operator when used in a custom join condition.

         .. versionadded:: 0.9.2 - added the
            :paramref:`.Operators.op.is_comparison` flag.

        :param return_type: a :class:`.TypeEngine` class or object that will
          force the return type of an expression produced by this operator
          to be of that type.   By default, operators that specify
          :paramref:`.Operators.op.is_comparison` will resolve to
          :class:`.Boolean`, and those that do not will be of the same
          type as the left-hand operand.

          .. versionadded:: 1.2.0b3 - added the
             :paramref:`.Operators.op.return_type` argument.

        .. seealso::

            :ref:`types_operators`

            :ref:`relationship_custom_operator`

        c                s
    | S )Nr   )r   )operatorr   r   r   against   s    zOperators.op.<locals>.against)	custom_op)r   opstring
precedenceis_comparisonreturn_typer"   r   )r!   r   r   op|   s    :zOperators.opc             C   s   | j ||ddS )a+  Return a custom boolean operator.

        This method is shorthand for calling
        :meth:`.Operators.op` and passing the
        :paramref:`.Operators.op.is_comparison`
        flag with True.

        .. versionadded:: 1.2.0b3

        .. seealso::

            :meth:`.Operators.op`

        T)r%   r&   )r(   )r   r$   r%   r   r   r   bool_op   s    zOperators.bool_opc             O   s   t t|dS )a3  Operate on an argument.

        This is the lowest level of operation, raises
        :class:`NotImplementedError` by default.

        Overriding this on a subclass can allow common
        behavior to be applied to all operations.
        For example, overriding :class:`.ColumnOperators`
        to apply ``func.lower()`` to the left and right
        side::

            class MyComparator(ColumnOperators):
                def operate(self, op, other):
                    return op(func.lower(self), func.lower(other))

        :param op:  Operator callable.
        :param \*other: the 'other' side of the operation. Will
         be a single scalar for most operations.
        :param \**kwargs: modifiers.  These may be passed by special
         operators such as :meth:`ColumnOperators.contains`.


        N)NotImplementedErrorstr)r   r(   r   kwargsr   r   r   r      s    zOperators.operatec             K   s   t t|dS )zXReverse operate on an argument.

        Usage is the same as :meth:`operate`.

        N)r*   r+   )r   r(   r   r,   r   r   r   reverse_operate   s    zOperators.reverse_operate)r   FN)r   )__name__
__module____qualname____doc__	__slots__r   r   r    r(   r)   r   r-   r   r   r   r   r   *   s   
@
r   c               @   s6   e Zd ZdZd Z dddZdd Zd	d
 Zdd ZdS )r#   a  Represent a 'custom' operator.

    :class:`.custom_op` is normally instantiated when the
    :meth:`.Operators.op` or :meth:`.Operators.bool_op` methods
    are used to create a custom operator callable.  The class can also be
    used directly when programmatically constructing expressions.   E.g.
    to represent the "factorial" operation::

        from sqlalchemy.sql import UnaryExpression
        from sqlalchemy.sql import operators
        from sqlalchemy import Numeric

        unary = UnaryExpression(table.c.somecolumn,
                modifier=operators.custom_op("!"),
                type_=Numeric)


    .. seealso::

        :meth:`.Operators.op`

        :meth:`.Operators.bool_op`

    r   FNc             C   s6   || _ || _|| _|| _|| _|r,||nd | _d S )N)r$   r%   r&   natural_self_precedenteager_groupingZ_to_instancer'   )r   r$   r%   r&   r'   r3   r4   r   r   r   __init__  s    	zcustom_op.__init__c             C   s   t |to|j| jkS )N)
isinstancer#   r$   )r   r   r   r   r   __eq__  s    zcustom_op.__eq__c             C   s   t | S )N)id)r   r   r   r   __hash__"  s    zcustom_op.__hash__c             K   s   |j | |f|S )N)r   )r   leftrightkwr   r   r   __call__%  s    zcustom_op.__call__)r   FNFF)r.   r/   r0   r1   r5   r7   r9   r=   r   r   r   r   r#      s       
r#   c               @   s  e Zd ZdZdZdZdd Zdd Zej	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d Zdd Zdcd d!Zddd"d#Zd$d% Zd&d' Zded(d)Zdfd*d+Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"d:d; Z#d<d= Z$d>d? Z%d@dA Z&dBdC Z'dDdE Z(dFdG Z)dHdI Z*dJdK Z+dgdMdNZ,dOdP Z-dQdR Z.dSdT Z/dUdV Z0dWdX Z1dYdZ Z2d[d\ Z3d]d^ Z4d_d` Z5dadb Z6dS )hColumnOperatorsa"  Defines boolean, comparison, and other operators for
    :class:`_expression.ColumnElement` expressions.

    By default, all methods call down to
    :meth:`.operate` or :meth:`.reverse_operate`,
    passing in the appropriate operator function from the
    Python builtin ``operator`` module or
    a SQLAlchemy-specific operator function from
    :mod:`sqlalchemy.expression.operators`.   For example
    the ``__eq__`` function::

        def __eq__(self, other):
            return self.operate(operators.eq, other)

    Where ``operators.eq`` is essentially::

        def eq(a, b):
            return a == b

    The core column expression unit :class:`_expression.ColumnElement`
    overrides :meth:`.Operators.operate` and others
    to return further :class:`_expression.ColumnElement` constructs,
    so that the ``==`` operation above is replaced by a clause
    construct.

    .. seealso::

        :ref:`types_operators`

        :attr:`.TypeEngine.comparator_factory`

        :class:`.ColumnOperators`

        :class:`.PropComparator`

    r   Nc             C   s   |  t|S )zdImplement the ``<`` operator.

        In a column context, produces the clause ``a < b``.

        )r   r   )r   r   r   r   r   __lt__T  s    zColumnOperators.__lt__c             C   s   |  t|S )zfImplement the ``<=`` operator.

        In a column context, produces the clause ``a <= b``.

        )r   r
   )r   r   r   r   r   __le__\  s    zColumnOperators.__le__c             C   s   |  t|S )zImplement the ``==`` operator.

        In a column context, produces the clause ``a = b``.
        If the target is ``None``, produces ``a IS NULL``.

        )r   r   )r   r   r   r   r   r7   f  s    zColumnOperators.__eq__c             C   s   |  t|S )zImplement the ``!=`` operator.

        In a column context, produces the clause ``a != b``.
        If the target is ``None``, produces ``a IS NOT NULL``.

        )r   r   )r   r   r   r   r   __ne__o  s    zColumnOperators.__ne__c             C   s   |  t|S )zImplement the ``IS DISTINCT FROM`` operator.

        Renders "a IS DISTINCT FROM b" on most platforms;
        on some such as SQLite may render "a IS NOT b".

        .. versionadded:: 1.1

        )r   is_distinct_from)r   r   r   r   r   rB   x  s    	z ColumnOperators.is_distinct_fromc             C   s   |  t|S )zImplement the ``IS NOT DISTINCT FROM`` operator.

        Renders "a IS NOT DISTINCT FROM b" on most platforms;
        on some such as SQLite may render "a IS b".

        .. versionadded:: 1.1

        )r   isnot_distinct_from)r   r   r   r   r   rC     s    	z#ColumnOperators.isnot_distinct_fromc             C   s   |  t|S )zdImplement the ``>`` operator.

        In a column context, produces the clause ``a > b``.

        )r   r   )r   r   r   r   r   __gt__  s    zColumnOperators.__gt__c             C   s   |  t|S )zfImplement the ``>=`` operator.

        In a column context, produces the clause ``a >= b``.

        )r   r   )r   r   r   r   r   __ge__  s    zColumnOperators.__ge__c             C   s
   |  tS )zaImplement the ``-`` operator.

        In a column context, produces the clause ``-a``.

        )r   r   )r   r   r   r   __neg__  s    zColumnOperators.__neg__c             C   s   |  t|S )N)r   r   )r   r   r   r   r   __contains__  s    zColumnOperators.__contains__c             C   s   |  t|S )zImplement the [] operator.

        This can be used by some database-specific types
        such as PostgreSQL ARRAY and HSTORE.

        )r   r   )r   indexr   r   r   __getitem__  s    zColumnOperators.__getitem__c             C   s   |  t|S )zimplement the << operator.

        Not used by SQLAlchemy core, this is provided
        for custom operator systems which want to use
        << as an extension point.
        )r   r   )r   r   r   r   r   
__lshift__  s    zColumnOperators.__lshift__c             C   s   |  t|S )zimplement the >> operator.

        Not used by SQLAlchemy core, this is provided
        for custom operator systems which want to use
        >> as an extension point.
        )r   r   )r   r   r   r   r   
__rshift__  s    zColumnOperators.__rshift__c             C   s   |  t|S )zImplement the 'concat' operator.

        In a column context, produces the clause ``a || b``,
        or uses the ``concat()`` operator on MySQL.

        )r   	concat_op)r   r   r   r   r   concat  s    zColumnOperators.concatc             C   s   | j t||dS )a  Implement the ``like`` operator.

        In a column context, produces the expression::

            a LIKE other

        E.g.::

            stmt = select([sometable]).\
                where(sometable.c.column.like("%foobar%"))

        :param other: expression to be compared
        :param escape: optional escape character, renders the ``ESCAPE``
          keyword, e.g.::

            somecolumn.like("foo/%bar", escape="/")

        .. seealso::

            :meth:`.ColumnOperators.ilike`

        )escape)r   like_op)r   r   rN   r   r   r   like  s    zColumnOperators.likec             C   s   | j t||dS )a  Implement the ``ilike`` operator, e.g. case insensitive LIKE.

        In a column context, produces an expression either of the form::

            lower(a) LIKE lower(other)

        Or on backends that support the ILIKE operator::

            a ILIKE other

        E.g.::

            stmt = select([sometable]).\
                where(sometable.c.column.ilike("%foobar%"))

        :param other: expression to be compared
        :param escape: optional escape character, renders the ``ESCAPE``
          keyword, e.g.::

            somecolumn.ilike("foo/%bar", escape="/")

        .. seealso::

            :meth:`.ColumnOperators.like`

        )rN   )r   ilike_op)r   r   rN   r   r   r   ilike  s    zColumnOperators.ilikec             C   s   |  t|S )a  Implement the ``in`` operator.

        In a column context, produces the clause ``column IN <other>``.

        The given parameter ``other`` may be:

        * A list of literal values, e.g.::

            stmt.where(column.in_([1, 2, 3]))

          In this calling form, the list of items is converted to a set of
          bound parameters the same length as the list given::

            WHERE COL IN (?, ?, ?)

        * A list of tuples may be provided if the comparison is against a
          :func:`.tuple_` containing multiple expressions::

            from sqlalchemy import tuple_
            stmt.where(tuple_(col1, col2).in_([(1, 10), (2, 20), (3, 30)]))

        * An empty list, e.g.::

            stmt.where(column.in_([]))

          In this calling form, the expression renders a "false" expression,
          e.g.::

            WHERE 1 != 1

          This "false" expression has historically had different behaviors
          in older SQLAlchemy versions, see
          :paramref:`_sa.create_engine.empty_in_strategy`
          for behavioral options.

          .. versionchanged:: 1.2 simplified the behavior of "empty in"
             expressions

        * A bound parameter, e.g. :func:`.bindparam`, may be used if it
          includes the :paramref:`.bindparam.expanding` flag::

            stmt.where(column.in_(bindparam('value', expanding=True)))

          In this calling form, the expression renders a special non-SQL
          placeholder expression that looks like::

            WHERE COL IN ([EXPANDING_value])

          This placeholder expression is intercepted at statement execution
          time to be converted into the variable number of bound parameter
          form illustrated earlier.   If the statement were executed as::

            connection.execute(stmt, {"value": [1, 2, 3]})

          The database would be passed a bound parameter for each value::

            WHERE COL IN (?, ?, ?)

          .. versionadded:: 1.2 added "expanding" bound parameters

          If an empty list is passed, a special "empty list" expression,
          which is specific to the database in use, is rendered.  On
          SQLite this would be::

            WHERE COL IN (SELECT 1 FROM (SELECT 1) WHERE 1!=1)

          .. versionadded:: 1.3 "expanding" bound parameters now support
             empty lists

        * a :func:`_expression.select` construct,
          which is usually a correlated
          scalar select::

            stmt.where(
                column.in_(
                    select([othertable.c.y]).
                    where(table.c.x == othertable.c.x)
                )
            )

          In this calling form, :meth:`.ColumnOperators.in_` renders as given::

            WHERE COL IN (SELECT othertable.y
            FROM othertable WHERE othertable.x = table.x)

        :param other: a list of literals, a :func:`_expression.select`
         construct,
         or a :func:`.bindparam` construct that includes the
         :paramref:`.bindparam.expanding` flag set to True.

        )r   in_op)r   r   r   r   r   in_  s    \zColumnOperators.in_c             C   s   |  t|S )a  implement the ``NOT IN`` operator.

        This is equivalent to using negation with
        :meth:`.ColumnOperators.in_`, i.e. ``~x.in_(y)``.

        In the case that ``other`` is an empty sequence, the compiler
        produces an "empty not in" expression.   This defaults to the
        expression "1 = 1" to produce true in all cases.  The
        :paramref:`_sa.create_engine.empty_in_strategy` may be used to
        alter this behavior.

        .. versionchanged:: 1.2  The :meth:`.ColumnOperators.in_` and
           :meth:`.ColumnOperators.notin_` operators
           now produce a "static" expression for an empty IN sequence
           by default.

        .. seealso::

            :meth:`.ColumnOperators.in_`

        )r   notin_op)r   r   r   r   r   notin_a  s    zColumnOperators.notin_c             C   s   | j t||dS )zimplement the ``NOT LIKE`` operator.

        This is equivalent to using negation with
        :meth:`.ColumnOperators.like`, i.e. ``~x.like(y)``.

        .. seealso::

            :meth:`.ColumnOperators.like`

        )rN   )r   
notlike_op)r   r   rN   r   r   r   notlikey  s    zColumnOperators.notlikec             C   s   | j t||dS )zimplement the ``NOT ILIKE`` operator.

        This is equivalent to using negation with
        :meth:`.ColumnOperators.ilike`, i.e. ``~x.ilike(y)``.

        .. seealso::

            :meth:`.ColumnOperators.ilike`

        )rN   )r   notilike_op)r   r   rN   r   r   r   notilike  s    zColumnOperators.notilikec             C   s   |  t|S )aV  Implement the ``IS`` operator.

        Normally, ``IS`` is generated automatically when comparing to a
        value of ``None``, which resolves to ``NULL``.  However, explicit
        usage of ``IS`` may be desirable if comparing to boolean values
        on certain platforms.

        .. seealso:: :meth:`.ColumnOperators.isnot`

        )r   is_)r   r   r   r   r   r[     s    zColumnOperators.is_c             C   s   |  t|S )a`  Implement the ``IS NOT`` operator.

        Normally, ``IS NOT`` is generated automatically when comparing to a
        value of ``None``, which resolves to ``NULL``.  However, explicit
        usage of ``IS NOT`` may be desirable if comparing to boolean values
        on certain platforms.

        .. seealso:: :meth:`.ColumnOperators.is_`

        )r   isnot)r   r   r   r   r   r\     s    zColumnOperators.isnotc             K   s   | j t|f|S )a  Implement the ``startswith`` operator.

        Produces a LIKE expression that tests against a match for the start
        of a string value::

            column LIKE <other> || '%'

        E.g.::

            stmt = select([sometable]).\
                where(sometable.c.column.startswith("foobar"))

        Since the operator uses ``LIKE``, wildcard characters
        ``"%"`` and ``"_"`` that are present inside the <other> expression
        will behave like wildcards as well.   For literal string
        values, the :paramref:`.ColumnOperators.startswith.autoescape` flag
        may be set to ``True`` to apply escaping to occurrences of these
        characters within the string value so that they match as themselves
        and not as wildcard characters.  Alternatively, the
        :paramref:`.ColumnOperators.startswith.escape` parameter will establish
        a given character as an escape character which can be of use when
        the target expression is not a literal string.

        :param other: expression to be compared.   This is usually a plain
          string value, but can also be an arbitrary SQL expression.  LIKE
          wildcard characters ``%`` and ``_`` are not escaped by default unless
          the :paramref:`.ColumnOperators.startswith.autoescape` flag is
          set to True.

        :param autoescape: boolean; when True, establishes an escape character
          within the LIKE expression, then applies it to all occurrences of
          ``"%"``, ``"_"`` and the escape character itself within the
          comparison value, which is assumed to be a literal string and not a
          SQL expression.

          An expression such as::

            somecolumn.startswith("foo%bar", autoescape=True)

          Will render as::

            somecolumn LIKE :param || '%' ESCAPE '/'

          With the value of ``:param`` as ``"foo/%bar"``.

          .. versionadded:: 1.2

          .. versionchanged:: 1.2.0 The
            :paramref:`.ColumnOperators.startswith.autoescape` parameter is
             now a simple boolean rather than a character; the escape
             character itself is also escaped, and defaults to a forwards
             slash, which itself can be customized using the
             :paramref:`.ColumnOperators.startswith.escape` parameter.

        :param escape: a character which when given will render with the
          ``ESCAPE`` keyword to establish that character as the escape
          character.  This character can then be placed preceding occurrences
          of ``%`` and ``_`` to allow them to act as themselves and not
          wildcard characters.

          An expression such as::

            somecolumn.startswith("foo/%bar", escape="^")

          Will render as::

            somecolumn LIKE :param || '%' ESCAPE '^'

          The parameter may also be combined with
          :paramref:`.ColumnOperators.startswith.autoescape`::

            somecolumn.startswith("foo%bar^bat", escape="^", autoescape=True)

          Where above, the given literal parameter will be converted to
          ``"foo^%bar^^bat"`` before being passed to the database.

        .. seealso::

            :meth:`.ColumnOperators.endswith`

            :meth:`.ColumnOperators.contains`

            :meth:`.ColumnOperators.like`

        )r   startswith_op)r   r   r,   r   r   r   
startswith  s    VzColumnOperators.startswithc             K   s   | j t|f|S )a  Implement the 'endswith' operator.

        Produces a LIKE expression that tests against a match for the end
        of a string value::

            column LIKE '%' || <other>

        E.g.::

            stmt = select([sometable]).\
                where(sometable.c.column.endswith("foobar"))

        Since the operator uses ``LIKE``, wildcard characters
        ``"%"`` and ``"_"`` that are present inside the <other> expression
        will behave like wildcards as well.   For literal string
        values, the :paramref:`.ColumnOperators.endswith.autoescape` flag
        may be set to ``True`` to apply escaping to occurrences of these
        characters within the string value so that they match as themselves
        and not as wildcard characters.  Alternatively, the
        :paramref:`.ColumnOperators.endswith.escape` parameter will establish
        a given character as an escape character which can be of use when
        the target expression is not a literal string.

        :param other: expression to be compared.   This is usually a plain
          string value, but can also be an arbitrary SQL expression.  LIKE
          wildcard characters ``%`` and ``_`` are not escaped by default unless
          the :paramref:`.ColumnOperators.endswith.autoescape` flag is
          set to True.

        :param autoescape: boolean; when True, establishes an escape character
          within the LIKE expression, then applies it to all occurrences of
          ``"%"``, ``"_"`` and the escape character itself within the
          comparison value, which is assumed to be a literal string and not a
          SQL expression.

          An expression such as::

            somecolumn.endswith("foo%bar", autoescape=True)

          Will render as::

            somecolumn LIKE '%' || :param ESCAPE '/'

          With the value of ``:param`` as ``"foo/%bar"``.

          .. versionadded:: 1.2

          .. versionchanged:: 1.2.0 The
            :paramref:`.ColumnOperators.endswith.autoescape` parameter is
             now a simple boolean rather than a character; the escape
             character itself is also escaped, and defaults to a forwards
             slash, which itself can be customized using the
             :paramref:`.ColumnOperators.endswith.escape` parameter.

        :param escape: a character which when given will render with the
          ``ESCAPE`` keyword to establish that character as the escape
          character.  This character can then be placed preceding occurrences
          of ``%`` and ``_`` to allow them to act as themselves and not
          wildcard characters.

          An expression such as::

            somecolumn.endswith("foo/%bar", escape="^")

          Will render as::

            somecolumn LIKE '%' || :param ESCAPE '^'

          The parameter may also be combined with
          :paramref:`.ColumnOperators.endswith.autoescape`::

            somecolumn.endswith("foo%bar^bat", escape="^", autoescape=True)

          Where above, the given literal parameter will be converted to
          ``"foo^%bar^^bat"`` before being passed to the database.

        .. seealso::

            :meth:`.ColumnOperators.startswith`

            :meth:`.ColumnOperators.contains`

            :meth:`.ColumnOperators.like`

        )r   endswith_op)r   r   r,   r   r   r   endswith  s    VzColumnOperators.endswithc             K   s   | j t|f|S )a   Implement the 'contains' operator.

        Produces a LIKE expression that tests against a match for the middle
        of a string value::

            column LIKE '%' || <other> || '%'

        E.g.::

            stmt = select([sometable]).\
                where(sometable.c.column.contains("foobar"))

        Since the operator uses ``LIKE``, wildcard characters
        ``"%"`` and ``"_"`` that are present inside the <other> expression
        will behave like wildcards as well.   For literal string
        values, the :paramref:`.ColumnOperators.contains.autoescape` flag
        may be set to ``True`` to apply escaping to occurrences of these
        characters within the string value so that they match as themselves
        and not as wildcard characters.  Alternatively, the
        :paramref:`.ColumnOperators.contains.escape` parameter will establish
        a given character as an escape character which can be of use when
        the target expression is not a literal string.

        :param other: expression to be compared.   This is usually a plain
          string value, but can also be an arbitrary SQL expression.  LIKE
          wildcard characters ``%`` and ``_`` are not escaped by default unless
          the :paramref:`.ColumnOperators.contains.autoescape` flag is
          set to True.

        :param autoescape: boolean; when True, establishes an escape character
          within the LIKE expression, then applies it to all occurrences of
          ``"%"``, ``"_"`` and the escape character itself within the
          comparison value, which is assumed to be a literal string and not a
          SQL expression.

          An expression such as::

            somecolumn.contains("foo%bar", autoescape=True)

          Will render as::

            somecolumn LIKE '%' || :param || '%' ESCAPE '/'

          With the value of ``:param`` as ``"foo/%bar"``.

          .. versionadded:: 1.2

          .. versionchanged:: 1.2.0 The
            :paramref:`.ColumnOperators.contains.autoescape` parameter is
             now a simple boolean rather than a character; the escape
             character itself is also escaped, and defaults to a forwards
             slash, which itself can be customized using the
             :paramref:`.ColumnOperators.contains.escape` parameter.

        :param escape: a character which when given will render with the
          ``ESCAPE`` keyword to establish that character as the escape
          character.  This character can then be placed preceding occurrences
          of ``%`` and ``_`` to allow them to act as themselves and not
          wildcard characters.

          An expression such as::

            somecolumn.contains("foo/%bar", escape="^")

          Will render as::

            somecolumn LIKE '%' || :param || '%' ESCAPE '^'

          The parameter may also be combined with
          :paramref:`.ColumnOperators.contains.autoescape`::

            somecolumn.contains("foo%bar^bat", escape="^", autoescape=True)

          Where above, the given literal parameter will be converted to
          ``"foo^%bar^^bat"`` before being passed to the database.

        .. seealso::

            :meth:`.ColumnOperators.startswith`

            :meth:`.ColumnOperators.endswith`

            :meth:`.ColumnOperators.like`


        )r   contains_op)r   r   r,   r   r   r   r   ]  s    WzColumnOperators.containsc             K   s   | j t|f|S )aY  Implements a database-specific 'match' operator.

        :meth:`~.ColumnOperators.match` attempts to resolve to
        a MATCH-like function or operator provided by the backend.
        Examples include:

        * PostgreSQL - renders ``x @@ to_tsquery(y)``
        * MySQL - renders ``MATCH (x) AGAINST (y IN BOOLEAN MODE)``
        * Oracle - renders ``CONTAINS(x, y)``
        * other backends may provide special implementations.
        * Backends without any special implementation will emit
          the operator as "MATCH".  This is compatible with SQLite, for
          example.

        )r   match_op)r   r   r,   r   r   r   match  s    zColumnOperators.matchc             C   s
   |  tS )zLProduce a :func:`_expression.desc` clause against the
        parent object.)r   desc_op)r   r   r   r   desc  s    zColumnOperators.descc             C   s
   |  tS )zKProduce a :func:`_expression.asc` clause against the
        parent object.)r   asc_op)r   r   r   r   asc  s    zColumnOperators.ascc             C   s
   |  tS )zRProduce a :func:`_expression.nullsfirst` clause against the
        parent object.)r   nullsfirst_op)r   r   r   r   
nullsfirst  s    zColumnOperators.nullsfirstc             C   s
   |  tS )zQProduce a :func:`_expression.nullslast` clause against the
        parent object.)r   nullslast_op)r   r   r   r   	nullslast  s    zColumnOperators.nullslastc             C   s   |  t|S )zProduce a :func:`_expression.collate` clause against
        the parent object, given the collation string.

        .. seealso::

            :func:`_expression.collate`

        )r   collate)r   Z	collationr   r   r   rl     s    	zColumnOperators.collatec             C   s   |  t|S )zaImplement the ``+`` operator in reverse.

        See :meth:`.ColumnOperators.__add__`.

        )r-   r   )r   r   r   r   r   __radd__  s    zColumnOperators.__radd__c             C   s   |  t|S )zaImplement the ``-`` operator in reverse.

        See :meth:`.ColumnOperators.__sub__`.

        )r-   r   )r   r   r   r   r   __rsub__  s    zColumnOperators.__rsub__c             C   s   |  t|S )zaImplement the ``*`` operator in reverse.

        See :meth:`.ColumnOperators.__mul__`.

        )r-   r   )r   r   r   r   r   __rmul__  s    zColumnOperators.__rmul__c             C   s   |  t|S )zaImplement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        )r-   r   )r   r   r   r   r   __rdiv__  s    zColumnOperators.__rdiv__c             C   s   |  t|S )zaImplement the ``%`` operator in reverse.

        See :meth:`.ColumnOperators.__mod__`.

        )r-   r   )r   r   r   r   r   __rmod__  s    zColumnOperators.__rmod__Fc             C   s   | j t|||dS )zzProduce a :func:`_expression.between` clause against
        the parent object, given the lower and upper range.

        )	symmetric)r   
between_op)r   ZcleftZcrightrr   r   r   r   between  s    zColumnOperators.betweenc             C   s
   |  tS )zZProduce a :func:`_expression.distinct` clause against the
        parent object.

        )r   distinct_op)r   r   r   r   distinct  s    zColumnOperators.distinctc             C   s
   |  tS )a  Produce a :func:`_expression.any_` clause against the
        parent object.

        This operator is only appropriate against a scalar subquery
        object, or for some backends an column expression that is
        against the ARRAY type, e.g.::

            # postgresql '5 = ANY (somearray)'
            expr = 5 == mytable.c.somearray.any_()

            # mysql '5 = ANY (SELECT value FROM table)'
            expr = 5 == select([table.c.value]).as_scalar().any_()

        .. seealso::

            :func:`_expression.any_` - standalone version

            :func:`_expression.all_` - ALL operator

        .. versionadded:: 1.1

        )r   any_op)r   r   r   r   any_  s    zColumnOperators.any_c             C   s
   |  tS )a  Produce a :func:`_expression.all_` clause against the
        parent object.

        This operator is only appropriate against a scalar subquery
        object, or for some backends an column expression that is
        against the ARRAY type, e.g.::

            # postgresql '5 = ALL (somearray)'
            expr = 5 == mytable.c.somearray.all_()

            # mysql '5 = ALL (SELECT value FROM table)'
            expr = 5 == select([table.c.value]).as_scalar().all_()

        .. seealso::

            :func:`_expression.all_` - standalone version

            :func:`_expression.any_` - ANY operator

        .. versionadded:: 1.1

        )r   all_op)r   r   r   r   all_6  s    zColumnOperators.all_c             C   s   |  t|S )a4  Implement the ``+`` operator.

        In a column context, produces the clause ``a + b``
        if the parent object has non-string affinity.
        If the parent object has a string affinity,
        produces the concatenation operator, ``a || b`` -
        see :meth:`.ColumnOperators.concat`.

        )r   r   )r   r   r   r   r   __add__O  s    
zColumnOperators.__add__c             C   s   |  t|S )zdImplement the ``-`` operator.

        In a column context, produces the clause ``a - b``.

        )r   r   )r   r   r   r   r   __sub__[  s    zColumnOperators.__sub__c             C   s   |  t|S )zdImplement the ``*`` operator.

        In a column context, produces the clause ``a * b``.

        )r   r   )r   r   r   r   r   __mul__c  s    zColumnOperators.__mul__c             C   s   |  t|S )zdImplement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        )r   r   )r   r   r   r   r   __div__k  s    zColumnOperators.__div__c             C   s   |  t|S )zdImplement the ``%`` operator.

        In a column context, produces the clause ``a % b``.

        )r   r   )r   r   r   r   r   __mod__s  s    zColumnOperators.__mod__c             C   s   |  t|S )zeImplement the ``//`` operator.

        In a column context, produces the clause ``a / b``.

        )r   r   )r   r   r   r   r   __truediv__{  s    zColumnOperators.__truediv__c             C   s   |  t|S )zfImplement the ``//`` operator in reverse.

        See :meth:`.ColumnOperators.__truediv__`.

        )r-   r   )r   r   r   r   r   __rtruediv__  s    zColumnOperators.__rtruediv__)N)N)N)N)F)7r.   r/   r0   r1   r2   	timetupler?   r@   r   r9   r7   rA   rB   rC   rD   rE   rF   rG   rI   rJ   rK   rM   rP   rR   rT   rV   rX   rZ   r[   r\   r^   r`   r   rc   re   rg   ri   rk   rl   rm   rn   ro   rp   rq   rt   rv   rx   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r>   )  sf   $						

^

XXY
r>   c             C   s   t |  | S )N)_commutativer   )fnr   r   r   commutative_op  s    
r   c             C   s   t |  | S )N)_comparisonr   )r   r   r   r   comparison_op  s    
r   c               C   s
   t  d S )N)r*   r   r   r   r   from_  s    r   c               C   s
   t  d S )N)r*   r   r   r   r   function_as_comparison_op  s    r   c               C   s
   t  d S )N)r*   r   r   r   r   as_  s    r   c               C   s
   t  d S )N)r*   r   r   r   r   exists  s    r   c             C   s
   t  d S )N)r*   )ar   r   r   istrue  s    r   c             C   s
   t  d S )N)r*   )r   r   r   r   isfalse  s    r   c             C   s
   |  |S )N)rB   )r   br   r   r   rB     s    rB   c             C   s
   |  |S )N)rC   )r   r   r   r   r   rC     s    rC   c             C   s
   |  |S )N)r[   )r   r   r   r   r   r[     s    r[   c             C   s
   |  |S )N)r\   )r   r   r   r   r   r\     s    r\   c             C   s
   |  |S )N)rl   )r   r   r   r   r   rl     s    rl   c             C   s   |  ||S )N)r(   )r   r$   r   r   r   r   r(     s    r(   Nc             C   s   | j ||dS )N)rN   )rP   )r   r   rN   r   r   r   rO     s    rO   c             C   s   | j ||dS )N)rN   )rX   )r   r   rN   r   r   r   rW     s    rW   c             C   s   | j ||dS )N)rN   )rR   )r   r   rN   r   r   r   rQ     s    rQ   c             C   s   | j ||dS )N)rN   )rZ   )r   r   rN   r   r   r   rY     s    rY   Fc             C   s   | j |||dS )N)rr   )rt   )r   r   crr   r   r   r   rs     s    rs   c             C   s   | j |||dS )N)rr   )Z
notbetween)r   r   r   rr   r   r   r   notbetween_op  s    r   c             C   s
   |  |S )N)rT   )r   r   r   r   r   rS     s    rS   c             C   s
   |  |S )N)rV   )r   r   r   r   r   rU     s    rU   c             C   s   |   S )N)rv   )r   r   r   r   ru     s    ru   c             C   s   |   S )N)rx   )r   r   r   r   rw     s    rw   c             C   s   |   S )N)rz   )r   r   r   r   ry     s    ry   c             C   sx   |rl|dk	rt d |d kr"d}t|t jjs8td|dkrP|||| }|d|d d|d }| ||dS )	NTz;The autoescape parameter is now a simple boolean True/False/z*String value expected when autoescape=True)%_r   r   )rN   )r   warnr6   compatstring_types	TypeErrorreplace)r   r   rN   
autoescaper   r   r   _escaped_like_impl  s    r   c             C   s   t | j|||S )N)r   r^   )r   r   rN   r   r   r   r   r]     s    r]   c             C   s   t | j||| S )N)r   r^   )r   r   rN   r   r   r   r   notstartswith_op  s    r   c             C   s   t | j|||S )N)r   r`   )r   r   rN   r   r   r   r   r_   !  s    r_   c             C   s   t | j||| S )N)r   r`   )r   r   rN   r   r   r   r   notendswith_op&  s    r   c             C   s   t | j|||S )N)r   r   )r   r   rN   r   r   r   r   ra   +  s    ra   c             C   s   t | j||| S )N)r   r   )r   r   rN   r   r   r   r   notcontains_op0  s    r   c             K   s   | j |f|S )N)rc   )r   r   r<   r   r   r   rb   5  s    rb   c             K   s   | j |f|S )N)Znotmatch)r   r   r<   r   r   r   notmatch_op:  s    r   c             C   s
   t  d S )N)r*   )r   r   r   r   r   comma_op?  s    r   c             C   s
   t  d S )N)r*   )r   r   r   r   r   empty_in_opC  s    r   c             C   s
   t  d S )N)r*   )r   r   r   r   r   empty_notin_opH  s    r   c             C   s
   t  d S )N)r*   )r   r   r   r   r   	filter_opM  s    r   c             C   s
   |  |S )N)rM   )r   r   r   r   r   rL   Q  s    rL   c             C   s   |   S )N)re   )r   r   r   r   rd   U  s    rd   c             C   s   |   S )N)rg   )r   r   r   r   rf   Y  s    rf   c             C   s   |   S )N)ri   )r   r   r   r   rh   ]  s    rh   c             C   s   |   S )N)rk   )r   r   r   r   rj   a  s    rj   c             C   s
   t  d S )N)r*   )r   r   r   r   r   json_getitem_ope  s    r   c             C   s
   t  d S )N)r*   )r   r   r   r   r   json_path_getitem_opi  s    r   c             C   s   | t kpt| to| jS )N)r   r6   r#   r&   )r(   r   r   r   r&   m  s    r&   c             C   s   | t kS )N)r   )r(   r   r   r   is_commutativeq  s    r   c             C   s   | t tttfkS )N)rf   rd   rh   rj   )r(   r   r   r   is_ordering_modifieru  s    r   c             C   s   | t kpt| to| jS )N)_natural_self_precedentr6   r#   r3   )r(   r   r   r   is_natural_self_precedenty  s    
r   c             C   s   t | p| tkS )N)r&   	_booleans)r(   r   r   r   
is_boolean  s    r   c             C   s   t | | S )z[rotate a comparison operator 180 degrees.

    Note this is not the same as negation.

    )_mirrorget)r(   r   r   r   mirror  s    r   _asbooli)	canonical	_smallesti_largestd                        c             C   s@   | |krt | rdS t| t| dtt|t|dtkS d S )NFr%   )r   _PRECEDENCEr   getattrr   r   )r!   r"   r   r   r   is_precedent  s
    r   )N)N)N)N)F)F)NF)NF)NF)NF)NF)NF)^r1   r!   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r    r   Zpy2kr   objectr   r#   r>   r   r   r   r   r   r   r   r   r   r   rB   rC   r[   r\   rl   r(   rO   rW   rQ   rY   rs   r   rS   rU   ru   rw   ry   r   r]   r   r_   r   ra   r   rb   r   r   r   r   r   rL   rd   rf   rh   rj   r   r   r&   r   r   r   r   r   r   r   union
differenceZ_associativer   symbolr   r   r   r   r   r   r   r   r   <module>   s@   H8      i	