当前位置: 首页>>代码示例>>Python>>正文


Python statemachine.string2lines方法代码示例

本文整理汇总了Python中docutils.statemachine.string2lines方法的典型用法代码示例。如果您正苦于以下问题:Python statemachine.string2lines方法的具体用法?Python statemachine.string2lines怎么用?Python statemachine.string2lines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.statemachine的用法示例。


在下文中一共展示了statemachine.string2lines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def run(self):
        oldStdout, sys.stdout = sys.stdout, StringIO()

        tab_width = self.options.get(
            'tab-width', self.state.document.settings.tab_width)
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)

        try:
            exec('\n'.join(self.content))
            text = sys.stdout.getvalue()
            lines = statemachine.string2lines(
                text, tab_width, convert_whitespace=True)
            self.state_machine.insert_input(lines, source)
            return []
        except Exception:
            return [nodes.error(None, nodes.paragraph(text="Unable to execute python code at %s:%d:" % (basename(source), self.lineno)), nodes.paragraph(text=str(sys.exc_info()[1])))]
        finally:
            sys.stdout = oldStdout 
开发者ID:GiggleLiu,项目名称:viznet,代码行数:21,代码来源:conf.py

示例2: run

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def run(self):
        oldStdout, sys.stdout = sys.stdout, StringIO()

        tab_width = self.options.get('tab-width', self.state.document.settings.tab_width)
        source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)

        try:
            exec('\n'.join(self.content))
            text = sys.stdout.getvalue()
            lines = statemachine.string2lines(text, tab_width, convert_whitespace=True)
            self.state_machine.insert_input(lines, source)
            return []
        except Exception:
            return [nodes.error(
                None,
                nodes.paragraph(text="Unable to execute python code at %s:%d:" % (
                    basename(source), self.lineno)),
                nodes.paragraph(text=str(sys.exc_info()[1])))]
        finally:
            sys.stdout = oldStdout 
开发者ID:mobiusklein,项目名称:ms_deisotope,代码行数:22,代码来源:exec_directive.py

示例3: run

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def run(self):
        oldStdout, sys.stdout = sys.stdout, StringIO()

        tab_width = self.options.get('tab-width', self.state.document.settings.tab_width)
        source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)

        try:
            exec('\n'.join(self.content))
            text = sys.stdout.getvalue()
            lines = statemachine.string2lines(text, tab_width, convert_whitespace=True)
            self.state_machine.insert_input(lines, source)
            return []
        except Exception:
            return [nodes.error(None, nodes.paragraph(text = "Unable to execute python code at %s:%d:" % (basename(source), self.lineno)), nodes.paragraph(text = str(sys.exc_info()[1])))]
        finally:
            sys.stdout = oldStdout 
开发者ID:hootnot,项目名称:oanda-api-v20,代码行数:18,代码来源:conf.py

示例4: _format_optional_action

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_optional_action(action):
    """Format an optional action."""
    if action.help == argparse.SUPPRESS:
        return

    if action.nargs == 0:
        yield '.. option:: {}'.format(', '.join(action.option_strings))
    else:
        # TODO(stephenfin): At some point, we may wish to provide more
        # information about the options themselves, for example, if nargs is
        # specified
        option_strings = [' '.join(
            [x, action.metavar or '<{}>'.format(action.dest.upper())])
            for x in action.option_strings]
        yield '.. option:: {}'.format(', '.join(option_strings))

    if action.help:
        yield ''
        for line in statemachine.string2lines(
                action.help, tab_width=4, convert_whitespace=True):
            yield _indent(line) 
开发者ID:openstack,项目名称:cliff,代码行数:23,代码来源:sphinxext.py

示例5: run

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def run(self):
        old_stdout, sys.stdout = sys.stdout, StringIO()

        tab_width = self.options.get('tab-width', self.state.document.settings.tab_width)
        source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)

        try:
            exec('\n'.join(self.content))
            text = sys.stdout.getvalue()
            lines = statemachine.string2lines(text, tab_width, convert_whitespace=True)
            self.state_machine.insert_input(lines, source)
            return []
        except Exception:
            warn_text = "Unable to execute python code at %s:%d" % (basename(source), self.lineno)
            warning = self.state_machine.reporter.warning(warn_text)
            return [warning, nodes.error(None, nodes.paragraph(text=warn_text), nodes.paragraph(text=str(sys.exc_info()[1])))]
        finally:
            sys.stdout = old_stdout 
开发者ID:team-ocean,项目名称:veros,代码行数:20,代码来源:conf.py

