mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 11:17:53 +00:00
Raise ImportError in python_script (#134792)
This commit is contained in:
parent
09ffa38ddf
commit
eda60073ee
@ -180,7 +180,7 @@ def guarded_import(
|
|||||||
# Allow import of _strptime needed by datetime.datetime.strptime
|
# Allow import of _strptime needed by datetime.datetime.strptime
|
||||||
if name == "_strptime":
|
if name == "_strptime":
|
||||||
return __import__(name, globals, locals, fromlist, level)
|
return __import__(name, globals, locals, fromlist, level)
|
||||||
raise ScriptError(f"Not allowed to import {name}")
|
raise ImportError(f"Not allowed to import {name}")
|
||||||
|
|
||||||
|
|
||||||
def guarded_inplacevar(op: str, target: Any, operand: Any) -> Any:
|
def guarded_inplacevar(op: str, target: Any, operand: Any) -> Any:
|
||||||
|
@ -711,4 +711,4 @@ async def test_no_other_imports_allowed(
|
|||||||
source = "import sys"
|
source = "import sys"
|
||||||
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done(wait_background_tasks=True)
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
assert "Error executing script: Not allowed to import sys" in caplog.text
|
assert "ImportError: Not allowed to import sys" in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user