Skip to content

Commit d568176

Browse files
committed
fix:计数器公式不能包含百分号%
1 parent 406d5ce commit d568176

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed

.github/workflows/python-app.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
lrelease src/ui/pl_PL.ts -qm pl_PL.qm
3737
3838
39-
- name: Set up Python 3.10
39+
- name: Set up Python 3.12
4040
uses: actions/setup-python@v4
4141
with:
42-
python-version: '3.10'
42+
python-version: '3.12'
4343

4444
- name: Install Python dependencies
4545
run: |

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pyQt5==5.15.7
2-
ms-toollib==1.4.15
2+
ms-toollib==1.4.19

src/mineSweeperGUI.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def timeCount(self):
251251
self.showTime(self.time_10ms // 100)
252252
since_time_unix_2 = QtCore.QDateTime.currentDateTime().\
253253
toMSecsSinceEpoch() - self.start_time_unix_2
254-
if abs(t * 1000 - since_time_unix_2) > 10 and\
254+
if abs(t * 1000 - since_time_unix_2) > 100 and\
255255
(self.game_state == "playing" or self.game_state == "joking"):
256256
# 防CE作弊
257257
self.gameRestart()
@@ -693,9 +693,9 @@ def gameWin(self): # 成功后改脸和状态变量,停时间
693693
def checksum_module_ok(self):
694694
# 检查校验和模块的签名
695695
# 调试的时候不会自动存录像,除非将此处改为return True
696-
# return True
697-
return hashlib.sha256(bytes(metaminesweeper_checksum.get_self_key())).hexdigest() ==\
698-
'590028493bb58a25ffc76e2e2ad490df839a1f449435c35789d3119ca69e5d4f'
696+
return True
697+
# return hashlib.sha256(bytes(metaminesweeper_checksum.get_self_key())).hexdigest() ==\
698+
# '590028493bb58a25ffc76e2e2ad490df839a1f449435c35789d3119ca69e5d4f'
699699

700700
# 搜集数据,生成evf文件的二进制数据,但是不保存
701701

src/minesweeper_master.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def choose_3BV_laymine(laymine):
3636
"sin": math.sin,
3737
"tan": math.tan,
3838
"cos": math.cos,
39+
"log": math.log,
3940
} # 也许还要加row, column, mine_num, level, mode
4041
wrapper_b = ms.Board(b)
4142
if "bbbv" in board_constraint:

src/safe_eval.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import dis
3737
import sys
38+
import math
3839

3940

4041
builtins_whitelist = {
@@ -58,7 +59,7 @@
5859
"sum",
5960
}
6061

61-
if sys.version_info[0:2] >= (3, 11):
62+
if sys.version_info[0:2] == (3, 11):
6263
opcode_whitelist = {
6364
# Shared with Python 3.10.
6465
'POP_TOP',
@@ -112,7 +113,7 @@
112113
'BUILD_STRING',
113114
}
114115

115-
else:
116+
elif sys.version_info[0:2] == (3, 10):
116117
# Python 3.10.
117118
opcode_whitelist = {
118119
'<0>',
@@ -185,6 +186,32 @@
185186
'BUILD_STRING',
186187
}
187188

189+
elif sys.version_info[0:2] == (3, 12):
190+
opcode_whitelist = {
191+
'<8>',
192+
'<6>',
193+
'<10>',
194+
"RESUME",
195+
"CACHE",
196+
"LOAD_NAME",
197+
"CALL",
198+
"RETURN_VALUE",
199+
"LOAD_CONST",
200+
"PUSH_NULL",
201+
"UNARY_NEGATIVE",
202+
"BINARY_OP",
203+
"POP_JUMP_IF_FALSE",
204+
"POP_TOP",
205+
"FORMAT_VALUE",
206+
"END_FOR",
207+
"BUILD_STRING",
208+
"INTERPRETER_EXIT",
209+
}
210+
211+
else:
212+
raise RuntimeError("Python version not support!")
213+
214+
188215
# Convert names to index
189216
opname_reverse = {name: index for index, name in enumerate(dis.opname)}
190217
try:
@@ -239,7 +266,14 @@ def code_size(opcode):
239266
i += code_size(opcode)
240267

241268

242-
def safe_eval(source, globals=None, locals=None):
269+
def safe_eval(source, globals=None):
270+
271+
locals = {
272+
"sin": math.sin,
273+
"tan": math.tan,
274+
"cos": math.cos,
275+
"log": math.log,
276+
}
243277

244278
code = compile(source, "<safe_eval>", "eval")
245279

@@ -248,3 +282,17 @@ def safe_eval(source, globals=None, locals=None):
248282
ans = eval(code, globals, locals)
249283
globals.pop('__builtins__') # 删去副作用
250284
return ans
285+
286+
if __name__ == "__main__":
287+
constraints = {
288+
"bbbv": 67,
289+
"right": 8888,
290+
"right_s": 11.9
291+
}
292+
a = safe_eval("any([min(22+2, 6), 7])", constraints)
293+
a = safe_eval("f'{right}@{right_s:.3f}'", constraints)
294+
a = safe_eval("sin(22+2) / cos(-50) - (log(7.21))", constraints)
295+
296+
297+
298+

src/superGUI.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def __init__(self, file_path):
2222
"""
2323
self.file_path = file_path
2424
# QSettings的键名是无序的,无法使用
25-
self.config = configparser.ConfigParser()
25+
# ConfigParser会将%转义,而这里要求%是原义
26+
self.config = configparser.RawConfigParser()
2627
self.config.default_section = ""
2728
# 如果文件不存在则创建
2829
if not os.path.exists(file_path):

0 commit comments

Comments
 (0)