evalidate 2.0.0__tar.gz → 2.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {evalidate-2.0.0 → evalidate-2.0.1}/PKG-INFO +8 -8
- {evalidate-2.0.0 → evalidate-2.0.1}/README.md +7 -7
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate/__init__.py +5 -5
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate.egg-info/PKG-INFO +8 -8
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate/security.py +0 -0
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate.egg-info/SOURCES.txt +0 -0
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate.egg-info/dependency_links.txt +0 -0
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate.egg-info/not-zip-safe +0 -0
- {evalidate-2.0.0 → evalidate-2.0.1}/evalidate.egg-info/top_level.txt +0 -0
- {evalidate-2.0.0 → evalidate-2.0.1}/setup.cfg +0 -0
- {evalidate-2.0.0 → evalidate-2.0.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: evalidate
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.1
|
|
4
4
|
Summary: Validation and secure evaluation of untrusted python expressions
|
|
5
5
|
Home-page: http://github.com/yaroslaff/evalidate
|
|
6
6
|
Author: Yaroslav Polyakov
|
|
@@ -63,15 +63,16 @@ Description: # Evalidate
|
|
|
63
63
|
inherit from base exception class `EvalException`.
|
|
64
64
|
|
|
65
65
|
## Configure validation
|
|
66
|
-
Evalidate is very flexible, depending on
|
|
66
|
+
Evalidate is very flexible, depending on security model, same code can either pass validation or raise exception.
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
### EvalModel - using custom security model
|
|
70
|
-
EvalModel is security model for eval - list of allowed AST nodes, function calls, attributes and imported functions. There is built-in model `base_eval_model` with basic operations allowed (which are safe from authors point of view).
|
|
68
|
+
EvalModel is security model class for eval - lists of allowed AST nodes, function calls, attributes and dict of imported functions. There is built-in model `base_eval_model` with basic operations allowed (which are safe from authors point of view).
|
|
71
69
|
|
|
72
70
|
You can create custom empty model (and extend it later):
|
|
71
|
+
~~~python
|
|
73
72
|
my_model = evalidate.EvalModel()
|
|
74
|
-
|
|
73
|
+
~~~
|
|
74
|
+
|
|
75
|
+
(nothing is allowed by default, even `1+2` will not be considered safe)
|
|
75
76
|
|
|
76
77
|
or you may start from `base_eval_mode` and extend it:
|
|
77
78
|
~~~python
|
|
@@ -94,11 +95,10 @@ Description: # Evalidate
|
|
|
94
95
|
|
|
95
96
|
Or, to call attributes:
|
|
96
97
|
~~~python
|
|
97
|
-
m =
|
|
98
|
+
m = base_eval_model.clone()
|
|
98
99
|
m.nodes.extend(['Call', 'Attribute'])
|
|
99
100
|
m.attributes.append('startswith')
|
|
100
101
|
|
|
101
|
-
|
|
102
102
|
src = '"abcdef".startswith("abc")'
|
|
103
103
|
r = evalidate.Expr(src, model=m).eval()
|
|
104
104
|
~~~
|
|
@@ -55,15 +55,16 @@ Evalidate throws exceptions `CompilationException`, `ValidationException`, `Exec
|
|
|
55
55
|
inherit from base exception class `EvalException`.
|
|
56
56
|
|
|
57
57
|
## Configure validation
|
|
58
|
-
Evalidate is very flexible, depending on
|
|
58
|
+
Evalidate is very flexible, depending on security model, same code can either pass validation or raise exception.
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
### EvalModel - using custom security model
|
|
62
|
-
EvalModel is security model for eval - list of allowed AST nodes, function calls, attributes and imported functions. There is built-in model `base_eval_model` with basic operations allowed (which are safe from authors point of view).
|
|
60
|
+
EvalModel is security model class for eval - lists of allowed AST nodes, function calls, attributes and dict of imported functions. There is built-in model `base_eval_model` with basic operations allowed (which are safe from authors point of view).
|
|
63
61
|
|
|
64
62
|
You can create custom empty model (and extend it later):
|
|
63
|
+
~~~python
|
|
65
64
|
my_model = evalidate.EvalModel()
|
|
66
|
-
|
|
65
|
+
~~~
|
|
66
|
+
|
|
67
|
+
(nothing is allowed by default, even `1+2` will not be considered safe)
|
|
67
68
|
|
|
68
69
|
or you may start from `base_eval_mode` and extend it:
|
|
69
70
|
~~~python
|
|
@@ -86,11 +87,10 @@ Expr('int(36.6)', model=my_model).eval()
|
|
|
86
87
|
|
|
87
88
|
Or, to call attributes:
|
|
88
89
|
~~~python
|
|
89
|
-
m =
|
|
90
|
+
m = base_eval_model.clone()
|
|
90
91
|
m.nodes.extend(['Call', 'Attribute'])
|
|
91
92
|
m.attributes.append('startswith')
|
|
92
93
|
|
|
93
|
-
|
|
94
94
|
src = '"abcdef".startswith("abc")'
|
|
95
95
|
r = evalidate.Expr(src, model=m).eval()
|
|
96
96
|
~~~
|
|
@@ -6,7 +6,7 @@ import ast
|
|
|
6
6
|
import dataclasses
|
|
7
7
|
from typing import Callable
|
|
8
8
|
|
|
9
|
-
__version__ = '2.0.
|
|
9
|
+
__version__ = '2.0.1'
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class EvalException(Exception):
|
|
@@ -34,10 +34,10 @@ class ExecutionException(EvalException):
|
|
|
34
34
|
@dataclasses.dataclass
|
|
35
35
|
class EvalModel:
|
|
36
36
|
""" eval security model """
|
|
37
|
-
nodes: list
|
|
38
|
-
allowed_functions: list
|
|
39
|
-
imported_functions: dict
|
|
40
|
-
attributes: list
|
|
37
|
+
nodes: list
|
|
38
|
+
allowed_functions: list = dataclasses.field(default_factory=list)
|
|
39
|
+
imported_functions: dict = dataclasses.field(default_factory=dict)
|
|
40
|
+
attributes: list = dataclasses.field(default_factory=list)
|
|
41
41
|
|
|
42
42
|
def clone(self):
|
|
43
43
|
return EvalModel(**dataclasses.asdict(self))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: evalidate
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.1
|
|
4
4
|
Summary: Validation and secure evaluation of untrusted python expressions
|
|
5
5
|
Home-page: http://github.com/yaroslaff/evalidate
|
|
6
6
|
Author: Yaroslav Polyakov
|
|
@@ -63,15 +63,16 @@ Description: # Evalidate
|
|
|
63
63
|
inherit from base exception class `EvalException`.
|
|
64
64
|
|
|
65
65
|
## Configure validation
|
|
66
|
-
Evalidate is very flexible, depending on
|
|
66
|
+
Evalidate is very flexible, depending on security model, same code can either pass validation or raise exception.
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
### EvalModel - using custom security model
|
|
70
|
-
EvalModel is security model for eval - list of allowed AST nodes, function calls, attributes and imported functions. There is built-in model `base_eval_model` with basic operations allowed (which are safe from authors point of view).
|
|
68
|
+
EvalModel is security model class for eval - lists of allowed AST nodes, function calls, attributes and dict of imported functions. There is built-in model `base_eval_model` with basic operations allowed (which are safe from authors point of view).
|
|
71
69
|
|
|
72
70
|
You can create custom empty model (and extend it later):
|
|
71
|
+
~~~python
|
|
73
72
|
my_model = evalidate.EvalModel()
|
|
74
|
-
|
|
73
|
+
~~~
|
|
74
|
+
|
|
75
|
+
(nothing is allowed by default, even `1+2` will not be considered safe)
|
|
75
76
|
|
|
76
77
|
or you may start from `base_eval_mode` and extend it:
|
|
77
78
|
~~~python
|
|
@@ -94,11 +95,10 @@ Description: # Evalidate
|
|
|
94
95
|
|
|
95
96
|
Or, to call attributes:
|
|
96
97
|
~~~python
|
|
97
|
-
m =
|
|
98
|
+
m = base_eval_model.clone()
|
|
98
99
|
m.nodes.extend(['Call', 'Attribute'])
|
|
99
100
|
m.attributes.append('startswith')
|
|
100
101
|
|
|
101
|
-
|
|
102
102
|
src = '"abcdef".startswith("abc")'
|
|
103
103
|
r = evalidate.Expr(src, model=m).eval()
|
|
104
104
|
~~~
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|