|
23 | 23 | import traceback |
24 | 24 | import unicodedata |
25 | 25 |
|
26 | | -# for eval |
27 | | -import random |
28 | | -import math |
29 | | - |
30 | 26 | from collections.abc import Mapping |
31 | 27 | from copy import deepcopy |
32 | 28 | from croniter import croniter |
33 | 29 | from datetime import datetime, timedelta, timezone, tzinfo |
34 | 30 | from difflib import unified_diff |
35 | 31 | from importlib import import_module |
| 32 | +from lupa.lua51 import LuaSyntaxError |
36 | 33 | from pathlib import Path |
37 | 34 | from typing import TYPE_CHECKING, Generator, Iterable, Callable, Any |
38 | 35 | from urllib.parse import urlparse |
@@ -797,16 +794,18 @@ def read_file(self): |
797 | 794 | self.mtime = os.path.getmtime(self.path) |
798 | 795 | data = None |
799 | 796 | if self.path.lower().endswith('.lua'): |
800 | | - content = None |
801 | 797 | try: |
802 | | - #data = luadata.read(self.path, encoding='utf-8') |
803 | | - with open(self.path, mode='r', encoding='utf-8') as infile: |
804 | | - content = infile.read() |
805 | | - data = luadata.unserialize(content, encoding='utf-8') |
| 798 | + ex = None |
| 799 | + for i in range(0, 3): |
| 800 | + try: |
| 801 | + data = luadata.read(self.path, encoding='utf-8') |
| 802 | + break |
| 803 | + except LuaSyntaxError as ex: |
| 804 | + time.sleep(0.5) |
| 805 | + else: |
| 806 | + raise ex |
806 | 807 | except Exception as ex: |
807 | 808 | self.log.debug(f"Exception while reading {self.path}:\n{ex}") |
808 | | - if content: |
809 | | - self.log.debug("Content:\n{}".format(content)) |
810 | 809 | data = alternate_parse_settings(self.path) |
811 | 810 | if not data: |
812 | 811 | self.log.error("- Error while parsing {}:\n{}".format(os.path.basename(self.path), ex)) |
@@ -1080,6 +1079,9 @@ def evaluate(value: str | int | float | bool | list | dict, **kwargs) -> str | i |
1080 | 1079 | If the input value is a string starting with '$', it will be evaluated with placeholders replaced by keyword arguments. |
1081 | 1080 | """ |
1082 | 1081 | def _evaluate(value, **kwargs): |
| 1082 | + import random |
| 1083 | + import math |
| 1084 | + |
1083 | 1085 | if isinstance(value, (int, float, bool)) or not value.startswith('$'): |
1084 | 1086 | return value |
1085 | 1087 | value = format_string(value[1:], **kwargs) |
|
0 commit comments