Skip to content

Commit

Permalink
Update conditions.py
Browse files Browse the repository at this point in the history
Defined `_eval_condition_segments` method in the `ConditionHandler`
class for evaluating condition segments seperated by the specified
logical operator.
  • Loading branch information
rahul4732saini committed Nov 3, 2024
1 parent 543d041 commit 952a78a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions fise/query/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 952a78a

Please sign in to comment.