$47 GRAYBYTE WORDPRESS FILE MANAGER $15

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

/lib64/python2.7/site-packages/sqlalchemy/orm/

HOME
Current File : /lib64/python2.7/site-packages/sqlalchemy/orm//evaluator.py
# orm/evaluator.py
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php

import operator

from .. import inspect
from .. import util
from ..sql import and_
from ..sql import operators
from ..sql.sqltypes import Integer
from ..sql.sqltypes import Numeric


class UnevaluatableError(Exception):
    pass


class _NoObject(operators.ColumnOperators):
    def operate(self, *arg, **kw):
        return None

    def reverse_operate(self, *arg, **kw):
        return None


_NO_OBJECT = _NoObject()

_straight_ops = set(
    getattr(operators, op)
    for op in (
        "lt",
        "le",
        "ne",
        "gt",
        "ge",
        "eq",
    )
)

_math_only_straight_ops = set(
    getattr(operators, op)
    for op in (
        "add",
        "mul",
        "sub",
        "div",
        "mod",
        "truediv",
    )
)

_extended_ops = {
    operators.in_op: (lambda a, b: a in b if a is not _NO_OBJECT else None),
    operators.not_in_op: (
        lambda a, b: a not in b if a is not _NO_OBJECT else None
    ),
}

_notimplemented_ops = set(
    getattr(operators, op)
    for op in (
        "like_op",
        "not_like_op",
        "ilike_op",
        "not_ilike_op",
        "startswith_op",
        "between_op",
        "endswith_op",
    )
)


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

    def process(self, *clauses):
        if len(clauses) > 1:
            clause = and_(*clauses)
        elif clauses:
            clause = clauses[0]

        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)
            if obj is not None
            else _NO_OBJECT
        )

    def visit_tuple(self, clause):
        return self.visit_clauselist(clause)

    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 or value is _NO_OBJECT:
                            return None
                        return False
                return True

        elif clause.operator is operators.comma_op:

            def evaluate(obj):
                values = []
                for sub_evaluate in evaluators:
                    value = sub_evaluate(obj)
                    if value is None or value is _NO_OBJECT:
                        return None
                    values.append(value)
                return tuple(values)

        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.is_not:

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

        elif operator is operators.concat_op:

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

        elif operator in _extended_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 _extended_ops[operator](left_val, right_val)

        elif operator in _math_only_straight_ops:
            if (
                clause.left.type._type_affinity
                not in (
                    Numeric,
                    Integer,
                )
                or clause.right.type._type_affinity not in (Numeric, Integer)
            ):
                raise UnevaluatableError(
                    'Cannot evaluate math operator "%s" for '
                    "datatypes %s, %s"
                    % (operator.__name__, clause.left.type, clause.right.type)
                )

            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))

        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
