diff --git a/docs/usage/api.rst b/docs/usage/api.rst index 8e8ca90..6b81b6c 100644 --- a/docs/usage/api.rst +++ b/docs/usage/api.rst @@ -15,9 +15,9 @@ 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 unicode text or ``ast.AST`` - :type filename: str or unicode text - :type mode: str or unicode text + :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 :type dont_inherit: int :type policy: RestrictingNodeTransformer class diff --git a/src/RestrictedPython/compile.py b/src/RestrictedPython/compile.py index 3253b8c..f1b78cc 100644 --- a/src/RestrictedPython/compile.py +++ b/src/RestrictedPython/compile.py @@ -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: