evalidate 2.0.4__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.
@@ -4,3 +4,4 @@ evalidate.egg-info/
4
4
  *pyc
5
5
  build/
6
6
  dist/
7
+ .local/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evalidate
3
- Version: 2.0.4
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
@@ -6,7 +6,7 @@ import ast
6
6
  import dataclasses
7
7
  from typing import Callable
8
8
 
9
- __version__ = '2.0.4'
9
+ __version__ = '2.0.5'
10
10
 
11
11
 
12
12
  class EvalException(Exception):
evalidate-2.0.4/NOTES DELETED
@@ -1,4 +0,0 @@
1
- add security verification for attrs/nodes ... (test all jailbreaks against configuration)
2
- rebuild __builtins__ ?
3
- make fast filter code? (verify it, extend, and run as fast filter)
4
- try asteval filtering, maybe faster
evalidate-2.0.4/ev.py DELETED
@@ -1,60 +0,0 @@
1
- from evalidate import Expr, base_eval_model, ExecutionException
2
- import sys
3
-
4
- my_model = base_eval_model.clone()
5
- my_model.nodes.extend(
6
- [
7
- "Call",
8
- "Attributes",
9
- "ListComp",
10
- "DictComp",
11
- "comprehension",
12
- "Store",
13
- "ForOfStatement",
14
- "Subscript",
15
- "GeneratorExp",
16
- "For",
17
- ]
18
- )
19
- my_model.allowed_functions.append("sum")
20
- my_model.allowed_functions.append("len")
21
-
22
- my_shelve = {
23
- "height": 200,
24
- "boxes": {
25
- "box1": {"volume": 110},
26
- "box2": {"volume": 90},
27
- },
28
- "column_width": [20, 480, 40],
29
- }
30
-
31
- box_volumes = [my_shelve["boxes"][box]["volume"] for box in my_shelve["boxes"]]
32
- total_volume = sum(box_volumes)
33
- print(total_volume)
34
-
35
- # works fine
36
- exp_string = "sum( my_shelve['column_width'])"
37
- exp = Expr(exp_string, my_model)
38
- print("code:", exp.code)
39
- res = exp.eval({"my_shelve": my_shelve})
40
- print(res)
41
-
42
-
43
- # throws an Exception:
44
- # evalidate.ExecutionException: name 'my_shelve' is not defined
45
-
46
- # exp_string = "sum([my_shelve['boxes'][box]['volume'] for box in my_shelve['boxes'] ])"
47
- # exp_string = "sum([my_shelve['boxes'][box]['volume'] for box in my_shelve['boxes'] ])"
48
- exp_string = "len(my_shelve)"
49
- exp = Expr(exp_string, my_model)
50
-
51
- #print("basic eval")
52
- #res = eval(exp.code, dict(), {"my_shelve": my_shelve})
53
- #print("basic res:",res)
54
- # sys.exit(0)
55
- try:
56
- res = exp.eval({"my_shelve": my_shelve})
57
- except ExecutionException as e:
58
- print(e)
59
-
60
- # print(res)
evalidate-2.0.4/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.4/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.4/xx2.py DELETED
@@ -1,27 +0,0 @@
1
- from dataclasses import dataclass
2
- from evalidate import Expr, EvalException, base_eval_model
3
-
4
- @dataclass
5
- class Person:
6
- name: str
7
- weight: float
8
-
9
- def get_weight(self):
10
- return self.weight
11
-
12
- john = Person(name="John", weight=100)
13
- jack = Person(name="Jack", weight=60)
14
- passengers = {"john": john, "jack": jack}
15
-
16
- sum_expr = "john.get_weight() + jack.get_weight()"
17
-
18
- mymodel = base_eval_model.clone()
19
- mymodel.nodes.extend(['Attribute', 'Call'])
20
- mymodel.attributes.append('get_weight')
21
-
22
- validated_expr = Expr(sum_expr, model=mymodel)
23
-
24
- total_weight = eval(validated_expr.code, passengers, None)
25
-
26
- print(total_weight)
27
-
evalidate-2.0.4/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 =
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.4/y.py DELETED
@@ -1,9 +0,0 @@
1
- from evalidate import Expr, EvalException
2
-
3
- src = '-a + 40 > b'
4
- # src = "__import__('os').system('clear')"
5
-
6
- try:
7
- print(Expr(src).eval({'a':10, 'b':42}))
8
- except EvalException as e:
9
- print(e)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes