diff options
author | 2021-02-26 14:21:00 +0100 | |
---|---|---|
committer | 2021-02-26 14:21:00 +0100 | |
commit | 9d2c3794a4c95f6c63a7de64172bc35a68403a4c (patch) | |
tree | c01d39e6f5862a00fc478da5f08d73ede43972dd /resources | |
parent | Properly hadnle hidden tests starting with test_ (diff) |
Use base64 encoded code snippets
Diffstat (limited to 'resources')
-rw-r--r-- | resources/unittest_template.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/resources/unittest_template.py b/resources/unittest_template.py index 38e3be8..2410278 100644 --- a/resources/unittest_template.py +++ b/resources/unittest_template.py @@ -1,6 +1,7 @@ # flake8: noqa """This template is used inside snekbox to evaluate and test user code.""" import ast +import base64 import io import os import sys @@ -36,14 +37,15 @@ def _exit_sandbox(code: int) -> NoReturn: def _load_user_module() -> ModuleType: """Load the user code into a new module and return it.""" + code = base64.b64decode(USER_CODE).decode("utf8") try: - ast.parse(USER_CODE, "<input>") + ast.parse(code, "<input>") except SyntaxError: RESULT.write("".join(traceback.format_exception(*sys.exc_info(), limit=0))) _exit_sandbox(5) _module = ModuleType("module") - exec(USER_CODE, _module.__dict__) + exec(code, _module.__dict__) return _module |