..
--
23 Sep 2024 10.41 AM
root / root
0755
__init__.py
10.707 KB
5 Sep 2024 10.50 PM
root / root
0644
__init__.pyc
12.471 KB
23 Sep 2024 10.41 AM
root / root
0644
attributes.py
75.885 KB
5 Sep 2024 10.50 PM
root / root
0644
attributes.pyc
68.515 KB
23 Sep 2024 10.41 AM
root / root
0644
base.py
14.881 KB
5 Sep 2024 10.50 PM
root / root
0644
base.pyc
14.961 KB
23 Sep 2024 10.41 AM
root / root
0644
clsregistry.py
12.987 KB
5 Sep 2024 10.50 PM
root / root
0644
clsregistry.pyc
14.702 KB
23 Sep 2024 10.41 AM
root / root
0644
collections.py
53.44 KB
5 Sep 2024 10.50 PM
root / root
0644
collections.pyc
61.913 KB
23 Sep 2024 10.41 AM
root / root
0644
context.py
108.652 KB
5 Sep 2024 10.50 PM
root / root
0644
context.pyc
61.606 KB
23 Sep 2024 10.41 AM
root / root
0644
decl_api.py
34.724 KB
5 Sep 2024 10.50 PM
root / root
0644
decl_api.pyc
37.08 KB
23 Sep 2024 10.41 AM
root / root
0644
decl_base.py
43.69 KB
5 Sep 2024 10.50 PM
root / root
0644
decl_base.pyc
30.072 KB
23 Sep 2024 10.41 AM
root / root
0644
dependency.py
45.886 KB
5 Sep 2024 10.50 PM
root / root
0644
dependency.pyc
28.217 KB
23 Sep 2024 10.41 AM
root / root
0644
descriptor_props.py
25.378 KB
5 Sep 2024 10.50 PM
root / root
0644
descriptor_props.pyc
27.322 KB
23 Sep 2024 10.41 AM
root / root
0644
dynamic.py
15.638 KB
5 Sep 2024 10.50 PM
root / root
0644
dynamic.pyc
16.155 KB
23 Sep 2024 10.41 AM
root / root
0644
evaluator.py
7.756 KB
5 Sep 2024 10.50 PM
root / root
0644
evaluator.pyc
10.283 KB
23 Sep 2024 10.41 AM
root / root
0644
events.py
109.648 KB
5 Sep 2024 10.50 PM
root / root
0644
events.pyc
116.313 KB
23 Sep 2024 10.41 AM
root / root
0644
exc.py
6.379 KB
5 Sep 2024 10.50 PM
root / root
0644
exc.pyc
8.012 KB
23 Sep 2024 10.41 AM
root / root
0644
identity.py
7.063 KB
5 Sep 2024 10.50 PM
root / root
0644
identity.pyc
9.846 KB
23 Sep 2024 10.41 AM
root / root
0644
instrumentation.py
19.914 KB
5 Sep 2024 10.50 PM
root / root
0644
instrumentation.pyc
21.94 KB
23 Sep 2024 10.41 AM
root / root
0644
interfaces.py
31.586 KB
5 Sep 2024 10.50 PM
root / root
0644
interfaces.pyc
36.536 KB
23 Sep 2024 10.41 AM
root / root
0644
loading.py
48.161 KB
5 Sep 2024 10.50 PM
root / root
0644
loading.pyc
28.739 KB
23 Sep 2024 10.41 AM
root / root
0644
mapper.py
140.959 KB
5 Sep 2024 10.50 PM
root / root
0644
mapper.pyc
106.941 KB
23 Sep 2024 10.41 AM
root / root
0644
path_registry.py
16.008 KB
5 Sep 2024 10.50 PM
root / root
0644
path_registry.pyc
17.739 KB
23 Sep 2024 10.41 AM
root / root
0644
persistence.py
82.275 KB
5 Sep 2024 10.50 PM
root / root
0644
persistence.pyc
48.377 KB
23 Sep 2024 10.41 AM
root / root
0644
properties.py
14.438 KB
5 Sep 2024 10.50 PM
root / root
0644
properties.pyc
14.746 KB
23 Sep 2024 10.41 AM
root / root
0644
query.py
122.999 KB
5 Sep 2024 10.50 PM
root / root
0644
query.pyc
119.512 KB
23 Sep 2024 10.41 AM
root / root
0644
relationships.py
140.622 KB
5 Sep 2024 10.50 PM
root / root
0644
relationships.pyc
114.873 KB
23 Sep 2024 10.41 AM
root / root
0644
scoping.py
7.087 KB
5 Sep 2024 10.50 PM
root / root
0644
scoping.pyc
7.317 KB
23 Sep 2024 10.41 AM
root / root
0644
session.py
158.795 KB
5 Sep 2024 10.50 PM
root / root
0644
session.pyc
142.412 KB
23 Sep 2024 10.41 AM
root / root
0644
state.py
32.738 KB
5 Sep 2024 10.50 PM
root / root
0644
state.pyc
32.091 KB
23 Sep 2024 10.41 AM
root / root
0644
strategies.py
105.8 KB
5 Sep 2024 10.50 PM
root / root
0644
strategies.pyc
65.906 KB
23 Sep 2024 10.41 AM
root / root
0644
strategy_options.py
66.687 KB
5 Sep 2024 10.50 PM
root / root
0644
strategy_options.pyc
58.673 KB
23 Sep 2024 10.41 AM
root / root
0644
sync.py
5.688 KB
5 Sep 2024 10.50 PM
root / root
0644
sync.pyc
4.58 KB
23 Sep 2024 10.41 AM
root / root
0644
unitofwork.py
26.455 KB
5 Sep 2024 10.50 PM
root / root
0644
unitofwork.pyc
24.882 KB
23 Sep 2024 10.41 AM
root / root
0644
util.py
74.473 KB
5 Sep 2024 10.50 PM
root / root
0644
util.pyc
69.456 KB
23 Sep 2024 10.41 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF