Python docutils.nodes 模块,warning() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用docutils.nodes.warning()

项目:bolero    作者:rock-learning    | 项目源码 | 文件源码
def format_parser_error(name, error, filename, state, lineno, do_unicode_warning):

    warning = '%s: Unable to parse xml file "%s". ' % (name, filename)
    explanation = 'Reported error: %s. ' % error

    unicode_explanation_text = ""
    unicode_explanation = []
    if do_unicode_warning:
        unicode_explanation_text = textwrap.dedent("""
        Parsing errors are often due to unicode errors associated with the encoding of the original
        source files. Doxygen propagates invalid characters from the input source files to the
        output xml.""").strip().replace("\n", " ")
        unicode_explanation = [nodes.paragraph("", "", nodes.Text(unicode_explanation_text))]

    return [nodes.warning("",
                nodes.paragraph("", "", nodes.Text(warning)),
                nodes.paragraph("", "", nodes.Text(explanation)),
                *unicode_explanation
                ),
            state.document.reporter.warning(warning + explanation + unicode_explanation_text, line=lineno)
            ]
项目:bolero    作者:rock-learning    | 项目源码 | 文件源码
def warn(self, raw_text, rendered_nodes=None):
        raw_text = self.format(raw_text)
        if rendered_nodes is None:
            rendered_nodes = [nodes.paragraph("", "", nodes.Text(raw_text))]
        return [
            nodes.warning("", *rendered_nodes),
            self.state.document.reporter.warning(raw_text, line=self.context['lineno'])
            ]
项目:Helix.Docs    作者:Sitecore    | 项目源码 | 文件源码
def process_meta(app, doctree, fromdocname):
    env = app.builder.env
    env.page_to_version = defaultdict(set)
    env.version_to_page = defaultdict(set)

    # index metadata
    for pagename, metadata in iter(env.metadata.items()):
        if 'version' in metadata:
            version = metadata['version']
            env.page_to_version[pagename] = version
            env.version_to_page[version].add(pagename)

            if fromdocname == pagename:

                # Alert on outdated version
                current_version = env.config['version']
                if version != current_version:
                    text = 'This page documents version {old} and has not yet been updated for version {new}'.format(
                        old=version,
                        new=current_version,
                    )

                    if app.config['versionwarning_node']:
                        prose = nodes.paragraph(text, text)
                        warning = nodes.warning(prose, prose)
                        doctree.insert(0, warning)
                    if app.config['versionwarning_console']:
                        app.warn(bold('[Version Warning: %s] ' % pagename) + red(text))
项目:plantweb    作者:carlos-jenkins    | 项目源码 | 文件源码
def _directive_checks(self):

        # Check if file insertion is enabled
        if not self.state.document.settings.file_insertion_enabled:
            msg = (
                'File and URL access deactivated. '
                'Ignoring directive "{}".'.format(self._get_directive_name())
            )
            warning = nodes.warning(
                '', self.state_machine.reporter.warning(
                    '', nodes.literal_block('', msg),
                    line=self.lineno
                )
            )
            return [warning]

        # Check that no content and argument are used at the same time
        if self.arguments and self.content:
            warning = self.state_machine.reporter.warning(
                '{} directive cannot have both content and a filename '
                'argument.'.format(self._get_directive_name()),
                line=self.lineno
            )
            return [warning]

        # Check that at least one was provided
        if not (self.arguments or self.content):
            warning = self.state_machine.reporter.warning(
                '{} directive must have content or a filename '
                'argument.'.format(self._get_directive_name()),
                line=self.lineno
            )
            return [warning]

        return None