Last active
January 2, 2019 10:48
-
-
Save lwzm/9756992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval_orig = eval | |
def patch_eval(): | |
if eval is not eval_orig: | |
return False | |
from functools import lru_cache | |
c = lru_cache(maxsize=1000)(compile) | |
e = eval_orig | |
def _eval(expr, globals=None, locals=None): | |
return e(c(expr, expr[:30], "eval"), globals, locals) | |
import builtins | |
builtins.eval = _eval | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment