本文整理匯總了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
示例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
示例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
示例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)
示例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
示例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 ''
示例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)
示例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 ''
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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)