$32 GRAYBYTE WORDPRESS FILE MANAGER $86

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm//evaluator.py
# orm/evaluator.py
# Copyright (C) 2005-2021 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php

import operator

from .. import inspect
from .. import util
from ..sql import operators


class UnevaluatableError(Exception):
    pass


_straight_ops = set(
    getattr(operators, op)
    for op in (
        "add",
        "mul",
        "sub",
        "div",
        "mod",
        "truediv",
        "lt",
        "le",
        "ne",
        "gt",
        "ge",
        "eq",
    )
)


_notimplemented_ops = set(
    getattr(operators, op)
    for op in (
        "like_op",
        "notlike_op",
        "ilike_op",
        "notilike_op",
        "between_op",
        "in_op",
        "notin_op",
        "endswith_op",
        "concat_op",
    )
)


class EvaluatorCompiler(object):
    def __init__(self, target_cls=None):
        self.target_cls = target_cls

    def process(self, clause):
        meth = getattr(self, "visit_%s" % clause.__visit_name__, None)
        if not meth:
            raise UnevaluatableError(
                "Cannot evaluate %s" % type(clause).__name__
            )
        return meth(clause)

    def visit_grouping(self, clause):
        return self.process(clause.element)

    def visit_null(self, clause):
        return lambda obj: None

    def visit_false(self, clause):
        return lambda obj: False

    def visit_true(self, clause):
        return lambda obj: True

    def visit_column(self, clause):
        if "parentmapper" in clause._annotations:
            parentmapper = clause._annotations["parentmapper"]
            if self.target_cls and not issubclass(
                self.target_cls, parentmapper.class_
            ):
                raise UnevaluatableError(
                    "Can't evaluate criteria against alternate class %s"
                    % parentmapper.class_
                )
            key = parentmapper._columntoproperty[clause].key
        else:
            key = clause.key
            if (
                self.target_cls
                and key in inspect(self.target_cls).column_attrs
            ):
                util.warn(
                    "Evaluating non-mapped column expression '%s' onto "
                    "ORM instances; this is a deprecated use case.  Please "
                    "make use of the actual mapped columns in ORM-evaluated "
                    "UPDATE / DELETE expressions." % clause
                )
            else:
                raise UnevaluatableError("Cannot evaluate column: %s" % clause)

        get_corresponding_attr = operator.attrgetter(key)
        return lambda obj: get_corresponding_attr(obj)

    def visit_clauselist(self, clause):
        evaluators = list(map(self.process, clause.clauses))
        if clause.operator is operators.or_:

            def evaluate(obj):
                has_null = False
                for sub_evaluate in evaluators:
                    value = sub_evaluate(obj)
                    if value:
                        return True
                    has_null = has_null or value is None
                if has_null:
                    return None
                return False

        elif clause.operator is operators.and_:

            def evaluate(obj):
                for sub_evaluate in evaluators:
                    value = sub_evaluate(obj)
                    if not value:
                        if value is None:
                            return None
                        return False
                return True

        else:
            raise UnevaluatableError(
                "Cannot evaluate clauselist with operator %s" % clause.operator
            )

        return evaluate

    def visit_binary(self, clause):
        eval_left, eval_right = list(
            map(self.process, [clause.left, clause.right])
        )
        operator = clause.operator
        if operator is operators.is_:

            def evaluate(obj):
                return eval_left(obj) == eval_right(obj)

        elif operator is operators.isnot:

            def evaluate(obj):
                return eval_left(obj) != eval_right(obj)

        elif operator in _straight_ops:

            def evaluate(obj):
                left_val = eval_left(obj)
                right_val = eval_right(obj)
                if left_val is None or right_val is None:
                    return None
                return operator(eval_left(obj), eval_right(obj))

        else:
            raise UnevaluatableError(
                "Cannot evaluate %s with operator %s"
                % (type(clause).__name__, clause.operator)
            )
        return evaluate

    def visit_unary(self, clause):
        eval_inner = self.process(clause.element)
        if clause.operator is operators.inv:

            def evaluate(obj):
                value = eval_inner(obj)
                if value is None:
                    return None
                return not value

            return evaluate
        raise UnevaluatableError(
            "Cannot evaluate %s with operator %s"
            % (type(clause).__name__, clause.operator)
        )

    def visit_bindparam(self, clause):
        if clause.callable:
            val = clause.callable()
        else:
            val = clause.value
        return lambda obj: val

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
14 Aug 2025 9.24 PM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
9.705 KB
17 Apr 2025 8.10 PM
root / root
0644
attributes.py
66.487 KB
17 Apr 2025 8.10 PM
root / root
0644
base.py
14.945 KB
17 Apr 2025 8.10 PM
root / root
0644
collections.py
51.625 KB
17 Apr 2025 8.10 PM
root / root
0644
dependency.py
45.465 KB
17 Apr 2025 8.10 PM
root / root
0644
deprecated_interfaces.py
20.272 KB
17 Apr 2025 8.10 PM
root / root
0644
descriptor_props.py
28.582 KB
17 Apr 2025 8.10 PM
root / root
0644
dynamic.py
14.323 KB
17 Apr 2025 8.10 PM
root / root
0644
evaluator.py
5.313 KB
17 Apr 2025 8.10 PM
root / root
0644
events.py
102.186 KB
17 Apr 2025 8.10 PM
root / root
0644
exc.py
6.461 KB
17 Apr 2025 8.10 PM
root / root
0644
identity.py
10.191 KB
17 Apr 2025 8.10 PM
root / root
0644
instrumentation.py
18.167 KB
17 Apr 2025 8.10 PM
root / root
0644
interfaces.py
25.245 KB
17 Apr 2025 8.10 PM
root / root
0644
loading.py
33.046 KB
17 Apr 2025 8.10 PM
root / root
0644
mapper.py
127.873 KB
17 Apr 2025 8.10 PM
root / root
0644
path_registry.py
13.441 KB
17 Apr 2025 8.10 PM
root / root
0644
persistence.py
64.487 KB
17 Apr 2025 8.10 PM
root / root
0644
properties.py
12.397 KB
17 Apr 2025 8.10 PM
root / root
0644
query.py
177.204 KB
17 Apr 2025 8.10 PM
root / root
0644
relationships.py
134.532 KB
17 Apr 2025 8.10 PM
root / root
0644
scoping.py
6.264 KB
17 Apr 2025 8.10 PM
root / root
0644
session.py
128.683 KB
17 Apr 2025 8.10 PM
root / root
0644
state.py
30.089 KB
17 Apr 2025 8.10 PM
root / root
0644
strategies.py
85.273 KB
17 Apr 2025 8.10 PM
root / root
0644
strategy_options.py
56.468 KB
17 Apr 2025 8.10 PM
root / root
0644
sync.py
5.687 KB
17 Apr 2025 8.10 PM
root / root
0644
unitofwork.py
24.163 KB
17 Apr 2025 8.10 PM
root / root
0644
util.py
44.381 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF