From 952a78ad72d4e363cdf7347b3a606afe8b7890f0 Mon Sep 17 00:00:00 2001 From: rahul4732saini Date: Sun, 3 Nov 2024 20:12:06 +0530 Subject: [PATCH] Update conditions.py Defined `_eval_condition_segments` method in the `ConditionHandler` class for evaluating condition segments seperated by the specified logical operator. --- fise/query/conditions.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fise/query/conditions.py b/fise/query/conditions.py index 67d677a..ce6f841 100644 --- a/fise/query/conditions.py +++ b/fise/query/conditions.py @@ -352,6 +352,41 @@ def _eval_condition( else: return response + def _eval_condition_segments( + self, + conditions: list[bool | str | list | Condition], + operator: str, + entity: BaseEntity, + ) -> list[bool | str | list | Condition]: + """ + Evaluates condition segments seperated by the specified operator. + + #### Params: + - conditions (list): List of query conditions. + - operator (str): Logical operator which has to be evaluated. + - entity (BaseEntity): Entity to be operated upon. + """ + + cur: str = "" + res: list[bool | str | list | Condition] = [] + + for token in conditions: + if isinstance(token, str) and token in constants.CONDITION_SEPARATORS: + res.append(cur := token) + + elif cur == operator: + result = self._logical_method_map[res.pop()]( + res.pop(), self._eval_condition(token, entity) + ) + + res.append(result) + cur = "" + + else: + res.append(self._eval_condition(token, entity)) + + return res + def _eval_conditions( self, conditions: list[str | Condition | list],