summaryrefslogtreecommitdiff
diff options
authorColin Watson <cjwatson@debian.org>2025-05-07 09:03:40 +0100
committergit-ubuntu importer <ubuntu-devel-discuss@lists.ubuntu.com>2025-05-07 16:53:52 +0000
commit1262972e79dfd2dbe9de8642c6023efe78ac27aa (patch)
tree6311c5b382389b2aef82bf94a011a7f8398eff19
parentd02b7057b47c226ce0fa238b7e817411caeda0e8 (diff)
parentcaa93e4e0a9bc2e2d88414d4f0f672e56ba04731 (diff)
Imported using git-ubuntu import.
-rw-r--r--.gitignore1
-rw-r--r--NOTES4
-rw-r--r--PKG-INFO2
-rw-r--r--debian/changelog6
-rw-r--r--ev.py60
-rwxr-xr-xevalidate/__init__.py2
-rw-r--r--x.py47
-rw-r--r--xx.py26
-rw-r--r--xx2.py27
-rw-r--r--xx3.py29
-rw-r--r--y.py9
11 files changed, 9 insertions, 204 deletions
diff --git a/.gitignore b/.gitignore
index 0c4e547..5576b77 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ evalidate.egg-info/
*pyc
build/
dist/
+.local/
diff --git a/NOTES b/NOTES
deleted file mode 100644
index 227ac9a..0000000
--- a/NOTES
+++ /dev/null
@@ -1,4 +0,0 @@
-add security verification for attrs/nodes ... (test all jailbreaks against configuration)
-rebuild __builtins__ ?
-make fast filter code? (verify it, extend, and run as fast filter)
-try asteval filtering, maybe faster \ No newline at end of file
diff --git a/PKG-INFO b/PKG-INFO
index c64802e..e798b4e 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: evalidate
-Version: 2.0.4
+Version: 2.0.5
Summary: Validation and secure evaluation of untrusted python expressions
Project-URL: Homepage, https://github.com/yaroslaff/evalidate
Project-URL: Issues, https://github.com/yaroslaff/evalidate/issues
diff --git a/debian/changelog b/debian/changelog
index 6514023..e7cc0a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+python-evalidate (2.0.5-1) unstable; urgency=medium
+
+ * New upstream release.
+
+ -- Colin Watson <cjwatson@debian.org> Wed, 07 May 2025 09:03:40 +0100
+
python-evalidate (2.0.4-1) unstable; urgency=medium
* New upstream release.
diff --git a/ev.py b/ev.py
deleted file mode 100644
index 889de57..0000000
--- a/ev.py
+++ /dev/null
@@ -1,60 +0,0 @@
-from evalidate import Expr, base_eval_model, ExecutionException
-import sys
-
-my_model = base_eval_model.clone()
-my_model.nodes.extend(
- [
- "Call",
- "Attributes",
- "ListComp",
- "DictComp",
- "comprehension",
- "Store",
- "ForOfStatement",
- "Subscript",
- "GeneratorExp",
- "For",
- ]
-)
-my_model.allowed_functions.append("sum")
-my_model.allowed_functions.append("len")
-
-my_shelve = {
- "height": 200,
- "boxes": {
- "box1": {"volume": 110},
- "box2": {"volume": 90},
- },
- "column_width": [20, 480, 40],
-}
-
-box_volumes = [my_shelve["boxes"][box]["volume"] for box in my_shelve["boxes"]]
-total_volume = sum(box_volumes)
-print(total_volume)
-
-# works fine
-exp_string = "sum( my_shelve['column_width'])"
-exp = Expr(exp_string, my_model)
-print("code:", exp.code)
-res = exp.eval({"my_shelve": my_shelve})
-print(res)
-
-
-# throws an Exception:
-# evalidate.ExecutionException: name 'my_shelve' is not defined
-
-# exp_string = "sum([my_shelve['boxes'][box]['volume'] for box in my_shelve['boxes'] ])"
-# exp_string = "sum([my_shelve['boxes'][box]['volume'] for box in my_shelve['boxes'] ])"
-exp_string = "len(my_shelve)"
-exp = Expr(exp_string, my_model)
-
-#print("basic eval")
-#res = eval(exp.code, dict(), {"my_shelve": my_shelve})
-#print("basic res:",res)
-# sys.exit(0)
-try:
- res = exp.eval({"my_shelve": my_shelve})
-except ExecutionException as e:
- print(e)
-
-# print(res)
diff --git a/evalidate/__init__.py b/evalidate/__init__.py
index d5b4a6c..3042d78 100755
--- a/evalidate/__init__.py
+++ b/evalidate/__init__.py
@@ -6,7 +6,7 @@ import ast
import dataclasses
from typing import Callable
-__version__ = '2.0.4'
+__version__ = '2.0.5'
class EvalException(Exception):
diff --git a/x.py b/x.py
deleted file mode 100644
index 8649724..0000000
--- a/x.py
+++ /dev/null
@@ -1,47 +0,0 @@
-import evalidate
-
-def eval_expression(input_string):
- # Step 1
- allowed_names = {"sum": sum, "int": int, "a":1, "b":2, 'startswith': str.startswith}
- # Step 2
- code = compile(input_string, "<string>", "eval")
- # Step 3
- print(code.co_names)
- for name in code.co_names:
- if name not in allowed_names:
- # Step 4
- raise NameError(f"Use of {name!r} not allowed")
- return eval(code, {"__builtins__": {}}, allowed_names)
-
-try:
- src="""
-(lambda fc=(
- lambda n: [
- c for c in
- ().__class__.__bases__[0].__subclasses__()
- if c.__name__ == n
- ][0]
- ):
- fc("function")(
- fc("code")(
- 0,0,0,0,0,0,b"BOOM",(),(),(),"","",0,b""
- ),{}
- )()
-)()
-"""
-
-
- #src = "'asdf'.startswith('as')"
- #src2 ="""__builtins__['eval']("print(1)")"""
-
- #node = evalidate.evalidate(src,
- # addnodes=['Call', 'Attribute', 'ListComp', 'comprehension', 'Store'],
- # attrs=['startswith'])
- #code = compile(node, '<test>', 'eval')
- #r = eval(code)
- #print("eval:", r)
-
- r = eval_expression(src)
- print(r)
-except Exception as e:
- print(e) \ No newline at end of file
diff --git a/xx.py b/xx.py
deleted file mode 100644
index 197f994..0000000
--- a/xx.py
+++ /dev/null
@@ -1,26 +0,0 @@
-import evalidate
-from dataclasses import dataclass
-from evalidate import Expr, EvalException, base_eval_model
-
-@dataclass
-class Person:
- name: str
- weight: float
-
-john = Person(name="John", weight=100)
-jack = Person(name="Jack", weight=60)
-passengers = {"john": john, "jack": jack}
-
-sum_expr = "john.weight + jack.weight"
-
-mymodel = base_eval_model.clone()
-mymodel.nodes.append('Attribute')
-mymodel.attributes.append('weight')
-
-validated_expr = evalidate.Expr(sum_expr, model=mymodel)
-
-
-total_weight = eval(validated_expr.code, passengers, None)
-
-print(total_weight)
-
diff --git a/xx2.py b/xx2.py
deleted file mode 100644
index 6b82bb0..0000000
--- a/xx2.py
+++ /dev/null
@@ -1,27 +0,0 @@
-from dataclasses import dataclass
-from evalidate import Expr, EvalException, base_eval_model
-
-@dataclass
-class Person:
- name: str
- weight: float
-
- def get_weight(self):
- return self.weight
-
-john = Person(name="John", weight=100)
-jack = Person(name="Jack", weight=60)
-passengers = {"john": john, "jack": jack}
-
-sum_expr = "john.get_weight() + jack.get_weight()"
-
-mymodel = base_eval_model.clone()
-mymodel.nodes.extend(['Attribute', 'Call'])
-mymodel.attributes.append('get_weight')
-
-validated_expr = Expr(sum_expr, model=mymodel)
-
-total_weight = eval(validated_expr.code, passengers, None)
-
-print(total_weight)
-
diff --git a/xx3.py b/xx3.py
deleted file mode 100644
index 2d1dc9a..0000000
--- a/xx3.py
+++ /dev/null
@@ -1,29 +0,0 @@
-import evalidate
-from dataclasses import dataclass
-from evalidate import Expr, EvalException, base_eval_model
-
-@dataclass
-class Person:
- name: str
- weight: float
-
- def get_weight(self):
- return self.weight
-
-john = Person(name="John", weight=100)
-jack = Person(name="Jack", weight=60)
-passengers = {"john": john, "jack": jack}
-
-sum_expr = "john.get_weight() + jack.get_weight()"
-
-mymodel =
-
-mymodel.nodes.extend(['Attribute', 'Call'])
-mymodel.attributes.append('get_weight')
-
-validated_expr = evalidate.Expr(sum_expr, model=mymodel)
-
-total_weight = eval(validated_expr.code, {"john": john, "jack": jack}, None)
-
-print(total_weight)
-
diff --git a/y.py b/y.py
deleted file mode 100644
index 5917757..0000000
--- a/y.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from evalidate import Expr, EvalException
-
-src = '-a + 40 > b'
-# src = "__import__('os').system('clear')"
-
-try:
- print(Expr(src).eval({'a':10, 'b':42}))
-except EvalException as e:
- print(e)