Revert "Upgrade restrictedpython to 4.0b2"

This reverts commit 8e4f0ea5aec36879dcd58b4161161714d6d9d41c.
This commit is contained in:
Fabian Affolter 2017-10-27 21:52:44 +02:00
parent 8e4f0ea5ae
commit 38c189ecf4
No known key found for this signature in database
GPG Key ID: DDF3D6F44AAB1336
3 changed files with 20 additions and 28 deletions

View File

@ -1,9 +1,4 @@
""" """Component to allow running Python scripts."""
Component to allow running Python scripts.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/python_script/
"""
import datetime import datetime
import glob import glob
import logging import logging
@ -12,19 +7,16 @@ import time
import voluptuous as vol import voluptuous as vol
import homeassistant.util.dt as dt_util
from homeassistant.const import SERVICE_RELOAD from homeassistant.const import SERVICE_RELOAD
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.util import sanitize_filename from homeassistant.util import sanitize_filename
import homeassistant.util.dt as dt_util
REQUIREMENTS = ['restrictedpython==4.0b2']
_LOGGER = logging.getLogger(__name__)
DOMAIN = 'python_script' DOMAIN = 'python_script'
REQUIREMENTS = ['restrictedpython==4.0a3']
FOLDER = 'python_scripts' FOLDER = 'python_scripts'
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema({ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema(dict) DOMAIN: vol.Schema(dict)
@ -55,7 +47,7 @@ def setup(hass, config):
path = hass.config.path(FOLDER) path = hass.config.path(FOLDER)
if not os.path.isdir(path): if not os.path.isdir(path):
_LOGGER.warning("Folder %s not found in configuration folder", FOLDER) _LOGGER.warning('Folder %s not found in config folder', FOLDER)
return False return False
discover_scripts(hass) discover_scripts(hass)
@ -73,7 +65,7 @@ def discover_scripts(hass):
path = hass.config.path(FOLDER) path = hass.config.path(FOLDER)
if not os.path.isdir(path): if not os.path.isdir(path):
_LOGGER.warning("Folder %s not found in configuration folder", FOLDER) _LOGGER.warning('Folder %s not found in config folder', FOLDER)
return False return False
def python_script_service_handler(call): def python_script_service_handler(call):
@ -112,19 +104,19 @@ def execute(hass, filename, source, data=None):
compiled = compile_restricted_exec(source, filename=filename) compiled = compile_restricted_exec(source, filename=filename)
if compiled.errors: if compiled.errors:
_LOGGER.error("Error loading script %s: %s", filename, _LOGGER.error('Error loading script %s: %s', filename,
", ".join(compiled.errors)) ', '.join(compiled.errors))
return return
if compiled.warnings: if compiled.warnings:
_LOGGER.warning("Warning loading script %s: %s", filename, _LOGGER.warning('Warning loading script %s: %s', filename,
", ".join(compiled.warnings)) ', '.join(compiled.warnings))
def protected_getattr(obj, name, default=None): def protected_getattr(obj, name, default=None):
"""Restricted method to get attributes.""" """Restricted method to get attributes."""
# pylint: disable=too-many-boolean-expressions # pylint: disable=too-many-boolean-expressions
if name.startswith('async_'): if name.startswith('async_'):
raise ScriptError("Not allowed to access async methods") raise ScriptError('Not allowed to access async methods')
elif (obj is hass and name not in ALLOWED_HASS or elif (obj is hass and name not in ALLOWED_HASS or
obj is hass.bus and name not in ALLOWED_EVENTBUS or obj is hass.bus and name not in ALLOWED_EVENTBUS or
obj is hass.states and name not in ALLOWED_STATEMACHINE or obj is hass.states and name not in ALLOWED_STATEMACHINE or
@ -132,7 +124,7 @@ def execute(hass, filename, source, data=None):
obj is dt_util and name not in ALLOWED_DT_UTIL or obj is dt_util and name not in ALLOWED_DT_UTIL or
obj is datetime and name not in ALLOWED_DATETIME or obj is datetime and name not in ALLOWED_DATETIME or
isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME): isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME):
raise ScriptError("Not allowed to access {}.{}".format( raise ScriptError('Not allowed to access {}.{}'.format(
obj.__class__.__name__, name)) obj.__class__.__name__, name))
return getattr(obj, name, default) return getattr(obj, name, default)
@ -160,13 +152,13 @@ def execute(hass, filename, source, data=None):
} }
try: try:
_LOGGER.info("Executing %s: %s", filename, data) _LOGGER.info('Executing %s: %s', filename, data)
# pylint: disable=exec-used # pylint: disable=exec-used
exec(compiled.code, restricted_globals, local) exec(compiled.code, restricted_globals, local)
except ScriptError as err: except ScriptError as err:
logger.error("Error executing script: %s", err) logger.error('Error executing script: %s', err)
except Exception as err: # pylint: disable=broad-except except Exception as err: # pylint: disable=broad-except
logger.exception("Error executing script: %s", err) logger.exception('Error executing script: %s', err)
class StubPrinter: class StubPrinter:
@ -180,7 +172,7 @@ class StubPrinter:
"""Print text.""" """Print text."""
# pylint: disable=no-self-use # pylint: disable=no-self-use
_LOGGER.warning( _LOGGER.warning(
"Don't use print() inside scripts. Use logger.info() instead") "Don't use print() inside scripts. Use logger.info() instead.")
class TimeWrapper: class TimeWrapper:
@ -194,8 +186,8 @@ class TimeWrapper:
"""Sleep method that warns once.""" """Sleep method that warns once."""
if not TimeWrapper.warned: if not TimeWrapper.warned:
TimeWrapper.warned = True TimeWrapper.warned = True
_LOGGER.warning("Using time.sleep can reduce the performance of " _LOGGER.warning('Using time.sleep can reduce the performance of '
"Home Assistant") 'Home Assistant')
time.sleep(*args, **kwargs) time.sleep(*args, **kwargs)

View File

@ -894,7 +894,7 @@ raincloudy==0.0.3
regenmaschine==0.4.1 regenmaschine==0.4.1
# homeassistant.components.python_script # homeassistant.components.python_script
restrictedpython==4.0b2 restrictedpython==4.0a3
# homeassistant.components.rflink # homeassistant.components.rflink
rflink==0.0.34 rflink==0.0.34

View File

@ -124,7 +124,7 @@ pyunifi==2.13
pywebpush==1.1.0 pywebpush==1.1.0
# homeassistant.components.python_script # homeassistant.components.python_script
restrictedpython==4.0b2 restrictedpython==4.0a3
# homeassistant.components.rflink # homeassistant.components.rflink
rflink==0.0.34 rflink==0.0.34