mirror of
https://github.com/home-assistant/core.git
synced 2025-12-23 20:39:01 +00:00
Enhance python_script to support "_getitem_" (#8541)
* 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. * Add tests for dict/list support in python_scripts * Lint
This commit is contained in:
committed by
Paulus Schoutsen
parent
ee05a4ab89
commit
8d1999dc12
@@ -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)
|
||||
|
||||
@@ -99,6 +100,7 @@ def execute(hass, filename, source, data=None):
|
||||
'_getattr_': protected_getattr,
|
||||
'_write_': full_write_guard,
|
||||
'_getiter_': iter,
|
||||
'_getitem_': default_guarded_getitem
|
||||
}
|
||||
logger = logging.getLogger('{}.{}'.format(__name__, filename))
|
||||
local = {
|
||||
|
||||
Reference in New Issue
Block a user