當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。