sync: mnogo

This commit is contained in:
2025-10-03 21:55:24 +03:00
parent 2abfbb4b1a
commit 86182c0808
22 changed files with 4462 additions and 1469 deletions

View File

@@ -594,6 +594,12 @@ def _tokenize_condition_expr(expr: str, context: Dict[str, Any], out_map: Dict[s
while j < n and (expr[j].isalnum() or expr[j] in "._"):
j += 1
word = expr[i:j]
lw = word.lower()
# Литералы: true/false/null (любая раскладка) → Python-константы
if re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", word) and lw in {"true", "false", "null"}:
tokens.append("True" if lw == "true" else ("False" if lw == "false" else "None"))
i = j
continue
# Поддержка «голых» идентификаторов из vars: cycleindex, WAS_ERROR и т.п.
# Если это простой идентификатор (без точек) и он есть в context.vars — биндим его значением.
try:
@@ -752,17 +758,19 @@ def _safe_eval_bool(py_expr: str, bindings: Dict[str, Any]) -> bool:
if isinstance(node.op, ast.Not):
return (not val)
if isinstance(node, ast.BoolOp) and isinstance(node.op, tuple(allowed_boolops)):
vals = [bool(eval_node(v)) for v in node.values]
# Короткое замыкание:
# AND — при первом False прекращаем и возвращаем False; иначе True
# OR — при первом True прекращаем и возвращаем True; иначе False
if isinstance(node.op, ast.And):
res = True
for v in vals:
res = res and v
return res
for v in node.values:
if not bool(eval_node(v)):
return False
return True
if isinstance(node.op, ast.Or):
res = False
for v in vals:
res = res or v
return res
for v in node.values:
if bool(eval_node(v)):
return True
return False
if isinstance(node, ast.Compare):
left = eval_node(node.left)
for opnode, comparator in zip(node.ops, node.comparators):