Spaces:
Sleeping
Sleeping
Hopefully resolving one final issue
Browse files
restrictedpython_code_eval.py
CHANGED
|
@@ -46,6 +46,9 @@ from RestrictedPython.Eval import default_guarded_getiter, default_guarded_getit
|
|
| 46 |
from RestrictedPython.Guards import guarded_iter_unpack_sequence, safer_getattr, guarded_unpack_sequence
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
# patch their list implementation to allow empty lists and tuples
|
| 50 |
def limited_list(seq=None):
|
| 51 |
if isinstance(seq, str):
|
|
@@ -54,6 +57,11 @@ def limited_list(seq=None):
|
|
| 54 |
return list(seq) if seq is not None else list()
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
limited_builtins['list'] = limited_list
|
| 58 |
|
| 59 |
|
|
@@ -64,6 +72,11 @@ def limited_tuple(seq=None):
|
|
| 64 |
return tuple(seq) if seq is not None else tuple()
|
| 65 |
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
limited_builtins['tuple'] = limited_tuple
|
| 68 |
|
| 69 |
|
|
|
|
| 46 |
from RestrictedPython.Guards import guarded_iter_unpack_sequence, safer_getattr, guarded_unpack_sequence
|
| 47 |
|
| 48 |
|
| 49 |
+
SAFE_ATTRIBUTES = ['__add__', '__ge__', '__gt__', '__le__', '__lt__', '__mul__', '__ne__', '__rmul__', '__str__',]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
# patch their list implementation to allow empty lists and tuples
|
| 53 |
def limited_list(seq=None):
|
| 54 |
if isinstance(seq, str):
|
|
|
|
| 57 |
return list(seq) if seq is not None else list()
|
| 58 |
|
| 59 |
|
| 60 |
+
for attr in SAFE_ATTRIBUTES:
|
| 61 |
+
if hasattr(list, attr):
|
| 62 |
+
setattr(limited_list, attr, getattr(list, attr))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
limited_builtins['list'] = limited_list
|
| 66 |
|
| 67 |
|
|
|
|
| 72 |
return tuple(seq) if seq is not None else tuple()
|
| 73 |
|
| 74 |
|
| 75 |
+
for attr in SAFE_ATTRIBUTES:
|
| 76 |
+
if hasattr(tuple, attr):
|
| 77 |
+
setattr(limited_tuple, attr, getattr(tuple, attr))
|
| 78 |
+
|
| 79 |
+
|
| 80 |
limited_builtins['tuple'] = limited_tuple
|
| 81 |
|
| 82 |
|