示例6: _format_description

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_description(ctx):
    """Format the description for a given `click.Command`.

    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    help_string = ctx.command.help or ctx.command.short_help
    if not help_string:
        return

    bar_enabled = False
    for line in statemachine.string2lines(help_string,
                                          tab_width=4,
                                          convert_whitespace=True):
        if line == '\b':
            bar_enabled = True
            continue
        if line == '':
            bar_enabled = False
        line = '| ' + line if bar_enabled else line
        yield line
    yield '' 
开发者ID:click-contrib,项目名称:sphinx-click,代码行数:24,代码来源:ext.py

示例7: _format_subcommand

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_subcommand(command):
    """Format a sub-command of a `click.Command` or `click.Group`."""
    yield '.. object:: {}'.format(command.name)

    # click 7.0 stopped setting short_help by default
    if CLICK_VERSION < (7, 0):
        short_help = command.short_help
    else:
        short_help = command.get_short_help_str()

    if short_help:
        yield ''
        for line in statemachine.string2lines(short_help,
                                              tab_width=4,
                                              convert_whitespace=True):
            yield _indent(line) 
开发者ID:click-contrib,项目名称:sphinx-click,代码行数:18,代码来源:ext.py

示例8: _format_description

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_description(ctx):
    """Format the description for a given `click.Command`.
    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    help_string = ctx.command.help or ctx.command.short_help
    if not help_string:
        return

    bar_enabled = False
    for line in statemachine.string2lines(
            help_string, tab_width=4, convert_whitespace=True):
        if line == '\b':
            bar_enabled = True
            continue
        if line == '':
            bar_enabled = False
        line = '| ' + line if bar_enabled else line
        yield line
    yield '' 
开发者ID:mirnylab,项目名称:cooler,代码行数:22,代码来源:make_cli_rst.py

示例9: run

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def run(self):
        oldStdout, sys.stdout = sys.stdout, StringIO()

        tab_width = self.options.get(
            "tab-width", self.state.document.settings.tab_width
        )
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1
        )

        try:
            exec("\n".join(self.content))
            text = sys.stdout.getvalue()
            lines = statemachine.string2lines(text, tab_width, convert_whitespace=True)
            self.state_machine.insert_input(lines, source)
            return []
        except Exception:
            return [
                nodes.error(
                    None,
                    nodes.paragraph(
                        text="Unable to execute python "
                        "code at {file}:{line}".format(
                            file=os.path.basename(source), line=self.lineno
                        )
                    ),
                    nodes.paragraph(text=str(sys.exc_info()[1])),
                )
            ]
        finally:
            sys.stdout = oldStdout 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:33,代码来源:conf.py

示例10: _format_description

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_description(parser):
    """Get parser description.

    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    for line in statemachine.string2lines(
            parser.description, tab_width=4, convert_whitespace=True):
        yield line 
开发者ID:openstack,项目名称:cliff,代码行数:11,代码来源:sphinxext.py

示例11: _format_epilog

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_epilog(parser):
    """Get parser epilog.

    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    for line in statemachine.string2lines(
            parser.epilog, tab_width=4, convert_whitespace=True):
        yield line 
开发者ID:openstack,项目名称:cliff,代码行数:11,代码来源:sphinxext.py

示例12: _format_positional_action

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_positional_action(action):
    """Format a positional action."""
    if action.help == argparse.SUPPRESS:
        return

    # NOTE(stephenfin): We strip all types of brackets from 'metavar' because
    # the 'option' directive dictates that only option argument names should be
    # surrounded by angle brackets
    yield '.. option:: {}'.format(
        (action.metavar or action.dest).strip('<>[]() '))
    if action.help:
        yield ''
        for line in statemachine.string2lines(
                action.help, tab_width=4, convert_whitespace=True):
            yield _indent(line) 
开发者ID:openstack,项目名称:cliff,代码行数:17,代码来源:sphinxext.py

示例13: _format_option

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_option(opt):
    """Format the output for a `click.Option`."""
    opt = _get_help_record(opt)

    yield '.. option:: {}'.format(opt[0])
    if opt[1]:
        yield ''
        for line in statemachine.string2lines(opt[1],
                                              tab_width=4,
                                              convert_whitespace=True):
            yield _indent(line) 
开发者ID:click-contrib,项目名称:sphinx-click,代码行数:13,代码来源:ext.py

示例14: _format_option

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_option(opt):
    """Format the output for a `click.Option`."""
    opt = _get_help_record(opt)

    yield '.. option:: {}'.format(opt[0])
    if opt[1]:
        yield ''
        for line in statemachine.string2lines(
                opt[1], tab_width=4, convert_whitespace=True):
            yield _indent(line) 
开发者ID:mirnylab,项目名称:cooler,代码行数:12,代码来源:make_cli_rst.py

示例15: _format_subcommand

# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import string2lines [as 别名]
def _format_subcommand(command):
    """Format a sub-command of a `click.Command` or `click.Group`."""
    yield '.. object:: {}'.format(command.name)

    if command.short_help:
        yield ''
        for line in statemachine.string2lines(
                command.short_help, tab_width=4, convert_whitespace=True):
            yield _indent(line) 
开发者ID:mirnylab,项目名称:cooler,代码行数:11,代码来源:make_cli_rst.py


注:本文中的docutils.statemachine.string2lines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。