U
    x^                  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   @/tmp/pip-install-dq5v43_d/SQLAlchemy/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   __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   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`.

        Nr/   r2   r   r   r   reverse_operate   s    zOperators.reverse_operate)r   FN)r   )__name__
__module____qualname____doc__	__slots__r   r    r"   r,   r.   r   r4   r   r   r   r   r   *   s        
A
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 r#   )r(   r)   r*   natural_self_precedenteager_groupingZ_to_instancer+   )r   r(   r)   r*   r+   r:   r;   r   r   r   __init__  s    	zcustom_op.__init__c                 C   s   t |to|j| jkS r#   )
isinstancer'   r(   r   r   r   r   __eq__  s    zcustom_op.__eq__c                 C   s   t | S r#   )idr!   r   r   r   __hash__"  s    zcustom_op.__hash__c                 K   s   |j | |f|S r#   )r   )r   leftrightkwr   r   r   __call__%  s    zcustom_op.__call__)r   FNFF)r5   r6   r7   r8   r<   r>   r@   rD   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:`.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:`.ColumnElement`
    overrides :meth:`.Operators.operate` and others
    to return further :class:`.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   __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   __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>   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   __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_fromr   r   r   r   rI   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_fromr   r   r   r   rJ     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   __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   __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 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   
__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   
__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_opr   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   rV   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`

        rU   )r   ilike_oprX   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:`.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:`.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:`.select` construct,
         or a :func:`.bindparam` construct that includes the
         :paramref:`.bindparam.expanding` flag set to True.

        )r   in_opr   r   r   r   in_  s    Yz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:`.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_opr   r   r   r   notin_^  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`

        rU   )r   
notlike_oprX   r   r   r   notlikev  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`

        rU   )r   notilike_oprX   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   rd     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   isnotr   r   r   r   re     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   r3   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_oprg   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_oprg   r   r   r   r   Z  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_oprg   r   r   r   match  s    zColumnOperators.matchc                 C   s
   |  tS )zMProduce a :func:`~.expression.desc` clause against the
        parent object.)r   desc_opr!   r   r   r   desc  s    zColumnOperators.descc                 C   s
   |  tS )zLProduce a :func:`~.expression.asc` clause against the
        parent object.)r   asc_opr!   r   r   r   asc  s    zColumnOperators.ascc                 C   s
   |  tS )zSProduce a :func:`~.expression.nullsfirst` clause against the
        parent object.)r   nullsfirst_opr!   r   r   r   
nullsfirst  s    zColumnOperators.nullsfirstc                 C   s
   |  tS )zRProduce a :func:`~.expression.nullslast` clause against the
        parent object.)r   nullslast_opr!   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   rv     s    	zColumnOperators.collatec                 C   s   |  t|S )zaImplement the ``+`` operator in reverse.

        See :meth:`.ColumnOperators.__add__`.

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

        See :meth:`.ColumnOperators.__sub__`.

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

        See :meth:`.ColumnOperators.__mul__`.

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

        See :meth:`.ColumnOperators.__div__`.

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

        See :meth:`.ColumnOperators.__mod__`.

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

        	symmetric)r   
between_op)r   ZcleftZcrightr}   r   r   r   between  s    zColumnOperators.betweenc                 C   s
   |  tS )z[Produce a :func:`~.expression.distinct` clause against the
        parent object.

        )r   distinct_opr!   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_opr!   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_opr!   r   r   r   all_3  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   __add__L  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   __sub__X  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   __mul__`  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   __div__h  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   __mod__p  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   __truediv__x  s    zColumnOperators.__truediv__c                 C   s   |  t|S )zfImplement the ``//`` operator in reverse.

        See :meth:`.ColumnOperators.__truediv__`.

        )r4   r   r   r   r   r   __rtruediv__  s    zColumnOperators.__rtruediv__)N)N)N)N)F)7r5   r6   r7   r8   r9   	timetuplerF   rG   r   r@   r>   rH   rI   rJ   rK   rL   rM   rN   rP   rQ   rR   rT   rY   r[   r]   r_   ra   rc   rd   re   rh   rj   r   rm   ro   rq   rs   ru   rv   rw   rx   ry   rz   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   )  sf   %						

[

XXY
rE   c                 C   s   t |  | S r#   )_commutativer   fnr   r   r   commutative_op  s    
r   c                 C   s   t |  | S r#   )_comparisonr   r   r   r   r   comparison_op  s    
r   c                   C   s
   t  d S r#   r0   r   r   r   r   from_  s    r   c                   C   s
   t  d S r#   r   r   r   r   r   function_as_comparison_op  s    r   c                   C   s
   t  d S r#   r   r   r   r   r   as_  s    r   c                   C   s
   t  d S r#   r   r   r   r   r   exists  s    r   c                 C   s
   t  d S r#   r   ar   r   r   istrue  s    r   c                 C   s
   t  d S r#   r   r   r   r   r   isfalse  s    r   c                 C   s
   |  |S r#   )rI   r   br   r   r   rI     s    rI   c                 C   s
   |  |S r#   )rJ   r   r   r   r   rJ     s    rJ   c                 C   s
   |  |S r#   )rd   r   r   r   r   rd     s    rd   c                 C   s
   |  |S r#   )re   r   r   r   r   re     s    re   c                 C   s
   |  |S r#   )rv   r   r   r   r   rv     s    rv   c                 C   s   |  ||S r#   r-   )r   r(   r   r   r   r   r,     s    r,   Nc                 C   s   | j ||dS NrU   )rY   r   r   rV   r   r   r   rW     s    rW   c                 C   s   | j ||dS r   )ra   r   r   r   r   r`     s    r`   c                 C   s   | j ||dS r   )r[   r   r   r   r   rZ     s    rZ   c                 C   s   | j ||dS r   )rc   r   r   r   r   rb     s    rb   Fc                 C   s   | j |||dS Nr|   )r   r   r   cr}   r   r   r   r~     s    r~   c                 C   s   | j |||dS r   )Z
notbetweenr   r   r   r   notbetween_op  s    r   c                 C   s
   |  |S r#   )r]   r   r   r   r   r\     s    r\   c                 C   s
   |  |S r#   )r_   r   r   r   r   r^     s    r^   c                 C   s   |   S r#   )r   r   r   r   r   r     s    r   c                 C   s   |   S r#   )r   r   r   r   r   r     s    r   c                 C   s   |   S r#   )r   r   r   r   r   r     s    r   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   rU   )r   warnr=   compatstring_types	TypeErrorreplace)r   r   rV   
autoescaper   r   r   _escaped_like_impl   s    r   c                 C   s   t | j|||S r#   r   rh   r   r   rV   r   r   r   r   rf     s    rf   c                 C   s   t | j||| S r#   r   r   r   r   r   notstartswith_op  s    r   c                 C   s   t | j|||S r#   r   rj   r   r   r   r   ri     s    ri   c                 C   s   t | j||| S r#   r   r   r   r   r   notendswith_op#  s    r   c                 C   s   t | j|||S r#   r   r   r   r   r   r   rk   (  s    rk   c                 C   s   t | j||| S r#   r   r   r   r   r   notcontains_op-  s    r   c                 K   s   | j |f|S r#   )rm   r   r   rC   r   r   r   rl   2  s    rl   c                 K   s   | j |f|S r#   )Znotmatchr   r   r   r   notmatch_op7  s    r   c                 C   s
   t  d S r#   r   r   r   r   r   comma_op<  s    r   c                 C   s
   t  d S r#   r   r   r   r   r   empty_in_op@  s    r   c                 C   s
   t  d S r#   r   r   r   r   r   empty_notin_opE  s    r   c                 C   s
   t  d S r#   r   r   r   r   r   	filter_opJ  s    r   c                 C   s
   |  |S r#   )rT   r   r   r   r   rS   N  s    rS   c                 C   s   |   S r#   )ro   r   r   r   r   rn   R  s    rn   c                 C   s   |   S r#   )rq   r   r   r   r   rp   V  s    rp   c                 C   s   |   S r#   )rs   r   r   r   r   rr   Z  s    rr   c                 C   s   |   S r#   )ru   r   r   r   r   rt   ^  s    rt   c                 C   s
   t  d S r#   r   r   r   r   r   json_getitem_opb  s    r   c                 C   s
   t  d S r#   r   r   r   r   r   json_path_getitem_opf  s    r   c                 C   s   | t kpt| to| jS r#   )r   r=   r'   r*   r-   r   r   r   r*   j  s    r*   c                 C   s   | t kS r#   )r   r-   r   r   r   is_commutativen  s    r   c                 C   s   | t tttfkS r#   )rp   rn   rr   rt   r-   r   r   r   is_ordering_modifierr  s    r   c                 C   s   | t kpt| to| jS r#   )_natural_self_precedentr=   r'   r:   r-   r   r   r   is_natural_self_precedentv  s    
r   c                 C   s   t | p| tkS r#   )r*   	_booleansr-   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getr-   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)^r8   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'   rE   r   r   r   r   r   r   r   r   r   r   rI   rJ   rd   re   rv   r,   rW   r`   rZ   rb   r~   r   r\   r^   r   r   r   r   rf   r   ri   r   rk   r   rl   r   r   r   r   r   rS   rn   rp   rr   rt   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      f










		                                                     9