Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance python_script to support "_getitem_" #8541

Merged
merged 3 commits into from
Jul 20, 2017
Merged
Changes from 1 commit
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
Next Next commit
Enhance python_script to support "_getitem_"
In order to use dict / list structures in python scripts we need
_getitem_ allowed in the RestrictedPython environment. There is a
default_guarded_getitem included with RestrictedPython, which is a
pass through used in the Eval code paths.
  • Loading branch information
sdague committed Jul 18, 2017
commit a1d61c466c6f26eb1190837652163ac3260e83e2
2 changes: 2 additions & 0 deletions homeassistant/components/python_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def execute(hass, filename, source, data=None):
from RestrictedPython import compile_restricted_exec
from RestrictedPython.Guards import safe_builtins, full_write_guard
from RestrictedPython.Utilities import utility_builtins
from RestrictedPython.Eval import default_guarded_getitem

compiled = compile_restricted_exec(source, filename=filename)

Expand Down Expand Up @@ -99,6 +100,7 @@ def protected_getattr(obj, name, default=None):
'_getattr_': protected_getattr,
'_write_': full_write_guard,
'_getiter_': iter,
'_getitem_': default_guarded_getitem
}
logger = logging.getLogger('{}.{}'.format(__name__, filename))
local = {
Expand Down