evalidate 2.0.3__tar.gz → 2.0.5__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.3 → evalidate-2.0.5}/.gitignore +1 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/PKG-INFO +5 -4
- {evalidate-2.0.3 → evalidate-2.0.5}/README.md +3 -2
- {evalidate-2.0.3 → evalidate-2.0.5}/evalidate/__init__.py +11 -3
- {evalidate-2.0.3 → evalidate-2.0.5}/pyproject.toml +1 -1
- evalidate-2.0.3/NOTES +0 -4
- evalidate-2.0.3/x.py +0 -47
- evalidate-2.0.3/xx.py +0 -26
- evalidate-2.0.3/xx2.py +0 -28
- evalidate-2.0.3/xx3.py +0 -29
- evalidate-2.0.3/y.py +0 -9
- {evalidate-2.0.3 → evalidate-2.0.5}/LICENSE +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/benchmark/benchmark.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/evalidate/credits.txt +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/evalidate/security.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/examples/basic.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/examples/products.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/setup.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/tests/test_exc.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/tests/test_expr.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/tests/test_feature.py +0 -0
- {evalidate-2.0.3 → evalidate-2.0.5}/tests/test_jailbreak.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: evalidate
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.5
|
|
4
4
|
Summary: Validation and secure evaluation of untrusted python expressions
|
|
5
5
|
Project-URL: Homepage, https://github.com/yaroslaff/evalidate
|
|
6
6
|
Project-URL: Issues, https://github.com/yaroslaff/evalidate/issues
|
|
@@ -25,7 +25,7 @@ Originally it's developed for filtering complex data structures e.g.
|
|
|
25
25
|
|
|
26
26
|
Find cheap smartphones available for sale:
|
|
27
27
|
```python
|
|
28
|
-
category
|
|
28
|
+
category=="smartphones" and price<300 and stock>0
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
But also, it can be used for other expressions, e.g. arithmetical, like
|
|
@@ -33,7 +33,7 @@ But also, it can be used for other expressions, e.g. arithmetical, like
|
|
|
33
33
|
a+b-100
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
Evalidate is fastest among all (known to me) secure eval
|
|
36
|
+
Evalidate is fastest among all (known to me) secure eval python modules.
|
|
37
37
|
|
|
38
38
|
## Install
|
|
39
39
|
|
|
@@ -121,6 +121,7 @@ def one():
|
|
|
121
121
|
|
|
122
122
|
m = base_eval_model.clone()
|
|
123
123
|
m.nodes.append('Call')
|
|
124
|
+
m.imported_functions["one"] = one
|
|
124
125
|
Expr('one()', model=m).eval()
|
|
125
126
|
~~~
|
|
126
127
|
|
|
@@ -11,7 +11,7 @@ Originally it's developed for filtering complex data structures e.g.
|
|
|
11
11
|
|
|
12
12
|
Find cheap smartphones available for sale:
|
|
13
13
|
```python
|
|
14
|
-
category
|
|
14
|
+
category=="smartphones" and price<300 and stock>0
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
But also, it can be used for other expressions, e.g. arithmetical, like
|
|
@@ -19,7 +19,7 @@ But also, it can be used for other expressions, e.g. arithmetical, like
|
|
|
19
19
|
a+b-100
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Evalidate is fastest among all (known to me) secure eval
|
|
22
|
+
Evalidate is fastest among all (known to me) secure eval python modules.
|
|
23
23
|
|
|
24
24
|
## Install
|
|
25
25
|
|
|
@@ -107,6 +107,7 @@ def one():
|
|
|
107
107
|
|
|
108
108
|
m = base_eval_model.clone()
|
|
109
109
|
m.nodes.append('Call')
|
|
110
|
+
m.imported_functions["one"] = one
|
|
110
111
|
Expr('one()', model=m).eval()
|
|
111
112
|
~~~
|
|
112
113
|
|
|
@@ -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.5'
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class EvalException(Exception):
|
|
@@ -124,9 +124,17 @@ class Expr():
|
|
|
124
124
|
self.code = compile(self.node, filename or '<usercode>', 'eval')
|
|
125
125
|
|
|
126
126
|
def eval(self, ctx=None):
|
|
127
|
-
|
|
127
|
+
|
|
128
|
+
if ctx:
|
|
129
|
+
global_ctx = {
|
|
130
|
+
**self.model.imported_functions,
|
|
131
|
+
**ctx
|
|
132
|
+
}
|
|
133
|
+
else:
|
|
134
|
+
global_ctx = self.model.imported_functions
|
|
135
|
+
|
|
128
136
|
try:
|
|
129
|
-
result = eval(self.code,
|
|
137
|
+
result = eval(self.code, global_ctx)
|
|
130
138
|
except Exception as e:
|
|
131
139
|
raise ExecutionException(e)
|
|
132
140
|
|
evalidate-2.0.3/NOTES
DELETED
evalidate-2.0.3/x.py
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import evalidate
|
|
2
|
-
|
|
3
|
-
def eval_expression(input_string):
|
|
4
|
-
# Step 1
|
|
5
|
-
allowed_names = {"sum": sum, "int": int, "a":1, "b":2, 'startswith': str.startswith}
|
|
6
|
-
# Step 2
|
|
7
|
-
code = compile(input_string, "<string>", "eval")
|
|
8
|
-
# Step 3
|
|
9
|
-
print(code.co_names)
|
|
10
|
-
for name in code.co_names:
|
|
11
|
-
if name not in allowed_names:
|
|
12
|
-
# Step 4
|
|
13
|
-
raise NameError(f"Use of {name!r} not allowed")
|
|
14
|
-
return eval(code, {"__builtins__": {}}, allowed_names)
|
|
15
|
-
|
|
16
|
-
try:
|
|
17
|
-
src="""
|
|
18
|
-
(lambda fc=(
|
|
19
|
-
lambda n: [
|
|
20
|
-
c for c in
|
|
21
|
-
().__class__.__bases__[0].__subclasses__()
|
|
22
|
-
if c.__name__ == n
|
|
23
|
-
][0]
|
|
24
|
-
):
|
|
25
|
-
fc("function")(
|
|
26
|
-
fc("code")(
|
|
27
|
-
0,0,0,0,0,0,b"BOOM",(),(),(),"","",0,b""
|
|
28
|
-
),{}
|
|
29
|
-
)()
|
|
30
|
-
)()
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
#src = "'asdf'.startswith('as')"
|
|
35
|
-
#src2 ="""__builtins__['eval']("print(1)")"""
|
|
36
|
-
|
|
37
|
-
#node = evalidate.evalidate(src,
|
|
38
|
-
# addnodes=['Call', 'Attribute', 'ListComp', 'comprehension', 'Store'],
|
|
39
|
-
# attrs=['startswith'])
|
|
40
|
-
#code = compile(node, '<test>', 'eval')
|
|
41
|
-
#r = eval(code)
|
|
42
|
-
#print("eval:", r)
|
|
43
|
-
|
|
44
|
-
r = eval_expression(src)
|
|
45
|
-
print(r)
|
|
46
|
-
except Exception as e:
|
|
47
|
-
print(e)
|
evalidate-2.0.3/xx.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import evalidate
|
|
2
|
-
from dataclasses import dataclass
|
|
3
|
-
from evalidate import Expr, EvalException, base_eval_model
|
|
4
|
-
|
|
5
|
-
@dataclass
|
|
6
|
-
class Person:
|
|
7
|
-
name: str
|
|
8
|
-
weight: float
|
|
9
|
-
|
|
10
|
-
john = Person(name="John", weight=100)
|
|
11
|
-
jack = Person(name="Jack", weight=60)
|
|
12
|
-
passengers = {"john": john, "jack": jack}
|
|
13
|
-
|
|
14
|
-
sum_expr = "john.weight + jack.weight"
|
|
15
|
-
|
|
16
|
-
mymodel = base_eval_model.clone()
|
|
17
|
-
mymodel.nodes.append('Attribute')
|
|
18
|
-
mymodel.attributes.append('weight')
|
|
19
|
-
|
|
20
|
-
validated_expr = evalidate.Expr(sum_expr, model=mymodel)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
total_weight = eval(validated_expr.code, passengers, None)
|
|
24
|
-
|
|
25
|
-
print(total_weight)
|
|
26
|
-
|
evalidate-2.0.3/xx2.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import evalidate
|
|
2
|
-
from dataclasses import dataclass
|
|
3
|
-
from evalidate import Expr, EvalException, base_eval_model
|
|
4
|
-
|
|
5
|
-
@dataclass
|
|
6
|
-
class Person:
|
|
7
|
-
name: str
|
|
8
|
-
weight: float
|
|
9
|
-
|
|
10
|
-
def get_weight(self):
|
|
11
|
-
return self.weight
|
|
12
|
-
|
|
13
|
-
john = Person(name="John", weight=100)
|
|
14
|
-
jack = Person(name="Jack", weight=60)
|
|
15
|
-
passengers = {"john": john, "jack": jack}
|
|
16
|
-
|
|
17
|
-
sum_expr = "john.get_weight() + jack.get_weight()"
|
|
18
|
-
|
|
19
|
-
mymodel = base_eval_model.clone()
|
|
20
|
-
mymodel.nodes.extend(['Attribute', 'Call'])
|
|
21
|
-
mymodel.attributes.append('get_weight')
|
|
22
|
-
|
|
23
|
-
validated_expr = evalidate.Expr(sum_expr, model=mymodel)
|
|
24
|
-
|
|
25
|
-
total_weight = eval(validated_expr.code, {"john": john, "jack": jack}, None)
|
|
26
|
-
|
|
27
|
-
print(total_weight)
|
|
28
|
-
|
evalidate-2.0.3/xx3.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import evalidate
|
|
2
|
-
from dataclasses import dataclass
|
|
3
|
-
from evalidate import Expr, EvalException, base_eval_model
|
|
4
|
-
|
|
5
|
-
@dataclass
|
|
6
|
-
class Person:
|
|
7
|
-
name: str
|
|
8
|
-
weight: float
|
|
9
|
-
|
|
10
|
-
def get_weight(self):
|
|
11
|
-
return self.weight
|
|
12
|
-
|
|
13
|
-
john = Person(name="John", weight=100)
|
|
14
|
-
jack = Person(name="Jack", weight=60)
|
|
15
|
-
passengers = {"john": john, "jack": jack}
|
|
16
|
-
|
|
17
|
-
sum_expr = "john.get_weight() + jack.get_weight()"
|
|
18
|
-
|
|
19
|
-
mymodel = evalidate.EvalModel()
|
|
20
|
-
|
|
21
|
-
mymodel.nodes.extend(['Attribute', 'Call'])
|
|
22
|
-
mymodel.attributes.append('get_weight')
|
|
23
|
-
|
|
24
|
-
validated_expr = evalidate.Expr(sum_expr, model=mymodel)
|
|
25
|
-
|
|
26
|
-
total_weight = eval(validated_expr.code, {"john": john, "jack": jack}, None)
|
|
27
|
-
|
|
28
|
-
print(total_weight)
|
|
29
|
-
|
evalidate-2.0.3/y.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|