本文整理汇总了Python中sphinx.addnodes.desc_parameter函数的典型用法代码示例。如果您正苦于以下问题:Python desc_parameter函数的具体用法?Python desc_parameter怎么用?Python desc_parameter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了desc_parameter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_column_node
def _get_column_node(m):
if m.group('name'):
node = addnodes.desc_parameter()
if m.group('key'):
node += nodes.Text("#", "#")
key = nodes.strong(m.group('name'), m.group('name'))
key['classes'].append('arg-key')
node += key
if m.group('type'):
node += nodes.Text(" : ", " : ")
value = nodes.inline(m.group('type'), m.group('type'))
value['classes'].append('arg-value') # FIXME: should vbe arg type probably
node += value
if m.group('optional'):
node += nodes.Text("? ", "?") # FIXME: find a better type
if m.group('reference'):
value = nodes.inline(m.group('reference'), m.group('reference'))
value['classes'].append('arg-value') # FIXME: should vbe arg type probably
node += value
return node
else:
return addnodes.desc_parameter(m.group(0), m.group(0))
示例2: render_atom
def render_atom(token, signode, noemph=True):
"add syntax hi-lighting to interesting atoms"
if token.startswith("&") or token.startswith(":"):
signode.append(addnodes.desc_parameter(token, token))
else:
signode.append(addnodes.desc_parameter(token, token))
示例3: _get_param_node
def _get_param_node(m,optional):
if m.group('flag'):
node = addnodes.desc_parameter()
flag = nodes.strong(m.group('flag'), m.group('flag'))
if optional:
flag['classes'].append('arg-flag-optional')
else:
flag['classes'].append('arg-flag')
node += flag
return flag
else:
return addnodes.desc_parameter(m.group(0), m.group(0))
示例4: handle_constructor_signature
def handle_constructor_signature(self, sig, signode):
try:
member = javalang.parse.parse_constructor_signature(sig)
except javalang.parser.JavaSyntaxError:
raise self.error("syntax error in constructor signature")
if not isinstance(member, javalang.tree.ConstructorDeclaration):
raise self.error("expected constructor declaration")
mods = formatter.output_modifiers(member.modifiers).build()
signode += nodes.Text(mods + ' ', mods + ' ')
signode += addnodes.desc_name(member.name, member.name)
paramlist = addnodes.desc_parameterlist()
for parameter in member.parameters:
param = addnodes.desc_parameter('', '', noemph=True)
param += self._build_type_node(parameter.type)
if parameter.varargs:
param += nodes.Text('...', '')
param += nodes.emphasis(' ' + parameter.name, ' ' + parameter.name)
paramlist += param
signode += paramlist
param_reprs = [formatter.output_type(param.type, with_generics=False).build() for param in member.parameters]
return '%s(%s)' % (member.name, ', '.join(param_reprs))
示例5: handle_signature
def handle_signature(self, sig, signode):
m = sig_pattern.match(sig)
if m is None:
raise ValueError()
return_type, method_name, arglist = m.groups()
arguments = []
if arglist:
for arg in arglist.split(","):
m = arg_pattern.match(arg)
if m is None:
raise ValueError()
arguments.append(m.groups())
class_name = self.env.temp_data.get("java:class")
if not class_name:
self.env.warn(
self.env.docname, "Java method description of %s outside of class is not supported" % sig, self.lineno
)
raise ValueError()
if return_type is not None: # will be absent for constructors
self._parse_type(return_type, signode)
signode += nodes.Text(" ", " ")
signode += addnodes.desc_name(method_name, method_name)
signode += addnodes.desc_parameterlist()
for type, name in arguments:
signode[-1] += addnodes.desc_parameter("", "", noemph=True)
self._parse_type(type, signode[-1][-1])
signode[-1][-1] += nodes.Text(" ", " ")
signode[-1][-1] += nodes.emphasis(name, name)
return "%s#%s(%s)" % (class_name, method_name, ", ".join(type for type, name in arguments))
示例6: handle_signature
def handle_signature(self, sig, signode):
cache = _APP_CACHES.get(self.env.app, {})
key = CursorKind.MACRO_DEFINITION, (sig, )
if key in cache:
node, comment, start, end, _ = cache[key]
signode += addnodes.desc_name(node.displayname, node.displayname)
# There is unfortunately no API to get the parameters of a macro,
# so we identify them by looking at the tokens.
tokens = list(node.get_tokens())
if (
tokens[1].kind is TokenKind.PUNCTUATION and
tokens[1].spelling == '('
):
paramlist = addnodes.desc_parameterlist()
for token in tokens[2:]:
if (
token.kind is TokenKind.PUNCTUATION and
token.spelling == ')'
):
break
elif token.kind is TokenKind.IDENTIFIER:
paramlist += addnodes.desc_parameter(token.spelling, token.spelling)
signode += paramlist
self.content = ViewList()
for lineno, line in enumerate(comment.splitlines(), start[0]):
self.content.append(line, '<unknown>', lineno)
return sig
示例7: handle_signature
def handle_signature(self, sig, signode):
method = self.method.upper() + ' '
signode += addnodes.desc_name(method, method)
offset = 0
path = None
for match in http_sig_param_re.finditer(sig):
path = sig[offset:match.start()]
signode += addnodes.desc_name(path, path)
params = addnodes.desc_parameterlist()
typ = match.group('type')
if typ:
typ += ': '
params += addnodes.desc_annotation(typ, typ)
name = match.group('name')
params += addnodes.desc_parameter(name, name)
signode += params
offset = match.end()
if offset < len(sig):
path = sig[offset:len(sig)]
signode += addnodes.desc_name(path, path)
assert path is not None, 'no matches for sig: %s' % sig
fullname = self.method.upper() + ' ' + path
signode['method'] = self.method
signode['path'] = sig
signode['fullname'] = fullname
return (fullname, self.method, sig)
示例8: attach_function
def attach_function(self, node, func):
owner, name = func.name.split_owner()
# Olaf: Never show Class::
owner = None
if owner is not None:
owner = unicode(owner) + '::'
node += addnodes.desc_addname(owner, owner)
# cast operator is special. in this case the return value
# is reversed.
if isinstance(name, CastOpDefExpr):
node += addnodes.desc_name('operator', 'operator')
node += nodes.Text(u' ')
self.attach_type(node, name.typename)
else:
funcname = unicode(name)
node += addnodes.desc_name(funcname, funcname)
paramlist = addnodes.desc_parameterlist()
for arg in func.signature:
param = addnodes.desc_parameter('', '', noemph=True)
if arg.type is not None:
self.attach_type(param, arg.type)
param += nodes.Text(u' ')
param += nodes.emphasis(unicode(arg.name), unicode(arg.name))
if arg.default is not None:
def_ = u'=' + unicode(arg.default)
param += nodes.emphasis(def_, def_)
paramlist += param
node += paramlist
if func.const:
node += addnodes.desc_addname(' const', ' const')
if func.pure_virtual:
node += addnodes.desc_addname(' = 0', ' = 0')
示例9: run
def run(self):
#no good
# node = nodes.paragraph('', 'Hi there!',
# ids=['foo'],
# names = ['foobar']
# )
#works
# node = nodes.section(names=['foobar'])
# self.state.document.note_explicit_target(node)
# node.append(nodes.paragraph('', "foo foo"))
#no good
# node = nodes.admonition(names=['foobar'])
# self.state.document.note_explicit_target(node)
# node.append(nodes.paragraph('', "foo foo"))
# node = nodes.paragraph('', 'foo foo', names=['foobar'])
# self.state.document.note_explicit_target(node)
#This doesn't properly render
desc = addnodes.desc('',
addnodes.desc_signature('',
addnodes.desc_name('', 'namename'),
addnodes.desc_parameterlist('',
addnodes.desc_parameter('', 'def')
),
names=['namename'], fullname="namename", ids=['namename'], module=None, first=False),
desctype="function", domain="py", objtype='objtype')
#no link (because didn't properly render?)
self.state.document.note_explicit_target(desc)
return [desc]
示例10: handle_signature
def handle_signature(self, sig, signode):
"""Transform a C signature into RST nodes."""
# first try the function pointer signature regex, it's more specific
m = c_funcptr_sig_re.match(sig)
if m is None:
m = c_sig_re.match(sig)
if m is None:
raise ValueError('no match')
rettype, name, arglist, const = m.groups()
signode += addnodes.desc_type('', '')
self._parse_type(signode[-1], rettype)
try:
classname, funcname = name.split('::', 1)
classname += '::'
signode += addnodes.desc_addname(classname, classname)
signode += addnodes.desc_name(funcname, funcname)
# name (the full name) is still both parts
except ValueError:
signode += addnodes.desc_name(name, name)
# clean up parentheses from canonical name
m = c_funcptr_name_re.match(name)
if m:
name = m.group(1)
typename = self.env.temp_data.get('c:type')
if self.name == 'c:member' and typename:
fullname = typename + '.' + name
else:
fullname = name
if not arglist:
if self.objtype == 'function':
# for functions, add an empty parameter list
signode += addnodes.desc_parameterlist()
if const:
signode += addnodes.desc_addname(const, const)
return fullname
paramlist = addnodes.desc_parameterlist()
arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup
# this messes up function pointer types, but not too badly ;)
args = arglist.split(',')
for arg in args:
arg = arg.strip()
param = addnodes.desc_parameter('', '', noemph=True)
try:
ctype, argname = arg.rsplit(' ', 1)
except ValueError:
# no argument name given, only the type
self._parse_type(param, arg)
else:
self._parse_type(param, ctype)
# separate by non-breaking space in the output
param += nodes.emphasis(' '+argname, u'\xa0'+argname)
paramlist += param
signode += paramlist
if const:
signode += addnodes.desc_addname(const, const)
return fullname
示例11: add_sig_args
def add_sig_args(self, signode, arglist, const):
if not arglist:
if self.sphinx_directive.objtype == 'function':
# for functions, add an empty parameter list
signode += addnodes.desc_parameterlist()
if const:
signode += addnodes.desc_addname(const, const)
return
paramlist = addnodes.desc_parameterlist()
arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup
# this messes up function pointer types, but not too badly ;)
args = arglist.split(',')
for arg in args:
arg = arg.strip()
param = addnodes.desc_parameter('', '', noemph=True)
try:
ctype, argname = arg.rsplit(' ', 1)
except ValueError:
# no argument name given, only the type
self.add_cross_ref(param, arg)
else:
self.add_cross_ref(param, ctype)
# separate by non-breaking space in the output
param += nodes.emphasis(' '+argname, u'\xa0'+argname)
paramlist += param
signode += paramlist
if const:
signode += addnodes.desc_addname(const, const)
示例12: handle_signature
def handle_signature(self, sig, signode):
method = self.method.upper() + " "
signode += addnodes.desc_name(method, method)
offset = 0
path = None
for match in http_sig_param_re.finditer(sig):
path = sig[offset : match.start()]
signode += addnodes.desc_name(path, path)
params = addnodes.desc_parameterlist()
typ = match.group("type")
if typ:
typ += ": "
params += addnodes.desc_annotation(typ, typ)
name = match.group("name")
params += addnodes.desc_parameter(name, name)
signode += params
offset = match.end()
if offset < len(sig):
path = sig[offset : len(sig)]
signode += addnodes.desc_name(path, path)
if path is None:
assert False, "no matches for sig: %s" % sig
fullname = self.method.upper() + " " + path
signode["method"] = self.method
signode["path"] = sig
signode["fullname"] = fullname
return (fullname, self.method, sig)
示例13: _pseudo_parse_arglist
def _pseudo_parse_arglist(signode, arglist):
# type: (addnodes.desc_signature, str) -> None
""""Parse" a list of arguments separated by commas.
Arguments can have "optional" annotations given by enclosing them in
brackets. Currently, this will split at any comma, even if it's inside a
string literal (e.g. default argument value).
"""
paramlist = addnodes.desc_parameterlist()
stack = [paramlist] # type: List[nodes.Element]
try:
for argument in arglist.split(','):
argument = argument.strip()
ends_open = ends_close = 0
while argument.startswith('['):
stack.append(addnodes.desc_optional())
stack[-2] += stack[-1]
argument = argument[1:].strip()
while argument.startswith(']'):
stack.pop()
argument = argument[1:].strip()
while argument.endswith(']') and not argument.endswith('[]'):
ends_close += 1
argument = argument[:-1].strip()
while argument.endswith('['):
ends_open += 1
argument = argument[:-1].strip()
if argument:
stack[-1] += addnodes.desc_parameter(argument, argument)
while ends_open:
stack.append(addnodes.desc_optional())
stack[-2] += stack[-1]
ends_open -= 1
while ends_close:
stack.pop()
ends_close -= 1
if len(stack) != 1:
raise IndexError
except IndexError:
# if there are too few or too many elements on the stack, just give up
# and treat the whole argument list as one argument, discarding the
# already partially populated paramlist node
paramlist = addnodes.desc_parameterlist()
paramlist += addnodes.desc_parameter(arglist, arglist)
signode += paramlist
else:
signode += paramlist
示例14: handle_signature
def handle_signature(self, sig, signode):
"""
Transform a CFEngine 3 signature into RST nodes.
"""
sig_d = {}
m = cf3_sig_re.match(sig)
try:
sig_d['type'], sig_d['ns'], sig_d['id'], sig_d['args'] = m.groups()
except AttributeError:
raise ValueError
sig_d['ns'] = sig_d['ns'] or self.options.get(
'namespace', self.env.temp_data.get('cf3:namespace')
)
fullname = []
fn_app = fullname.append
fn_app(self.objtype + _FN_SEP)
if self.objtype in ('body', 'bundle'):
tnode = addnodes.desc_type('', '')
tnode += nodes.Text(self.objtype + _SP, self.objtype)
try:
sig_d['type'] = sig_d['type'].strip()
tnode += nodes.Text(sig_d['type'] + _SP, sig_d['type'])
fn_app(sig_d['type'] + _FN_SEP)
except AttributeError:
self.state_machine.reporter.warning(
'invalid %s definition: %s' % (self.objtype, sig),
line=self.lineno
)
signode += tnode
if sig_d['ns'] and sig_d['ns'] != 'default' \
and self.env.config.add_module_names:
signode += addnodes.desc_addname(
sig_d['ns'], sig_d['ns'] + _NS_SEP
)
signode += addnodes.desc_name(sig_d['id'], sig_d['id'])
fn_app(sig_d['id'])
signode['namespace'] = sig_d['ns']
signode['fullname'] = ''.join(fullname)
if self.objtype == 'class':
signode += addnodes.desc_name(_CL_MRK, _CL_MRK)
return ''.join(fullname), sig_d['ns']
if not sig_d['args'] and self.objtype == 'function':
signode += addnodes.desc_parameterlist()
return ''.join(fullname), sig_d['ns']
if sig_d['args']:
paramlist = addnodes.desc_parameterlist()
for arg in sig_d['args'].split(','):
arg = arg.strip()
paramlist += addnodes.desc_parameter(arg, arg)
signode += paramlist
return ''.join(fullname), sig_d['ns']
示例15: make_desc_parameters
def make_desc_parameters(params):
for p in params:
if '.' in p.name:
continue
node = addnodes.desc_parameter(p.name, p.name)
if p.optional:
node = addnodes.desc_optional('', '', node)
yield node