Skip to content

Commit f1f1bdb

Browse files
authored
- Add support for the bytes and sorted builtins (#198)
1 parent a31c557 commit f1f1bdb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

docs/CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changes
44
5.1a0 (unreleased)
55
------------------
66

7+
- Add support for the ``bytes`` and ``sorted`` builtins
8+
(`#186 <https://github.com/zopefoundation/RestrictedPython/issues/186>`_)
9+
710
- Drop install dependency on ``setuptools``.
811
(`#189 <https://github.com/zopefoundation/RestrictedPython/issues/189>`_)
912

src/RestrictedPython/Guards.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'True',
3434
'abs',
3535
'bool',
36+
'bytes',
3637
'callable',
3738
'chr',
3839
'complex',
@@ -52,6 +53,7 @@
5253
'repr',
5354
'round',
5455
'slice',
56+
'sorted',
5557
'str',
5658
'tuple',
5759
'zip'
@@ -174,7 +176,6 @@
174176
# one should care.
175177

176178
# buffer
177-
# bytes
178179
# bytearray
179180
# classmethod
180181
# coerce

tests/test_Guards.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def _write_(x):
1515
return x
1616

1717

18+
def test_Guards_bytes():
19+
"""It contains bytes"""
20+
assert restricted_eval('bytes(1)') == bytes(1)
21+
22+
23+
def test_Guards_sorted():
24+
"""It contains sorted"""
25+
assert restricted_eval('sorted([5, 2, 8, 1])') == sorted([5, 2, 8, 1])
26+
27+
1828
def test_Guards__safe_builtins__1():
1929
"""It contains `slice()`."""
2030
assert restricted_eval('slice(1)') == slice(1)

0 commit comments

Comments
 (0)