-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
BUG/PROBLEM REPORT / FEATURE REQUEST
Hello!
If I pass restricted_globals=dict(__builtins__=safe_builtins)
, my function does not compile. I don't see any errors that it was not compiled. How do I know what needs to be added to safe_builtins
? If I don't pass restricted_globals, then the function is compiled.
What I did:
from RestrictedPython import compile_restricted, safe_builtins
restricted_globals = dict(__builtins__=safe_builtins)
source_code = """
valid_sizes = ['6', '7', '8', '8.5', '9', '10', '10.5']
def check(row, valid_sizes=valid_sizes):
return any('shoes' in category.lower() and all(size in valid_sizes for size in row['sizes']) for category in row['categories'])
"""
byte_code = compile_restricted(
source_code,
filename='<string>',
mode='exec'
)
exec(byte_code, restricted_globals)
check({'categories': ['Shoes', "Women's Shoes", 'Clothing', "All Women's Shoes"], 'sizes': ['8.5', '7', '9.5', '7.5', '8']})
What I expect to happen:
check
to be executed.
What actually happened:
NameError: name 'check' is not defined
What version of Python and Zope/Addons I am using:
Python 3.11.4
RestrictedPython==6.2
Ubuntu
Metadata
Metadata
Assignees
Labels
No labels