Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _compile_check(name, check):
indent = " " * 4
# Allow check names to contain spaces/dashes, but replace them with underscores
check_name = name.replace(' ', '_').replace('-', '_')
# Allow check names to start with numbers by prepending an _ to them
if check_name[0].isdigit():
check_name = f"_{check_name}"
if not re.match("\w+", check_name):
raise CompileError(
_("{} is not a valid name for a check; check names should consist only of alphanumeric characters, underscores, and spaces").format(name))
out = ["@check50.check()",
f"def {check_name}():",
f'{indent}"""{name}"""']
for run in check:
_validate(name, run)
# Append exit with no args if unspecified
if "exit" not in run:
run["exit"] = None
line = [f"{indent}check50"]
for command_name in COMMANDS:
def _validate(name, run):
if run == "run":
raise CompileError(_("You forgot a - in front of run"))
for key in run:
if key not in COMMANDS:
raise UnsupportedCommand(
_("{} is not a valid command in check {}, use only: {}").format(key, name, COMMANDS))
for required_command in ["run"]:
if required_command not in run:
raise MissingCommand(_("Missing {} in check {}").format(required_name, name))
for key in run:
if key not in COMMANDS:
raise UnsupportedCommand(
_("{} is not a valid command in check {}, use only: {}").format(key, name, COMMANDS))
for required_command in ["run"]:
if required_command not in run:
raise MissingCommand(_("Missing {} in check {}").format(required_name, name))
class CompileError(Exception):
pass
class UnsupportedCommand(CompileError):
pass
class MissingCommand(CompileError):
pass
class InvalidArgument(CompileError):
pass
_("{} is not a valid command in check {}, use only: {}").format(key, name, COMMANDS))
for required_command in ["run"]:
if required_command not in run:
raise MissingCommand(_("Missing {} in check {}").format(required_name, name))
class CompileError(Exception):
pass
class UnsupportedCommand(CompileError):
pass
class MissingCommand(CompileError):
pass
class InvalidArgument(CompileError):
pass
raise MissingCommand(_("Missing {} in check {}").format(required_name, name))
class CompileError(Exception):
pass
class UnsupportedCommand(CompileError):
pass
class MissingCommand(CompileError):
pass
class InvalidArgument(CompileError):
pass