Open krackers opened 1 year ago
Seems like the eval for pp and p are handled via separate codepaths, and the exposed imports accessible to each differ.
pp
p
E.g. the imports available in the environment you eval an expression with p is given in translate_preset_variables, including:
translate_preset_variables
'date': datetime.datetime.now(), 'math':math, 'env': os.environ.get, 'glob' : glob.glob, 'letters': 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'digits': '0123456789', 'punctuation': """!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~""",
while the environment for pp is much more impoverished, containing only math.
math
I suggest that to provide parity between these two, the set of imports be hoisted to some common global like
in_eval_available_imports = { 'date': datetime.datetime.now(), 'math':math, 'random':random, 'env': os.environ.get, 'glob' : glob.glob, 'letters': 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'digits': '0123456789', 'punctuation': """!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~""", }
and then you could do could use **in_eval_available_imports to include it as part of the respective environment variables before eval'ing. This also allows users to add in any imports they might want (e.g. random).
**in_eval_available_imports
random
Interesting, I'll take a look at this for our future updates.
Seems like the eval for
pp
andp
are handled via separate codepaths, and the exposed imports accessible to each differ.E.g. the imports available in the environment you eval an expression with
p
is given intranslate_preset_variables
, including:while the environment for
pp
is much more impoverished, containing onlymath
.I suggest that to provide parity between these two, the set of imports be hoisted to some common global like
and then you could do could use
**in_eval_available_imports
to include it as part of the respective environment variables before eval'ing. This also allows users to add in any imports they might want (e.g.random
).