Skip to content

Commit

Permalink
使用evalidate代替eval
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Nov 10, 2023
1 parent 73ce895 commit e7844f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from arknights_mower.utils.logic_expression import LogicExpression
from arknights_mower.utils import rapidocr

from evalidate import Expr

conf = {}
plan = {}
operators = {}
Expand Down Expand Up @@ -456,7 +458,7 @@ def load_state(file="state.json"):
return None
with open(state_file, 'r') as f:
state = json.load(f)
operators = {k: eval(v) for k, v in state["operators"].items()}
operators = {k: Expr(v).eval() for k, v in state["operators"].items()}
for k, v in operators.items():
if not v.time_stamp == "None":
v.time_stamp = datetime.strptime(v.time_stamp, "%Y-%m-%d %H:%M:%S.%f")
Expand Down
3 changes: 2 additions & 1 deletion arknights_mower/utils/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ..solvers.record import save_action_to_sqlite_decorator
from ..utils.log import logger
import copy
from evalidate import Expr


class Operators(object):
Expand Down Expand Up @@ -242,7 +243,7 @@ def init_mood_limit(self):

def evaluate_expression(self, expression):
try:
result = eval(expression, {"op_data": self})
result = Expr(expression).eval({"op_data": self})
return result
except Exception as e:
logger.exception(f"Error evaluating expression: {e}")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ platformdirs==3.11.0
rapidocr-onnxruntime==1.3.7
beautifulsoup4==4.12.2
lxml==4.9.3
evalidate==2.0.2

0 comments on commit e7844f9

Please sign in to comment.