示例#1
0
    def validator(value, config_context):
        if config_context.partial:
            return valid_string(value, config_context)

        context = command_context.CommandContext(
            context_object,
            config_context.command_context,
        )

        try:
            StringFormatter(context).format(value)
            return value
        except (KeyError, ValueError) as e:
            error_msg = "Unknown context variable %s at %s: %s"
            raise ConfigError(error_msg % (e, config_context.path, value))
        except (TypeError) as e:
            error_msg = "Wrong command format %s: %s at %s"
            raise ConfigError(error_msg % (value, e, config_context.path))
示例#2
0
 def render_template(self, template):
     """Render our configured command using the command context."""
     return StringFormatter(self.context).format(template)