Пример #1
0
    def _load(self, context: ILoadingContext) -> Any:
        if not context.expect_scalar():
            return UNDEFINED

        current_node = context.current_node()
        string_value = current_node.value
        return self._convert(context, string_value)
Пример #2
0
    def load(self, context: ILoadingContext, field: IBaseField) -> Any:
        """See Resolver.resolve for usage."""
        if not context.expect_scalar(
            _("import / try-import must be set on a scalar node")
        ):
            return UNDEFINED

        file_path = self._get_file(context)
        if file_path is None:
            node = context.current_node()
            if node.tag == "!import":
                context.error(
                    ErrorCode.IMPORT_NOT_FOUND,
                    _("Unable to find {} in any of the configured directories"),
                    node.value,
                )

            return UNDEFINED

        file_yaml_node = self._load_file(context, file_path)

        if file_yaml_node is None:
            return UNDEFINED

        return context.load(field, file_yaml_node, str(file_path))
Пример #3
0
    def load(self, context: ILoadingContext, field: IBaseField) -> Any:
        if not context.expect_scalar(
            _("!env must be set on a string node containing the variable name.")
        ):
            return UNDEFINED

        node = context.current_node()
        var_name = node.value

        if var_name not in environ:
            return UNDEFINED

        fake_node = ScalarNode("", environ[var_name], node.start_mark, node.end_mark)

        return context.load(field, fake_node)
Пример #4
0
    def load(self, context: ILoadingContext, field: IBaseField) -> Any:
        """See Resolver.resolve for usage."""
        if not context.expect_scalar(_("glob must be set on a scalar node")):
            return UNDEFINED

        node = context.current_node()
        glob = node.value
        result = []
        for root in self._get_roots(context):
            for path in root.glob(glob):
                if not path.is_file():
                    continue

                content = self._load_file(context, path)

                if content is not None:
                    result.append(content)

        fake_node = SequenceNode("", result, node.start_mark, node.end_mark)
        return context.load(field, fake_node)