Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ API overview
:param flags: (optional). defaults to ``0``
:param dont_inherit: (optional). defaults to ``False``
:param policy: (optional). defaults to ``RestrictingNodeTransformer``
:type source: str or ``ast.Module``
:type source: str or bytes or bytearray or ``ast.Module`` or ``ast.Expression`` or ``ast.Interactive``
:type filename: str or bytes or os.PathLike[typing.Any]
:type mode: str
:type flags: int
Expand Down
10 changes: 8 additions & 2 deletions src/RestrictedPython/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ def _compile_restricted_mode(
dont_inherit=dont_inherit)
elif issubclass(policy, RestrictingNodeTransformer):
c_ast = None
allowed_source_types = [str, ast.Module]
allowed_source_types = [
str,
bytes,
bytearray,
ast.Module,
ast.Expression,
ast.Interactive]
if not issubclass(type(source), tuple(allowed_source_types)):
raise TypeError('Not allowed source type: '
'"{0.__class__.__name__}".'.format(source))
c_ast = None
# workaround for pypy issue https://bitbucket.org/pypy/pypy/issues/2552
if isinstance(source, ast.Module):
if isinstance(source, (ast.Module, ast.Expression, ast.Interactive)):
c_ast = source
else:
try:
Expand Down
Loading