Пример #1
0
def lowercase_string_list(value, min=None, max=None):
    """
    Custom ConfigObj validator that returns a list of lowercase
    items.
    """
    validated_string_list = is_string_list(value, min, max)
    return [x.lower() for x in validated_string_list]
Пример #2
0
def lowercase_string_list(value, min=None, max=None):
    """
    Custom ConfigObj validator that returns a list of lowercase
    items.
    """
    validated_string_list = is_string_list(value, min, max)
    return [x.lower() for x in validated_string_list]
Пример #3
0
def validate_private_objects(value: List[str]) -> List[str]:
    """Check that the private objects are reasonable

    :param value: the config value to check
    :returns: the list of private objects
    :raises: validate.ValidateError
    """
    value = validate.is_string_list(value)
    for obj in value:
        if re.search("[^a-z0-9-]", obj, re.IGNORECASE):
            raise validate.ValidateError(
                'Private objects may only contain letters, digits and the'
                ' \"-\" character.')
        if obj.startswith("-") or obj.endswith("-"):
            raise validate.ValidateError(
                "A \"-\" in a private object label must be at least "
                "surrounded by one letter or digit.")
    return value
Пример #4
0
def validate_command(value: List[str]) -> List[str]:
    """Special validator to check shell commands

    The input must either be a list of strings or a string that shlex.split can
    parse into such.

    :param value: the config value to validate
    :returns: the command after validation
    :raises: validate.ValidateError
    """
    logger.debug("validating %s", value)
    try:
        return validate.is_string_list(value)
    except validate.VdtTypeError:
        logger.debug('continue with %s', value)
        if isinstance(value, str):
            try:
                return shlex.split(value)
            except ValueError as err:
                raise validate.ValidateError(
                    'Error when parsing shell command "{}": {}'.format(
                        value, err))
        raise
Пример #5
0
def requirements_list_validator(value, **kwargs):
    value = validate.force_list(value, **kwargs)
    validate.is_string_list(value)
    # TODO: check the formatting here?
    return value
Пример #6
0
def is_string_set(value, min=None, max=None):
    """
    Function to be used as validation function for configobj to produce a set out of a list.
    """
    return set(is_string_list(value,min,max))
Пример #7
0
def requirements_list_validator(value, **kwargs):
    value = validate.force_list(value, **kwargs)
    validate.is_string_list(value)
    # TODO: check the formatting here?
    return value