Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertEqual(' and ', paragraph[2])
self.assertIsInstance(paragraph[3], nodes.literal)
self.assertEqual('code', paragraph[3].astext())
self.assertIsInstance(paragraph[4], nodes.Text)
self.assertEqual(' world', paragraph[4])
items = doc[0][2]
self.assertIsInstance(items, nodes.bullet_list)
self.assertEqual(7, len(items))
# backticks: `e=f()` or ``e=f("`")``
backticks = items[0][0]
self.assertIsInstance(backticks, nodes.paragraph)
self.assertEqual(4, len(backticks))
self.assertEqual('backticks: ', backticks[0])
self.assertIsInstance(backticks[1], nodes.literal)
self.assertEqual('e=f()', backticks[1][0])
self.assertIsInstance(backticks[2], nodes.Text)
self.assertEqual(' or ', backticks[2])
self.assertIsInstance(backticks[3], nodes.literal)
self.assertEqual('e=f("`")', backticks[3][0])
# escapes: \*hello world*
escapes = items[1][0]
self.assertIsInstance(escapes, nodes.paragraph)
self.assertEqual(1, len(escapes))
self.assertIsInstance(escapes[0], nodes.Text)
self.assertEqual('escapes: *hello world*', escapes[0])
# strong-em: ***strongem*** or ***em*strong**
strongem = items[2][0]
self.assertIsInstance(strongem, nodes.paragraph)
def _create_cli_paragraph(self, feature):
"""Create a paragraph which represents the CLI commands of the feature.
The paragraph will have a bullet list of CLI commands.
"""
para = nodes.paragraph()
para.append(nodes.strong(text="CLI commands:"))
commands = nodes.bullet_list()
for c in feature.cli.split(";"):
cli_command = nodes.list_item()
cli_command += nodes.literal(text=c, classes=["sp_cli"])
commands.append(cli_command)
para.append(commands)
return para
# Dummy-rendered roles
#------------------------------------------------------------------------------
# XXX: some of these should be reference-generating
register_generic_role('envvar', nodes.literal)
register_generic_role('token', nodes.literal)
register_generic_role('keyword', nodes.strong)
register_generic_role('option', nodes.literal)
register_generic_role('term', nodes.emphasis)
register_generic_role('command', nodes.literal)
register_generic_role('dfn', nodes.emphasis)
register_generic_role('file', nodes.literal)
register_generic_role('guilabel', nodes.emphasis)
register_generic_role('kbd', nodes.literal)
register_generic_role('mailheader', nodes.literal)
register_generic_role('makevar', nodes.literal)
register_generic_role('manpage', nodes.emphasis)
register_generic_role('menuselection', nodes.emphasis)
register_generic_role('mimetype', nodes.emphasis)
register_generic_role('newsgroup', nodes.emphasis)
register_generic_role('program', nodes.emphasis)
register_generic_role('regexp', nodes.literal)
register_generic_role('samp', nodes.literal)
#------------------------------------------------------------------------------
# Reference-generating (+ alt-text)
#------------------------------------------------------------------------------
# XXX: :ref: does not work properly
def ref_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
def apply(self):
config = self.document.settings.env.config
github_project = config.github_project
issue_pattern = config.github_issue_pattern
if isinstance(issue_pattern, str_t):
issue_pattern = re.compile(issue_pattern)
for node in self.document.traverse(nodes.Text):
parent = node.parent
if isinstance(parent, (nodes.literal, nodes.FixedTextElement)):
continue
text = text_t(node)
new_nodes = []
last_issue_ref_end = 0
for match in issue_pattern.finditer(text):
head = text[last_issue_ref_end:match.start()]
if head:
new_nodes.append(nodes.Text(head))
last_issue_ref_end = match.end()
issuetext = match.group(0)
issue_id = match.group(1)
refnode = pending_xref()
refnode['reftarget'] = issue_id
refnode['reftype'] = 'issue'
refnode['github_project'] = github_project
reftitle = issuetext
for k, v in tendrils:
entry = nodes.list_item()
lst += entry
para = nodes.paragraph()
entry += para
d[k] = dict(doc=v.doc,
type_name = v.type_name,
required = v.required)
if v.has_default:
try:
default = str(v.val)
except TypeError, e:
default = '[not visible from python]'
para += [nodes.strong(k, k), nodes.literal('', ' '),
nodes.emphasis('', ' type: '), nodes.literal('', v.type_name + " ")]
para += nodes.literal('', ' ')
if isparam:
if not v.required:
para += nodes.emphasis('', ' not ')
para += nodes.emphasis('', 'required')
para += nodes.literal('', ' ')
if v.has_default:
para += [nodes.emphasis('', " default: "), nodes.literal('', default)]
else:
para += nodes.emphasis('', ' no default value')
try:
if is_bp_enum(v.val):
valpara = nodes.paragraph()
valpara += nodes.emphasis('', 'Legal Values: ')
for thevalue, thename in v.val.values.iteritems():
def config_field_default(default):
s = pformat(default)
if '\n' in s:
return literal_block(text=s)
else:
return literal(text=s)
rows = []
for attr in el.xpath("xs:attribute[@name]", namespaces=NSMAP):
name = attr.get("name")
if self.ns_name:
fqname = "%s:%s" % (self.ns_name, name)
else:
fqname = name
if (self.options['onlyattrs'] and
name not in self.options['onlyattrs'] and
fqname not in self.options['onlyattrs']):
continue
tag = attr.tag[len(XS_NS):]
row = [build_paragraph(self.target_node(tag, self.ns_name, context,
name),
nodes.literal(fqname, fqname))]
row.append(self.get_doc(attr))
if attr.get("type") is not None:
row.append(build_paragraph(
self.get_values_from_type(entity=attr)))
else:
try:
atype = attr.xpath("xs:simpleType", namespaces=NSMAP)[0]
row.append(self.get_values_from_simpletype(atype))
except IndexError:
# todo: warn about no type found
pass
reqd = 0
if (name in self.options['requiredattrs'] or
attr.get("use", "optional") == "required"):
row.append("Yes")
reqd = 1
def prefixed_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
prefix, baseuri = prefixed_roles[name]
uri = baseuri + text
display = utils.unescape(text)
node = nodes.literal(prefix, prefix)
ref = nodes.reference(rawtext, display, refuri=uri, **options)
node += ref # keep it in the 'literal' background
return [node], []
item.append(self._create_cli_paragraph(feature))
para_divers = nodes.paragraph()
para_divers.append(nodes.strong(text="drivers:"))
# A sub-list giving details of each hypervisor target
impls = nodes.bullet_list()
for key in feature.implementations:
target = matrix.targets[key]
impl = feature.implementations[key]
subitem = nodes.list_item()
id = re.sub("[^a-zA-Z0-9_]", "_",
feature.key + "_" + key)
subitem += [
nodes.strong(text=target.title + ": "),
nodes.literal(text=impl.status,
classes=["fm_impl_" + impl.status],
ids=[id]),
]
if impl.release:
release_letter = impl.release.upper()
release_text = \
' (updated in "%s" release)' % release_letter
subitem.append(nodes.inline(text=release_text))
if impl.notes is not None:
subitem.append(self._create_notes_paragraph(impl.notes))
impls.append(subitem)
para_divers.append(impls)
item.append(para_divers)
details.append(item)
def sql_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
text = utils.unescape(text)
options['classes'] = ['sql']
return [nodes.literal(rawtext, text, **options)], []