Usual python eval() function is very flexible, but very insecure, allowing user to supply malicious code like os.system(‘clear’) or worse.
(for example: http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html )
evalidate module allows to easily pre-compile user-supplied python expressions to AST-tree and validate it (or indicate problem with expression), so only safe expressions will be evaluated.
Whitelist of allowed operations could be supplied by programmer as arguments to functions.
Using it could be as simple as:
import evalidate
src="a<b" # source code
c={'a': 1, 'b': 2} # context, variables which will be available for code
success,result = evalidate.safeeval(src,c)
Read more on readthedocs project page.
Metadata
Release files for evalidate 0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| evalidate-0.6.tar.gz | 2.0 kB | Details |
Release files / evalidate-0.6.tar.gz
| Download URL | evalidate-0.6.tar.gz |
|---|---|
| Size | 2.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ee01f17353ff63f818c7ee228b0e0a4e4f24833eae9fc48467799be08061e57
|
|
BLAKE2b-256 checksum How to use checksums |
6dd1ebc154f2f88f90be612b515fd284504fa4ca9de77854afa5a1e5db6cf8a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |