-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlxd_script_run.py
More file actions
33 lines (25 loc) · 823 Bytes
/
Copy pathlxd_script_run.py
File metadata and controls
33 lines (25 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from wrapt_timeout_decorator import *
import re
# def paste_imports():
# with open('script.py', 'r+') as f:
# content = f.read()
# f.seek(0, 0)
# f.write(line.rstrip('\r\n') + '\n' + content)
@timeout(5)
def exec_script():
exec(open("script.py", encoding="utf-8").read())
def search_for_illegal():
illegal_keywords = ["import" , "eval"]
with open("script.py", encoding="utf-8") as f:
for line in f:
for regex in illegal_keywords:
search = re.search(regex, line)
if search:
return search.group()
return None
if __name__ == "__main__":
err = search_for_illegal()
if err == None:
exec_script()
else:
print("Illegal keyword detected: " + err)