forked from SeattleTestbed/repy_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe_check.py
More file actions
32 lines (25 loc) · 757 Bytes
/
safe_check.py
File metadata and controls
32 lines (25 loc) · 757 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
"""
Author: Armon Dadgar
Date: June 11th, 2009
Description:
This simple script reads "code" from stdin, and runs safe.safe_check() on it.
The resulting return value or exception is serialized and written to stdout.
The purpose of this script is to be called from the main repy.py script so that the
memory used by the safe.safe_check() will be reclaimed when this process quits.
"""
import safe
import sys
if __name__ == "__main__":
# Get the user "code"
usercode = sys.stdin.read()
# Output buffer
output = ""
# Check the code
try:
value = safe.safe_check(usercode)
output += str(value)
except Exception,e:
output += str(type(e)) + " " + str(e)
# Write out
sys.stdout.write(output)
sys.stdout.flush()