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.
@@ -4,3 +4,4 @@ evalidate.egg-info/
4
4
  *pyc
5
5
  build/
6
6
  dist/
7
+ .local/
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: evalidate
3
- Version: 2.0.3
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="smartphones" and price<300 and stock>0
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 pythong modules.
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="smartphones" and price<300 and stock>0
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 pythong modules.
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.3'
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, self.model.imported_functions, ctx)
137
+ result = eval(self.code, global_ctx)
130
138
  except Exception as e:
131
139
  raise ExecutionException(e)
132
140
 
@@ -1,6 +1,6 @@
1
1
  [build-system]
2
2
  # requires = ["setuptools >= 40.6.0", "wheel"]
3
- requires = ["hatchling", "wheel"]
3
+ requires = ["hatchling>=1.27.0", "wheel"]
4
4
 
5
5
  # build-backend = "setuptools.build_meta"
6
6
  build-backend = "hatchling.build"
evalidate-2.0.3/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.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
@@ -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