B ĆĢ4]ķ¤ćj@sĄdZddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z dd lm Z dd lm Z ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZejr ddlmZneZGdd„deƒZGdd„deƒZGdd„deƒZeeeehZeee eee hZdd„Zd 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 d—d;d<„ƒZ-e d˜d=d>„ƒZ.e d™d?d@„ƒZ/e dšdAdB„ƒZ0e d›dDdE„ƒZ1e dœdFdG„ƒZ2e dHdI„ƒZ3e dJdK„ƒZ4dLdM„Z5dNdO„Z6dPdQ„Z7dRdS„Z8e ddTdU„ƒZ9e dždVdW„ƒZ:e dŸdXdY„ƒZ;e d dZd[„ƒZe d`da„ƒZ?e dbdc„ƒZ@ddde„ZAe dfdg„ƒZBe dhdi„ƒZCdjdk„ZDdldm„ZEdndo„ZFdpdq„ZGdrds„ZHdtdu„ZIdvdw„ZJdxdy„ZKdzd{„ZLd|d}„ZMd~d„ZNd€d„ZOe e%e&eefZPd‚dƒ„ZQee ee e ee eiZRd„d…„ZSe TeEeeg” Ueeg”ZVeV TeeJeKg”ZWejXd†d‡dˆZYejXd‰dŠdˆZZejXd‹dŒdˆZ[e!de"de6de7dedeJdeKdedŽedŽedŽe dŽedŽededeEdeDde?d‘e@d‘e/d‘e0d‘e-d‘e.d‘e3d‘e4d‘e)d‘e*d‘ed‘ed‘e'd‘e(d‘eBd‘eCd‘ed‘e d‘ed‘e d‘e1d‘e2d‘e5d‘e d‘e%d‘e&d‘ed’edeAd“eFd’eGd’e+d”e#d“e$deYd‡eZeZe[e[i5Z\d•d–„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@sPeZdZdZdZdd„Zdd„Zdd„Zdd d „Zddd„Z dd„Z dd„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`. ©cCs | 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ŚotherrrśK/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/operators.pyŚ__and__;szOperators.__and__cCs | 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) )rr)rrrrrŚ__or__SszOperators.__or__cCs | t”S)aImplement 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) )rr )rrrrŚ __invert__kszOperators.__invert__rFNcs t||||ƒ‰‡‡fdd„}|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` cs ˆˆ|ƒS)Nr)r)ŚoperatorrrrŚagainstøszOperators.op..against)Ś custom_op)rŚopstringŚ precedenceŚ is_comparisonŚ return_typer"r)r!rrŚop|s:z Operators.opcCs|j||dd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()rr$r%rrrŚbool_op½szOperators.bool_opcOstt|ƒƒ‚dS)a3Operate 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)rr(rŚkwargsrrrrĪszOperators.operatecKstt|ƒƒ‚dS)zXReverse operate on an argument. Usage is the same as :meth:`operate`. N)r*r+)rr(rr,rrrŚreverse_operatečszOperators.reverse_operate)rFN)r) Ś__name__Ś __module__Ś __qualname__Ś__doc__Ś __slots__rrr r(r)rr-rrrrr*s  @ rc@s6eZdZdZdZd dd„Zdd„Zd d „Zd d „ZdS)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` rFNcCs6||_||_||_||_||_|r,| |”nd|_dS)N)r$r%r&Śnatural_self_precedentŚeager_groupingZ _to_instancer')rr$r%r&r'r3r4rrrŚ__init__ s zcustom_op.__init__cCst|tƒo|j|jkS)N)Ś isinstancer#r$)rrrrrŚ__eq__szcustom_op.__eq__cCst|ƒS)N)Śid)rrrrŚ__hash__"szcustom_op.__hash__cKs|j||f|ŽS)N)r)rŚleftŚrightŚkwrrrŚ__call__%szcustom_op.__call__)rFNFF)r.r/r0r1r5r7r9r=rrrrr#ńs r#c@s eZdZdZdZdZdd„Zdd„Zej Z dd „Z d d „Z d d „Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdcd d!„Zddd"d#„Zd$d%„Zd&d'„Zded(d)„Zdfd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Z d6d7„Z!d8d9„Z"d:d;„Z#dd?„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„Z6dS)hŚColumnOperatorsaDefines 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` rNcCs | t|”S)zdImplement the ``<`` operator. In a column context, produces the clause ``a < b``. )rr )rrrrrŚ__lt__TszColumnOperators.__lt__cCs | t|”S)zfImplement the ``<=`` operator. In a column context, produces the clause ``a <= b``. )rr )rrrrrŚ__le__\szColumnOperators.__le__cCs | t|”S)z Implement the ``==`` operator. In a column context, produces the clause ``a = b``. If the target is ``None``, produces ``a IS NULL``. )rr)rrrrrr7fszColumnOperators.__eq__cCs | t|”S)z„Implement the ``!=`` operator. In a column context, produces the clause ``a != b``. If the target is ``None``, produces ``a IS NOT NULL``. )rr)rrrrrŚ__ne__oszColumnOperators.__ne__cCs | t|”S)zČImplement 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)rrrrrrBxs z ColumnOperators.is_distinct_fromcCs | t|”S)zĢImplement 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)rrrrrrCƒs z#ColumnOperators.isnot_distinct_fromcCs | t|”S)zdImplement the ``>`` operator. In a column context, produces the clause ``a > b``. )rr)rrrrrŚ__gt__ŽszColumnOperators.__gt__cCs | t|”S)zfImplement the ``>=`` operator. In a column context, produces the clause ``a >= b``. )rr)rrrrrŚ__ge__–szColumnOperators.__ge__cCs | t”S)zaImplement the ``-`` operator. In a column context, produces the clause ``-a``. )rr)rrrrŚ__neg__žszColumnOperators.__neg__cCs | t|”S)N)rr)rrrrrŚ __contains__¦szColumnOperators.__contains__cCs | t|”S)z‹Implement the [] operator. This can be used by some database-specific types such as PostgreSQL ARRAY and HSTORE. )rr)rŚindexrrrŚ __getitem__©szColumnOperators.__getitem__cCs | t|”S)z²implement the << operator. Not used by SQLAlchemy core, this is provided for custom operator systems which want to use << as an extension point. )rr )rrrrrŚ __lshift__²szColumnOperators.__lshift__cCs | t|”S)z²implement the >> operator. Not used by SQLAlchemy core, this is provided for custom operator systems which want to use >> as an extension point. )rr)rrrrrŚ __rshift__»szColumnOperators.__rshift__cCs | t|”S)zœImplement the 'concat' operator. In a column context, produces the clause ``a || b``, or uses the ``concat()`` operator on MySQL. )rŚ concat_op)rrrrrŚconcatÄszColumnOperators.concatcCs|jt||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)rrrNrrrŚlikeĶszColumnOperators.likecCs|jt||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)rrrNrrrŚilikeęszColumnOperators.ilikecCs | t|”S)aÉ Implement the ``in`` operator. In a column context, produces the clause ``column IN ``. 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 (?, ?, ?) * 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_op)rrrrrŚin_sSzColumnOperators.in_cCs | 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_op)rrrrrŚnotin_XszColumnOperators.notin_cCs|jt||dS)zŽimplement 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)rrrNrrrŚnotlikeps zColumnOperators.notlikecCs|jt||dS)zāimplement 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)rrrNrrrŚnotilike}s zColumnOperators.notilikecCs | t|”S)aVImplement 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_)rrrrrr[Šs zColumnOperators.is_cCs | 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)rrrrrr\—s zColumnOperators.isnotcKs|jt|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 || '%' E.g.:: stmt = select([sometable]).\ where(sometable.c.column.startswith("foobar")) Since the operator uses ``LIKE``, wildcard characters ``"%"`` and ``"_"`` that are present inside the 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)rrr,rrrŚ startswith¤sVzColumnOperators.startswithcKs|jt|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 '%' || E.g.:: stmt = select([sometable]).\ where(sometable.c.column.endswith("foobar")) Since the operator uses ``LIKE``, wildcard characters ``"%"`` and ``"_"`` that are present inside the 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)rrr,rrrŚendswithüsVzColumnOperators.endswithcKs|jt|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 '%' || || '%' E.g.:: stmt = select([sometable]).\ where(sometable.c.column.contains("foobar")) Since the operator uses ``LIKE``, wildcard characters ``"%"`` and ``"_"`` that are present inside the 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)rrr,rrrrTsWzColumnOperators.containscKs|jt|f|ŽS)aYImplements 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)rrr,rrrŚmatch­szColumnOperators.matchcCs | t”S)zMProduce a :func:`~.expression.desc` clause against the parent object.)rŚdesc_op)rrrrŚdescæszColumnOperators.desccCs | t”S)zLProduce a :func:`~.expression.asc` clause against the parent object.)rŚasc_op)rrrrŚascÄszColumnOperators.asccCs | t”S)zSProduce a :func:`~.expression.nullsfirst` clause against the parent object.)rŚ nullsfirst_op)rrrrŚ nullsfirstÉszColumnOperators.nullsfirstcCs | t”S)zRProduce a :func:`~.expression.nullslast` clause against the parent object.)rŚ nullslast_op)rrrrŚ nullslastĪszColumnOperators.nullslastcCs | t|”S)z¶Produce a :func:`~.expression.collate` clause against the parent object, given the collation string. .. seealso:: :func:`~.expression.collate` )rŚcollate)rZ collationrrrrlÓs zColumnOperators.collatecCs | t|”S)zaImplement the ``+`` operator in reverse. See :meth:`.ColumnOperators.__add__`. )r-r)rrrrrŚ__radd__ŽszColumnOperators.__radd__cCs | t|”S)zaImplement the ``-`` operator in reverse. See :meth:`.ColumnOperators.__sub__`. )r-r)rrrrrŚ__rsub__ęszColumnOperators.__rsub__cCs | t|”S)zaImplement the ``*`` operator in reverse. See :meth:`.ColumnOperators.__mul__`. )r-r)rrrrrŚ__rmul__īszColumnOperators.__rmul__cCs | t|”S)zaImplement the ``/`` operator in reverse. See :meth:`.ColumnOperators.__div__`. )r-r)rrrrrŚ__rdiv__öszColumnOperators.__rdiv__cCs | t|”S)zaImplement the ``%`` operator in reverse. See :meth:`.ColumnOperators.__mod__`. )r-r )rrrrrŚ__rmod__žszColumnOperators.__rmod__FcCs|jt|||dS)z{Produce a :func:`~.expression.between` clause against the parent object, given the lower and upper range. )Ś symmetric)rŚ between_op)rZcleftZcrightrrrrrŚbetweenszColumnOperators.betweencCs | t”S)z[Produce a :func:`~.expression.distinct` clause against the parent object. )rŚ distinct_op)rrrrŚdistinct szColumnOperators.distinctcCs | 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)rrrrŚany_szColumnOperators.any_cCs | 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)rrrrŚall_-szColumnOperators.all_cCs | t|”S)a4Implement 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`. )rr)rrrrrŚ__add__Fs zColumnOperators.__add__cCs | t|”S)zdImplement the ``-`` operator. In a column context, produces the clause ``a - b``. )rr)rrrrrŚ__sub__RszColumnOperators.__sub__cCs | t|”S)zdImplement the ``*`` operator. In a column context, produces the clause ``a * b``. )rr)rrrrrŚ__mul__ZszColumnOperators.__mul__cCs | t|”S)zdImplement the ``/`` operator. In a column context, produces the clause ``a / b``. )rr)rrrrrŚ__div__bszColumnOperators.__div__cCs | t|”S)zdImplement the ``%`` operator. In a column context, produces the clause ``a % b``. )rr )rrrrrŚ__mod__jszColumnOperators.__mod__cCs | t|”S)zeImplement the ``//`` operator. In a column context, produces the clause ``a / b``. )rr)rrrrrŚ __truediv__rszColumnOperators.__truediv__cCs | t|”S)zfImplement the ``//`` operator in reverse. See :meth:`.ColumnOperators.__truediv__`. )r-r)rrrrrŚ __rtruediv__zszColumnOperators.__rtruediv__)N)N)N)N)F)7r.r/r0r1r2Z timetupler?r@rr9r7rArBrCrDrErFrGrIrJrKrMrPrRrTrVrXrZr[r\r^r`rrcrergrirkrlrmrnrorprqrtrvrxrzr{r|r}r~rr€rrrrrr>)sf$         U   XXY   r>cCst |”|S)N)Ś _commutativer)ŚfnrrrŚcommutative_op‡s r„cCst |”|S)N)Ś _comparisonr)rƒrrrŚ comparison_opŒs r†cCs tƒ‚dS)N)r*rrrrŚfrom_‘sr‡cCs tƒ‚dS)N)r*rrrrŚfunction_as_comparison_op•srˆcCs tƒ‚dS)N)r*rrrrŚas_šsr‰cCs tƒ‚dS)N)r*rrrrŚexistsžsrŠcCs tƒ‚dS)N)r*)ŚarrrŚistrue¢srŒcCs tƒ‚dS)N)r*)r‹rrrŚisfalse¦srcCs | |”S)N)rB)r‹ŚbrrrrBŖsrBcCs | |”S)N)rC)r‹rŽrrrrCÆsrCcCs | |”S)N)r[)r‹rŽrrrr[“sr[cCs | |”S)N)r\)r‹rŽrrrr\¹sr\cCs | |”S)N)rl)r‹rŽrrrrl¾srlcCs| |”|ƒS)N)r()r‹r$rŽrrrr(Āsr(NcCs|j||dS)N)rN)rP)r‹rŽrNrrrrOĘsrOcCs|j||dS)N)rN)rX)r‹rŽrNrrrrWĖsrWcCs|j||dS)N)rN)rR)r‹rŽrNrrrrQŠsrQcCs|j||dS)N)rN)rZ)r‹rŽrNrrrrYÕsrYFcCs|j|||dS)N)rr)rt)r‹rŽŚcrrrrrrsŚsrscCs|j|||dS)N)rr)Z notbetween)r‹rŽrrrrrrŚ notbetween_opßsrcCs | |”S)N)rT)r‹rŽrrrrSäsrScCs | |”S)N)rV)r‹rŽrrrrUésrUcCs| ”S)N)rv)r‹rrrruīsrucCs| ”S)N)rx)r‹rrrrwņsrwcCs| ”S)N)rz)r‹rrrryösrycCsx|rl|dk rt d”|dkr"d}t|tjjƒs8tdƒ‚|dkrP| |||”}| 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ŚcompatZ string_typesŚ TypeErrorŚreplace)rƒrrNŚ autoescaperrrŚ_escaped_like_implśsr™cCst|j|||ƒS)N)r™r^)r‹rŽrNr˜rrrr]sr]cCst|j|||ƒS)N)r™r^)r‹rŽrNr˜rrrŚnotstartswith_opsršcCst|j|||ƒS)N)r™r`)r‹rŽrNr˜rrrr_sr_cCst|j|||ƒS)N)r™r`)r‹rŽrNr˜rrrŚnotendswith_opsr›cCst|j|||ƒS)N)r™r)r‹rŽrNr˜rrrra"sracCst|j|||ƒS)N)r™r)r‹rŽrNr˜rrrŚnotcontains_op'srœcKs|j|f|ŽS)N)rc)r‹rŽr<rrrrb,srbcKs|j|f|ŽS)N)Znotmatch)r‹rŽr<rrrŚ notmatch_op1srcCs tƒ‚dS)N)r*)r‹rŽrrrŚcomma_op6sržcCs tƒ‚dS)N)r*)r‹rŽrrrŚ empty_in_op:srŸcCs tƒ‚dS)N)r*)r‹rŽrrrŚempty_notin_op?sr cCs tƒ‚dS)N)r*)r‹rŽrrrŚ filter_opDsr”cCs | |”S)N)rM)r‹rŽrrrrLHsrLcCs| ”S)N)re)r‹rrrrdLsrdcCs| ”S)N)rg)r‹rrrrfPsrfcCs| ”S)N)ri)r‹rrrrhTsrhcCs| ”S)N)rk)r‹rrrrjXsrjcCs tƒ‚dS)N)r*)r‹rŽrrrŚjson_getitem_op\sr¢cCs tƒ‚dS)N)r*)r‹rŽrrrŚjson_path_getitem_op`sr£cCs|tkpt|tƒo|jS)N)r…r6r#r&)r(rrrr&dsr&cCs|tkS)N)r‚)r(rrrŚis_commutativehsr¤cCs|ttttfkS)N)rfrdrhrj)r(rrrŚis_ordering_modifierlsr„cCs|tkpt|tƒo|jS)N)Ś_natural_self_precedentr6r#r3)r(rrrŚis_natural_self_precedentps r§cCst|ƒp|tkS)N)r&Ś _booleans)r(rrrŚ is_boolean{sr©cCs t ||”S)z[rotate a comparison operator 180 degrees. Note this is not the same as negation. )Ś_mirrorŚget)r(rrrŚmirror‚sr¬Ś_asbooliö’’’)Z canonicalŚ _smallestiœ’’’Ś_largestédééééééé’’’’écCs@||krt|ƒrdSt |t|dtƒ”t |t|dtƒ”kSdS)NFr%)r§Ś _PRECEDENCEr«Śgetattrr®rÆ)r!r"rrrŚ is_precedentÓs r»)N)N)N)N)F)F)NF)NF)NF)NF)NF)NF)^r1r!rrrrrrrr r r r r rrrrrrrŚrZpy2krŚobjectrr#r>r‚r…r„r†r‡rˆr‰rŠrŒrrBrCr[r\rlr(rOrWrQrYrsrrSrUrurwryr™r]ršr_r›rarœrbrržrŸr r”rLrdrfrhrjr¢r£r&r¤r„r§rØr©rŖr¬ŚunionŚ differenceZ _associativer¦Zsymbolr­r®rÆr¹r»rrrrŚ s@                    H8`