U ÃÏ a(Áãl@sdZddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z dd lm Z dd lm Z ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZejr 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%e%Z&d,d-„Z'e'Z(e d.d/„ƒZ)e d0d1„ƒZ*e*Z+e d2d3„ƒZ,e d4d5„ƒZ-e-Z.d6d7„Z/d8d9„Z0e d›d;d<„ƒZ1e dœd=d>„ƒZ2e2Z3e dd?d@„ƒZ4e dždAdB„ƒZ5e5Z6e dŸdDdE„ƒZ7e d dFdG„ƒZ8e8Z9e dHdI„ƒZ:e dJdK„ƒZ;e;ZdPdQ„Z?dRdS„Z@e d¡dTdU„ƒZAe d¢dVdW„ƒZBeBZCe d£dXdY„ƒZDe d¤dZd[„ƒZEeEZFe d¥d\d]„ƒZGe d¦d^d_„ƒZHeHZIe d`da„ƒZJe d§dbdc„ƒZKe d¨ddde„ƒZLd©dfdg„ZMe dhdi„ƒZNeNZOdjdk„ZPdldm„ZQdndo„ZRdpdq„ZSdrds„ZTdtdu„ZUeUZVdvdw„ZWeWZXdxdy„ZYdzd{„ZZd|d}„Z[d~d„Z\d€d„Z]d‚dƒ„Z^e e%e'eefZ_d„d…„Z`ee ee e ee eiZad†d‡„Zbe ceReeg¡ deeg¡Zedˆd‰„Zfee ceeYeZg¡ZgejhdŠd‹dŒZiejhddŽdŒZjejhdddŒZke!d‘e"d‘e>d‘e?d‘ed‘eYd‘eZd‘ed’ed’ed’e d’ed’ed“ed“eRd”eQd”eJd•eNd•eKd•eLd•eMd•e4d•e5d•e1d•e2d•e:d•e;d•e,d•e-d•ed•ed•e)d•e*d•ed•e d•ed•e d•e7d•e8d•e=d•e d•e%d•e'd•ed–edePd—eSd–eTd–e/d˜e#d—e$deid‹ejejekeki6Zld™dš„Zmd: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úYC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\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) )rrrrrrÚ__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. .. 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&rr$rÚop|s7z Operators.opcCs|j||ddS)aReturn a custom boolean operator. This method is shorthand for calling :meth:`.Operators.op` and passing the :paramref:`.Operators.op.is_comparison` flag with True. .. seealso:: :meth:`.Operators.op` T)r)r*©r,)rr(r)rrrÚbool_opºs zOperators.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`. Nr/r2rrrÚreverse_operateãszOperators.reverse_operate)rFN)r) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__rr r"r,r.rr4rrrrr*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|_dSr#)r(r)r*Únatural_self_precedentÚeager_groupingZ _to_instancer+)rr(r)r*r+r:r;rrrÚ__init__s ÿzcustom_op.__init__cCst|tƒo|j|jkSr#)Ú isinstancer'r(rrrrÚ__eq__szcustom_op.__eq__cCst|ƒSr#)Úidr!rrrÚ__hash__szcustom_op.__hash__cKs|j||f|ŽSr#)r)rÚleftÚrightÚkwrrrÚ__call__ szcustom_op.__call__)rFNFF)r5r6r7r8r<r>r@rDrrrrr'ìsù r'c@sÐeZdZdZdZdZdd„Zdd„Zej Z dd „Z d d „Z d d „Z dd„Z e Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdgd d!„Zdhd"d#„Zd$d%„Zd&d'„ZeZdid(d)„ZeZdjd*d+„ZeZd,d-„Z d.d/„Z!e!Z"d0d1„Z#d2d3„Z$d4d5„Z%d6d7„Z&dkd8d9„Z'dld:d;„Z(dd?„Z*d@dA„Z+e+Z,dBdC„Z-e-Z.dDdE„Z/dFdG„Z0dHdI„Z1dJdK„Z2dLdM„Z3dNdO„Z4dmdQdR„Z5dSdT„Z6dUdV„Z7dWdX„Z8dYdZ„Z9d[d\„Z:d]d^„Z;d_d`„Zdedf„Z?dS)nÚ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` rNcCs | t|¡S)zdImplement the ``<`` operator. In a column context, produces the clause ``a < b``. )rr rrrrÚ__lt__OszColumnOperators.__lt__cCs | t|¡S)zfImplement the ``<=`` operator. In a column context, produces the clause ``a <= b``. )rr rrrrÚ__le__WszColumnOperators.__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``. )rrrrrrr>aszColumnOperators.__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``. )rrrrrrÚ__ne__jszColumnOperators.__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_fromrrrrrIss z ColumnOperators.is_distinct_fromcCs | t|¡S)a¬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". .. versionchanged:: 1.4 The ``is_not_distinct_from()`` operator is renamed from ``isnot_distinct_from()`` in previous releases. The previous name remains available for backwards compatibility. .. versionadded:: 1.1 )rÚis_not_distinct_fromrrrrrJ~s z$ColumnOperators.is_not_distinct_fromcCs | t|¡S)zdImplement the ``>`` operator. In a column context, produces the clause ``a > b``. )rrrrrrÚ__gt__szColumnOperators.__gt__cCs | t|¡S)zfImplement the ``>=`` operator. In a column context, produces the clause ``a >= b``. )rrrrrrÚ__ge__˜szColumnOperators.__ge__cCs | t¡S)zaImplement the ``-`` operator. In a column context, produces the clause ``-a``. )rrr!rrrÚ__neg__ szColumnOperators.__neg__cCs | t|¡Sr#)rrrrrrÚ __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 rrrrÚ __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. )rrrrrrÚ __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_oprrrrÚconcatÆszColumnOperators.concatcCs|jt||dS)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©rrrVrrrÚlikeÏszColumnOperators.likecCs|jt||dS)aImplement 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_oprXrrrÚ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 (?, ?, ?) * 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 an "empty set" expression. These expressions are tailored to individual backends and are generally trying to get an empty SELECT statement as a subquery. Such as on SQLite, the expression is:: WHERE col IN (SELECT 1 FROM (SELECT 1) WHERE 1!=1) .. versionchanged:: 1.4 empty IN expressions now use an execution-time generated SELECT subquery in all cases. * 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_oprrrrÚin_sWzColumnOperators.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:`_sa.create_engine.empty_in_strategy` may be used to alter this behavior. .. versionchanged:: 1.4 The ``not_in()`` operator is renamed from ``notin_()`` in previous releases. The previous name remains available for backwards compatibility. .. versionchanged:: 1.2 The :meth:`.ColumnOperators.in_` and :meth:`.ColumnOperators.not_in` operators now produce a "static" expression for an empty IN sequence by default. .. seealso:: :meth:`.ColumnOperators.in_` )rÚ not_in_oprrrrÚnot_in^szColumnOperators.not_incCs|jt||dS)a§implement the ``NOT LIKE`` operator. This is equivalent to using negation with :meth:`.ColumnOperators.like`, i.e. ``~x.like(y)``. .. versionchanged:: 1.4 The ``not_like()`` operator is renamed from ``notlike()`` in previous releases. The previous name remains available for backwards compatibility. .. seealso:: :meth:`.ColumnOperators.like` rU)rÚ notlike_oprXrrrÚnot_like}szColumnOperators.not_likecCs|jt||dS)a­implement the ``NOT ILIKE`` operator. This is equivalent to using negation with :meth:`.ColumnOperators.ilike`, i.e. ``~x.ilike(y)``. .. versionchanged:: 1.4 The ``not_ilike()`` operator is renamed from ``notilike()`` in previous releases. The previous name remains available for backwards compatibility. .. seealso:: :meth:`.ColumnOperators.ilike` rU)rÚ notilike_oprXrrrÚ not_ilike‘szColumnOperators.not_ilikecCs | t|¡S)aWImplement 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.is_not` )rÚis_rrrrrd¥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. .. versionchanged:: 1.4 The ``is_not()`` operator is renamed from ``isnot()`` in previous releases. The previous name remains available for backwards compatibility. .. seealso:: :meth:`.ColumnOperators.is_` )rÚis_notrrrrre²szColumnOperators.is_notcKs|jt|f|ŽS)aS 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"``. :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©rrr3rrrÚ startswithÆsMzColumnOperators.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"``. :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_oprgrrrÚendswithsMzColumnOperators.endswithcKs|jt|f|ŽS)aX 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"``. :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_oprgrrrrdsNzColumnOperators.containscKs|jt|f|ŽS)aáImplements a database-specific 'match' operator. :meth:`_sql.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)`` .. seealso:: :class:`_mysql.match` - MySQL specific construct with additional features. * 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_oprgrrrÚmatch´szColumnOperators.matchcCs|jt||dS)aImplements a database-specific 'regexp match' operator. E.g.:: stmt = select(table.c.some_column).where( table.c.some_column.regexp_match('^(b|c)') ) :meth:`_sql.ColumnOperators.regexp_match` attempts to resolve to a REGEXP-like function or operator provided by the backend, however the specific regular expression syntax and flags available are **not backend agnostic**. Examples include: * PostgreSQL - renders ``x ~ y`` or ``x !~ y`` when negated. * Oracle - renders ``REGEXP_LIKE(x, y)`` * SQLite - uses SQLite's ``REGEXP`` placeholder operator and calls into the Python ``re.match()`` builtin. * other backends may provide special implementations. * Backends without any special implementation will emit the operator as "REGEXP" or "NOT REGEXP". This is compatible with SQLite and MySQL, for example. Regular expression support is currently implemented for Oracle, PostgreSQL, MySQL and MariaDB. Partial support is available for SQLite. Support among third-party dialects may vary. :param pattern: The regular expression pattern string or column clause. :param flags: Any regular expression string flags to apply. Flags tend to be backend specific. It can be a string or a column clause. Some backends, like PostgreSQL and MariaDB, may alternatively specify the flags as part of the pattern. When using the ignore case flag 'i' in PostgreSQL, the ignore case regexp match operator ``~*`` or ``!~*`` will be used. .. versionadded:: 1.4 .. seealso:: :meth:`_sql.ColumnOperators.regexp_replace` ©Úflags)rÚregexp_match_op)rÚpatternrorrrÚ regexp_matchÌs.zColumnOperators.regexp_matchcCs|jt|||dS)a0Implements a database-specific 'regexp replace' operator. E.g.:: stmt = select( table.c.some_column.regexp_replace( 'b(..)', 'XY', flags='g' ) ) :meth:`_sql.ColumnOperators.regexp_replace` attempts to resolve to a REGEXP_REPLACE-like function provided by the backend, that usually emit the function ``REGEXP_REPLACE()``. However, the specific regular expression syntax and flags available are **not backend agnostic**. Regular expression replacement support is currently implemented for Oracle, PostgreSQL, MySQL 8 or greater and MariaDB. Support among third-party dialects may vary. :param pattern: The regular expression pattern string or column clause. :param pattern: The replacement string or column clause. :param flags: Any regular expression string flags to apply. Flags tend to be backend specific. It can be a string or a column clause. Some backends, like PostgreSQL and MariaDB, may alternatively specify the flags as part of the pattern. .. versionadded:: 1.4 .. seealso:: :meth:`_sql.ColumnOperators.regexp_match` ©Ú replacementro)rÚregexp_replace_op)rrqrtrorrrÚregexp_replaceüs &ÿzColumnOperators.regexp_replacecCs | t¡S)zLProduce a :func:`_expression.desc` clause against the parent object.)rÚdesc_opr!rrrÚdesc&szColumnOperators.desccCs | t¡S)zKProduce a :func:`_expression.asc` clause against the parent object.)rÚasc_opr!rrrÚasc+szColumnOperators.asccCs | t¡S)a*Produce a :func:`_expression.nulls_first` clause against the parent object. .. versionchanged:: 1.4 The ``nulls_first()`` operator is renamed from ``nullsfirst()`` in previous releases. The previous name remains available for backwards compatibility. )rÚnulls_first_opr!rrrÚ nulls_first0szColumnOperators.nulls_firstcCs | t¡S)a'Produce a :func:`_expression.nulls_last` clause against the parent object. .. versionchanged:: 1.4 The ``nulls_last()`` operator is renamed from ``nullslast()`` in previous releases. The previous name remains available for backwards compatibility. )rÚ nulls_last_opr!rrrÚ nulls_last=szColumnOperators.nulls_lastcCs | t|¡S)z´Produce a :func:`_expression.collate` clause against the parent object, given the collation string. .. seealso:: :func:`_expression.collate` )rÚcollate)rZ collationrrrrJs zColumnOperators.collatecCs | t|¡S)zaImplement the ``+`` operator in reverse. See :meth:`.ColumnOperators.__add__`. )r4rrrrrÚ__radd__UszColumnOperators.__radd__cCs | t|¡S)zaImplement the ``-`` operator in reverse. See :meth:`.ColumnOperators.__sub__`. )r4rrrrrÚ__rsub__]szColumnOperators.__rsub__cCs | t|¡S)zaImplement the ``*`` operator in reverse. See :meth:`.ColumnOperators.__mul__`. )r4rrrrrÚ__rmul__eszColumnOperators.__rmul__cCs | t|¡S)zaImplement the ``/`` operator in reverse. See :meth:`.ColumnOperators.__div__`. )r4rrrrrÚ__rdiv__mszColumnOperators.__rdiv__cCs | t|¡S)zaImplement the ``%`` operator in reverse. See :meth:`.ColumnOperators.__mod__`. )r4r rrrrÚ__rmod__uszColumnOperators.__rmod__FcCs|jt|||dS)zzProduce a :func:`_expression.between` clause against the parent object, given the lower and upper range. ©Ú symmetric)rÚ between_op)rZcleftZcrightr†rrrÚbetween}szColumnOperators.betweencCs | t¡S)zZProduce a :func:`_expression.distinct` clause against the parent object. )rÚ distinct_opr!rrrÚ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).scalar_subquery().any_() .. seealso:: :func:`_expression.any_` - standalone version :func:`_expression.all_` - ALL operator .. versionadded:: 1.1 )rÚany_opr!rrrÚ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).scalar_subquery().all_() .. seealso:: :func:`_expression.all_` - standalone version :func:`_expression.any_` - ANY operator .. versionadded:: 1.1 )rÚall_opr!rrrÚ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`. )rrrrrrÚ__add__½s zColumnOperators.__add__cCs | t|¡S)zdImplement the ``-`` operator. In a column context, produces the clause ``a - b``. )rrrrrrÚ__sub__ÉszColumnOperators.__sub__cCs | t|¡S)zdImplement the ``*`` operator. In a column context, produces the clause ``a * b``. )rrrrrrÚ__mul__ÑszColumnOperators.__mul__cCs | t|¡S)zdImplement the ``/`` operator. In a column context, produces the clause ``a / b``. )rrrrrrÚ__div__ÙszColumnOperators.__div__cCs | t|¡S)zdImplement the ``%`` operator. In a column context, produces the clause ``a % b``. )rr rrrrÚ__mod__ászColumnOperators.__mod__cCs | t|¡S)zeImplement the ``//`` operator. In a column context, produces the clause ``a / b``. )rrrrrrÚ __truediv__észColumnOperators.__truediv__cCs | t|¡S)zfImplement the ``//`` operator in reverse. See :meth:`.ColumnOperators.__truediv__`. )r4rrrrrÚ __rtruediv__ñszColumnOperators.__rtruediv__)N)N)N)N)N)N)F)@r5r6r7r8r9Ú timetuplerFrGrr@r>rHrIrJÚisnot_distinct_fromrKrLrMrNrPrQrRrTrYr[r]r_Znotin_raÚnotlikercZnotilikerdreÚisnotrhrjrrmrrrvrxrzr|Z nullsfirstr~Z nullslastrr€rr‚rƒr„rˆrŠrŒrŽrrr‘r’r“r”r•rrrrrE$sx%        Y   OOP 0 *     rEcCst |¡|Sr#)Ú _commutativer©ÚfnrrrÚcommutative_opþs rcCst |¡|Sr#)Ú _comparisonrr›rrrÚ comparison_ops rŸcCs tƒ‚dSr#©r0rrrrÚfrom_sr¡cCs tƒ‚dSr#r rrrrÚfunction_as_comparison_op sr¢cCs tƒ‚dSr#r rrrrÚas_sr£cCs tƒ‚dSr#r rrrrÚexistssr¤cCs tƒ‚dSr#r ©ÚarrrÚis_truesr§cCs tƒ‚dSr#r r¥rrrÚis_false!sr¨cCs | |¡Sr#)rI©r¦ÚbrrrrI)srIcCs | |¡Sr#)rJr©rrrrJ.srJcCs | |¡Sr#)rdr©rrrrd7srdcCs | |¡Sr#)rer©rrrre<srecCs | |¡Sr#)rr©rrrrEsrcCs| |¡|ƒSr#r-)r¦r(rªrrrr,Isr,NcCs|j||dS©NrU)rY©r¦rªrVrrrrWMsrWcCs|j||dSr«)r˜r¬rrrÚ not_like_opRsr­cCs|j||dSr«)r[r¬rrrrZ[srZcCs|j||dSr«)rcr¬rrrÚ not_ilike_op`sr®FcCs|j|||dS©Nr…©rˆ©r¦rªÚcr†rrrr‡isr‡cCs|j|||dSr¯r°r±rrrÚnot_between_opnsr³cCs | |¡Sr#)r]r©rrrr\wsr\cCs | |¡Sr#)r_r©rrrr^|sr^cCs| ¡Sr#)rŠr¥rrrr‰…sr‰cCs| ¡Sr#)rŒr¥rrrr‹‰sr‹cCs| ¡Sr#)rŽr¥rrrrsrcCsx|rl|dk rt d¡|dkr"d}t|tjjƒs8tdƒ‚|dkrP| |||¡}| d|d¡ d|d¡}|||dS) 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œrrVÚ autoescaperrrÚ_escaped_like_impl‘sÿr½cCst|j|||ƒSr#©r½rh©r¦rªrVr¼rrrrf¥srfcCst|j|||ƒSr#r¾r¿rrrÚnot_startswith_opªsrÀcCst|j|||ƒSr#©r½rjr¿rrrri³sricCst|j|||ƒSr#rÁr¿rrrÚnot_endswith_op¸srÂcCst|j|||ƒSr#©r½rr¿rrrrkÁsrkcCst|j|||ƒSr#rÃr¿rrrÚnot_contains_opÆsrÄcKs|j|f|ŽSr#©rm©r¦rªrCrrrrlÏsrlcCs|j||dS©Nrn©rr©r¦rªrorrrrpÔsrpcCs|j||dSrÇrÈrÉrrrÚnot_regexp_match_opÙsrÊcCs|j|||dS)Nrs)rv)r¦rªrtrorrrruÞsrucKs|j|f|ŽSr#rÅrÆrrrÚ not_match_opâsrËcCs tƒ‚dSr#r r©rrrÚcomma_opësrÌcCs tƒ‚dSr#r r©rrrÚ filter_opïsrÍcCs | |¡Sr#)rTr©rrrrSósrScCs| ¡Sr#)rxr¥rrrrw÷srwcCs| ¡Sr#)rzr¥rrrryûsrycCs| ¡Sr#)r|r¥rrrr{ÿsr{cCs| ¡Sr#)r~r¥rrrr}sr}cCs tƒ‚dSr#r r©rrrÚjson_getitem_opsrÎcCs tƒ‚dSr#r r©rrrÚjson_path_getitem_opsrÏcCs|tkpt|tƒo|jSr#)ržr=r'r*r-rrrr*sr*cCs|tkSr#)ršr-rrrÚis_commutativesrÐcCs|ttttfkSr#)ryrwr{r}r-rrrÚis_ordering_modifiersrÑcCs|tkpt|tƒo|jSr#)Ú_natural_self_precedentr=r'r:r-rrrÚis_natural_self_precedent#s ýrÓcCst|ƒp|tkSr#)r*Ú _booleansr-rrrÚ is_boolean.srÕcCs t ||¡S)z[rotate a comparison operator 180 degrees. Note this is not the same as negation. )Ú_mirrorÚgetr-rrrÚmirror5srØcCs|tkSr#)Ú _associativer-rrrÚis_associativeAsrÚÚ_asbooliöÿÿÿ)Ú 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)N)N)N)nr8r%rrrrrrrr r r r r rrrrrrrÚrZpy2krÚobjectrr'rEršržrrŸr¡r¢r£r¤r§Zistruer¨ZisfalserIrJr—rdrer™rr,rWr­r`rZr®rbr‡r³Z notbetween_opr\r^Znotin_opr‰r‹rr½rfrÀZnotstartswith_oprirÂZnotendswith_oprkrÄZnotcontains_oprlrprÊrurËZ notmatch_oprÌrÍrSrwryr{Z nullsfirst_opr}Z nullslast_oprÎrÏr*rÐrÑrÓrÔrÕrÖrØÚunionÚ differencerÙrÚrÒÚsymbolrÛrÝrÞrèrêrrrrÚ sê                    C8]                          ÿ Ê: