本文整理汇总了Python中docutils.statemachine.StringList方法的典型用法代码示例。如果您正苦于以下问题:Python statemachine.StringList方法的具体用法?Python statemachine.StringList怎么用?Python statemachine.StringList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.statemachine
的用法示例。
在下文中一共展示了statemachine.StringList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_csv_data_into_rows
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def parse_csv_data_into_rows(self, csv_data, dialect, source):
# csv.py doesn't do Unicode; encode temporarily as UTF-8
csv_reader = csv.reader([self.encode_for_csv(line + '\n')
for line in csv_data],
dialect=dialect)
rows = []
max_cols = 0
for row in csv_reader:
row_data = []
for cell in row:
# decode UTF-8 back to Unicode
cell_text = self.decode_from_csv(cell)
cell_data = (0, 0, 0, statemachine.StringList(
cell_text.splitlines(), source=source))
row_data.append(cell_data)
rows.append(row_data)
max_cols = max(max_cols, len(row))
return rows, max_cols
示例2: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
if len(self.content) != 0:
raise ValueError("`autotested` directive does not allow any arguments.")
# Seriously there _HAS_ to be a better way to do this...
# Creating something of length 1 so that I can rage-replace it
self.content = StringList("?")
self.content[0] = textwrap.dedent('''\
This method is tested automatically for every derived type of
:class:`~testing.base.ExhaleTestCase` that is not decorated with
:func:`~testing.decorators.no_run`. The metaclass
:class:`~testing.base.ExhaleTestCaseMetaclass` generates a testing method
``test_common`` that invokes this method.
''')
autotested_node = autotested("\n".join(self.content))
autotested_node += nodes.title(_("Automatically Tested"), _("Automatically Tested"))
self.state.nested_parse(self.content, self.content_offset, autotested_node)
return [autotested_node]
示例3: _container_wrapper
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def _container_wrapper(directive, literal_node, caption):
container_node = nodes.container('', literal_block=True,
classes=['literal-block-wrapper'])
parsed = nodes.Element()
directive.state.nested_parse(StringList([caption], source=''),
directive.content_offset, parsed)
if isinstance(parsed[0], nodes.system_message): # pragma: no cover
# TODO: Figure out if this is really possible and how to produce
# it in a test case.
msg = 'Invalid caption: %s' % parsed[0].astext()
raise ValueError(msg)
assert isinstance(parsed[0], nodes.Element)
caption_node = nodes.caption(parsed[0].rawsource, '',
*parsed[0].children)
caption_node.source = literal_node.source
caption_node.line = literal_node.line
container_node += caption_node
container_node += literal_node
return container_node
示例4: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer")
node_list = []
doc_sections = self.generate_sections(zenpy_client)
output = '.. py:class:: Zenpy%s\n\n' % inspect.signature(zenpy_client.__class__)
output += ' %s' % zenpy_client.__doc__
node = container()
self.state.nested_parse(StringList(output.split('\n')), 0, node)
node_list.append(node)
for doc_section in doc_sections:
node = paragraph()
self.state.nested_parse(StringList(doc_section.split('\n')), 0, node)
node_list.append(node)
return node_list
示例5: __init__
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def __init__(self, env: BuildEnvironment, reporter: Reporter, options: Options,
lineno: int, state: Any = None) -> None:
self.env = env
self.reporter = reporter
self.genopt = options
self.lineno = lineno
self.filename_set = set() # type: Set[str]
self.result = StringList()
if state:
self.state = state
else:
# create fake object for self.state.document.settings.tab_width
warnings.warn('DocumenterBridge requires a state object on instantiation.',
RemovedInSphinx40Warning)
settings = Struct(tab_width=8)
document = Struct(settings=settings)
self.state = Struct(document=document)
示例6: _parse_inline
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def _parse_inline(state, line, info):
source = StringList([line], items=[info])
node = nodes.paragraph()
state.nested_parse(source, 0, node)
par = node[0]
assert isinstance(node, nodes.paragraph)
par = node[0]
assert isinstance(node, nodes.paragraph)
return par.children
示例7: _nested_parse_paragraph
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def _nested_parse_paragraph(self, text):
content = nodes.paragraph()
self.state.nested_parse(StringList(text.split("\n")), 0, content)
return content
示例8: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
ytid = self.arguments[0]
description = [i if i != "" else "<br><br>" for i in self.content]
thumbnail_rst = YOUTUBE_TEMPLATE.format(id=ytid,
title=self.options["title"],
author=self.options["author"],
description=" ".join(description))
thumbnail = StringList(thumbnail_rst.split('\n'))
thumb = nodes.paragraph()
self.state.nested_parse(thumbnail, self.content_offset, thumb)
return [thumb]
示例9: handle_signature
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def handle_signature(self, sig: str, signode: addnodes.desc) -> str:
"""Transform signature into RST nodes"""
signode += addnodes.desc_annotation(self.typename, self.typename + " ")
signode += addnodes.desc_name(sig, sig)
if 'badges' in self.options:
badges = addnodes.desc_annotation()
badges['classes'] += ['badges']
content = StringList([self.options['badges']])
self.state.nested_parse(content, 0, badges)
signode += badges
if 'replaces_section_title' in self.options:
section = self.state.parent
if isinstance(section, nodes.section):
title = section[-1]
if isinstance(title, nodes.title):
section.remove(title)
else:
signode += self.state.document.reporter.warning(
"%s:%s:: must follow section directly to replace section title"
% (self.domain, self.objtype), line = self.lineno
)
else:
signode += self.state.document.reporter.warning(
"%s:%s:: must be in section to replace section title"
% (self.domain, self.objtype), line = self.lineno
)
return sig
示例10: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
if not hasattr(self.env, 'bioconda_lint_checks'):
self.env.bioconda_lint_checks = {str(check): check for check in get_checks()}
# gather data
check_name = self.arguments[0]
if check_name not in self.env.bioconda_lint_checks:
self.error("Duplicate lint description")
check = self.env.bioconda_lint_checks.pop(check_name)
_, lineno = inspect.getsourcelines(check)
lineno += 1
fname = inspect.getfile(check)
doclines = inspect.getdoc(check).splitlines()
docline_src = [(fname, i)
for i in range(lineno, lineno+len(doclines))]
lines = StringList(doclines, items=docline_src)
# create a new section with title
section = nodes.section(ids=[nodes.make_id(check_name)])
title_text = f'":py:class:`{check_name}`"'
title_nodes, messages = self.state.inline_text(title_text, self.lineno)
title = nodes.title(check_name, '', *title_nodes)
section += title
admonition = nodes.admonition()
title_text = doclines[0].rstrip('.')
title_nodes, messages = self.state.inline_text(title_text, lineno)
title = nodes.title(title_text, '', *title_nodes)
admonition += title
admonition += messages
self.state.nested_parse(lines[1:], 0, admonition)
section += admonition
# add remaining content of directive
par = nodes.paragraph()
self.state.nested_parse(self.content, self.content_offset, par)
section += par
return [section]
示例11: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
try:
if 'tooltip' in self.options:
tooltip = self.options['tooltip'][:195]
else:
raise ValueError('tooltip not found')
tags = ""
if 'tags' in self.options:
tags = self.options['tags']
if 'figure' in self.options:
env = self.state.document.settings.env
rel_figname, figname = env.relfn2path(self.options['figure'])
thumbnail = "/" + rel_figname
else:
thumbnail = '/_static/code.png'
if 'description' in self.options:
description = self.options['description']
else:
raise ValueError('description not doc found')
except FileNotFoundError as e:
print(e)
return []
except ValueError as e:
print(e)
raise
return []
thumbnail_rst = GALLERY_TEMPLATE.format(tooltip=tooltip,
thumbnail=thumbnail,
description=description,
tags=tags)
thumbnail = StringList(thumbnail_rst.split('\n'))
thumb = nodes.paragraph()
self.state.nested_parse(thumbnail, self.content_offset, thumb)
return [thumb]
示例12: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
try:
if 'tooltip' in self.options:
tooltip = self.options['tooltip'][:195] + '...'
else:
raise ValueError('tooltip not found')
if 'figure' in self.options:
env = self.state.document.settings.env
rel_figname, figname = env.relfn2path(self.options['figure'])
thumbnail = os.path.join('_static/thumbs/', os.path.basename(figname))
try:
os.makedirs('_static/thumbs')
except FileExistsError:
pass
sphinx_gallery.gen_rst.scale_image(figname, thumbnail, 400, 280)
else:
thumbnail = '_static/img/thumbnails/default.png'
if 'description' in self.options:
description = self.options['description']
else:
raise ValueError('description not doc found')
except FileNotFoundError as e:
print(e)
return []
except ValueError as e:
print(e)
raise
return []
thumbnail_rst = GALLERY_TEMPLATE.format(tooltip=tooltip,
thumbnail=thumbnail,
description=description)
thumbnail = StringList(thumbnail_rst.split('\n'))
thumb = nodes.paragraph()
self.state.nested_parse(thumbnail, self.content_offset, thumb)
return [thumb]
示例13: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
self.assert_has_content()
hidden_until = self.arguments[0]
try:
hidden_until = parse_date(hidden_until)
except:
raise self.error('Unknown date format in the "%s" directive; '
'%s' % (self.name, hidden_until))
force_show = self.state.document.settings.force_show_hidden_until
translation = _get_inginious_translation()
after_deadline = hidden_until <= datetime.now()
if after_deadline or force_show:
output = []
# Add a warning for teachers/tutors/...
if not after_deadline and force_show:
node = nodes.caution()
self.add_name(node)
text = translation.gettext("The feedback below will be hidden to the students until {}.").format(
hidden_until.strftime("%d/%m/%Y %H:%M:%S"))
self.state.nested_parse(StringList(text.split("\n")), 0, node)
output.append(node)
text = '\n'.join(self.content)
node = nodes.compound(text)
self.add_name(node)
self.state.nested_parse(self.content, self.content_offset, node)
output.append(node)
return output
else:
node = nodes.caution()
self.add_name(node)
text = translation.gettext(
"A part of this feedback is hidden until {}. Please come back later and reload the submission to see the full feedback.").format(
hidden_until.strftime("%d/%m/%Y %H:%M:%S"))
self.state.nested_parse(StringList(text.split("\n")), 0, node)
return [node]
示例14: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
try:
code = inspect.cleandoc(
"""
def usermethod():
{}
"""
).format("\n ".join(self.content))
exec(code)
result = locals()["usermethod"]()
if result is None:
raise Exception(
"Return value needed! The body of your `.. exec::` is used as a "
"function call that must return a value."
)
para = nodes.container()
# tab_width = self.options.get('tab-width', self.state.document.settings.tab_width)
lines = statemachine.StringList(result.split("\n"))
self.state.nested_parse(lines, self.content_offset, para)
return [para]
except Exception as e:
docname = self.state.document.settings.env.docname
return [
nodes.error(
None,
nodes.paragraph(
text="Unable to execute python code at {}:{} ... {}".format(
docname, self.lineno, datetime.datetime.now()
)
),
nodes.paragraph(text=str(e)),
nodes.literal_block(text=str(code)),
)
]
示例15: run
# 需要导入模块: from docutils import statemachine [as 别名]
# 或者: from docutils.statemachine import StringList [as 别名]
def run(self):
rst = USAGE_DETAILS_TEMPLATE.format(content="\n".join(self.content))
string_list = StringList(rst.split('\n'))
node = nodes.section()
self.state.nested_parse(string_list, self.content_offset, node)
return [node]