From 76951e665e42f357a21c99041ad6bae45a5b5e54 Mon Sep 17 00:00:00 2001 From: shughes Date: Thu, 9 Jan 2020 12:54:51 -0800 Subject: [PATCH] fix for situation where help is unavailable --- simpleeval.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/simpleeval.py b/simpleeval.py index 731c37e..e826c46 100644 --- a/simpleeval.py +++ b/simpleeval.py @@ -112,8 +112,21 @@ # people not be stupid. Allowing these functions opens up all sorts of holes - if any of # their functionality is required, then please wrap them up in a safe container. And think # very hard about it first. And don't say I didn't warn you. +if isinstance(__builtins__, dict) and 'help' in __builtins__: # builtins is a dict in python >3.6 but a module before + DISALLOW_FUNCTIONS = { + type, isinstance, eval, getattr, setattr, help, repr, compile, open + } +elif 'help' in dir(__builtins__): + DISALLOW_FUNCTIONS = { + type, isinstance, eval, getattr, setattr, help, repr, compile, open + } +else: + print('help not in builtins') + + DISALLOW_FUNCTIONS = { + type, isinstance, eval, getattr, setattr, repr, compile, open + } -DISALLOW_FUNCTIONS = {type, isinstance, eval, getattr, setattr, help, repr, compile, open} if PYTHON3: exec('DISALLOW_FUNCTIONS.add(exec)') # exec is not a function in Python2...