本文整理汇总了Python中sphinx.addnodes.desc_returns函数的典型用法代码示例。如果您正苦于以下问题:Python desc_returns函数的具体用法?Python desc_returns怎么用?Python desc_returns使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了desc_returns函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_signature
def handle_signature(self, sig, signode):
"""Transform a Python signature into RST nodes.
Return (fully qualified name of the thing, classname if any).
If inside a class, the current class name is handled intelligently:
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present
"""
name_prefix = None
name = sig
arglist = None
retann = None
# determine module and class name (if applicable), as well as full name
modname = self.options.get(
'module', self.env.temp_data.get('py:module'))
classname = self.env.temp_data.get('py:class')
fullname = name
signode['module'] = modname
signode['class'] = classname
signode['fullname'] = fullname
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if name_prefix:
signode += addnodes.desc_addname(name_prefix, name_prefix)
anno = self.options.get('annotation')
signode += addnodes.desc_name(name, name)
if not arglist:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
if anno:
signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
return fullname, name_prefix
_pseudo_parse_arglist(signode, arglist)
if retann:
signode += addnodes.desc_returns(retann, retann)
if anno:
signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
return fullname, name_prefix
示例2: _handle_function_signature
def _handle_function_signature(self, sig, signode):
m = ada_func_sig_re.match(sig)
if m is None:
print "m did not match the function"
raise ValueError
modname, name, dummy, arglist, returntype, abstract = m.groups()
print "DEBUG: modname %s name %s arglist %s" % (modname, name, arglist)
fullname = self._resolve_module_name(signode, modname, name)
print "DEBUG: fullname %s" % fullname
if not arglist:
if self.needs_arglist():
# for functions and procedures, add an empty parameter list
new_node = addnodes.desc_parameterlist()
new_node.child_text_separator = '; '
signode += new_node
if returntype:
signode += addnodes.desc_returns(returntype, returntype)
return fullname
signode += nodes.Text(' ')
new_node = addnodes.desc_parameterlist()
new_node.child_text_separator = '; '
signode += new_node
stack = [signode[-1]]
counters = [0, 0]
for token in string.split(arglist, ';'):
pieces = string.split(token, ':')
name = pieces[0].strip()
stack[-1] += addnodes.desc_parameter(name, name + " : " + pieces[1].strip())
if len(stack) == 1:
counters[0] += 1
else:
counters[1] += 1
if len(stack) != 1:
raise ValueError
if not counters[1]:
fullname = '%s/%d' % (fullname, counters[0])
else:
fullname = '%s/%d..%d' % (fullname, counters[0], sum(counters))
if returntype:
signode += addnodes.desc_returns(returntype,returntype)
return fullname
示例3: _handle_function_signature
def _handle_function_signature(self, sig, signode):
m = erl_func_sig_re.match(sig)
if m is None:
raise ValueError
modname, name, arglist, retann = m.groups()
fullname = self._resolve_module_name(signode, modname, name)
if not arglist:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
if self.objtype == 'function':
return fullname + '/0'
return fullname
signode += addnodes.desc_parameterlist()
stack = [signode[-1]]
counters = [0, 0]
for token in erl_paramlist_re.split(arglist):
if token == '[':
opt = addnodes.desc_optional()
stack[-1] += opt
stack.append(opt)
elif token == ']':
try:
stack.pop()
except IndexError:
raise ValueError
elif not token or token == ',' or token.isspace():
pass
else:
token = token.strip()
stack[-1] += addnodes.desc_parameter(token, token)
if len(stack) == 1:
counters[0] += 1
else:
counters[1] += 1
if len(stack) != 1:
raise ValueError
if not counters[1]:
fullname = '%s/%d' % (fullname, counters[0])
else:
fullname = '%s/%d..%d' % (fullname, counters[0], sum(counters))
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname
示例4: handle_signature
def handle_signature(self, sig, signode):
sdkname = self.options.get('sdk', self.env.ref_context.get('qbs:sdk'))
pkgname = self.options.get('package', self.env.ref_context.get('qbs:package'))
modname = self.env.ref_context.get('qbs:module', None)
itemname = self.env.ref_context.get('qbs:item', None)
type, name, value = self.parse(sig)
signode['module'] = modname
signode['package'] = pkgname
signode['item'] = itemname
if self.objtype == 'property':
fullname = self.get_signature_name(objname=(modname or itemname), name=name)
else:
fullname = name
signode['sdk'] = sdkname
signode['fullname'] = fullname
sigprefix = self.get_signature_prefix()
if sigprefix:
signode += addnodes.desc_annotation(sigprefix, sigprefix)
if type:
signode += addnodes.desc_addname(type, type)
if name:
signode += addnodes.desc_name(name, name)
if value:
signode += addnodes.desc_returns(value, value)
return fullname
示例5: make_signature
def make_signature(self):
ret = super(FunctionDocumenter, self).make_signature()
with addto(ret, addnodes.desc_parameterlist()) as params:
params += make_desc_parameters(self.item.params)
retval = self.item.return_val
if retval.type or retval.doc:
ret.append(addnodes.desc_returns(retval.type or '*', retval.type or '*'))
return ret
示例6: build_signode
def build_signode(self, signode):
if self.type == 'unary':
signode += addnodes.desc_name(self.name, self.name)
context = self.context + self.contextsep
signode += addnodes.desc_addname(context, context)
if self.retann:
signode += addnodes.desc_returns(self.retann, self.retann)
elif self.type == 'binary':
context = self.context + self.contextsep
name = " %s " % (self.name)
signode += addnodes.desc_addname(context, context)
signode += addnodes.desc_name(name, name)
signode += addnodes.desc_addname(context, context)
if self.retann:
signode += addnodes.desc_returns(self.retann, self.retann)
elif self.type == 'index' or self.type == 'newindex':
context = self.context + self.contextsep
signode += addnodes.desc_addname(context, context)
self.build_parameters(signode)
if self.retann:
if self.type == 'newindex':
retann = " = %s" % (self.retann)
signode += addnodes.desc_type(retann, retann)
else:
signode += addnodes.desc_returns(self.retann, self.retann)
elif self.type == 'convert':
context = self.context + self.contextsep
signode += addnodes.desc_name(self.name, self.name)
paramlist = _desc_parameterlist('(', ')')
paramlist.append(addnodes.desc_addname(context, context))
signode.append(paramlist)
if self.retann:
signode += addnodes.desc_returns(self.retann, self.retann)
示例7: _handle_function_signature
def _handle_function_signature(self, sig, signode):
m = pure_func_sig_re.match(sig)
if m is None:
raise ValueError
fixity, namesp, name, tag, arglist, retsym, retann = m.groups()
fullname = self._resolve_namespace(signode, namesp, name)
if tag:
fullname += "/%s" % tag
self.add_signature_prefix(signode)
if fixity:
signode['fixity'] = fixity
# Sphinx' default format for the parameter list isn't very useful with
# Pure's curried function applications, so we use freeform text for
# the arguments instead. We also have to take care of different
# fixities here.
if fixity=='postfix':
if arglist:
arglist += " "
signode += desc_args(arglist, arglist)
self._add_desc_name(signode, name)
elif fixity=='infix':
arglist = pure_paramlist_re.split(arglist)
left = ''.join(arglist[:1])
right = ''.join(arglist[2:])
if left:
left += " "
signode += desc_args(left, left)
self._add_desc_name(signode, name)
if right:
right = " "+right
signode += desc_args(right, right)
elif fixity=='outfix' and arglist:
arglist = pure_paramlist_re.split(arglist)
name2 = arglist[0]
signode['other'] = name2
arglist = ''.join(arglist[2:])
self._add_desc_name(signode, name)
if arglist:
arglist = " "+arglist+" "
signode += desc_args(arglist, arglist)
self._add_desc_name(signode, name2)
else:
self._add_desc_name(signode, name)
if arglist:
arglist = " "+arglist
signode += desc_args(arglist, arglist)
if retann:
if retsym=="->":
signode += addnodes.desc_returns(retann, retann)
else:
retann = " %s %s" % (retsym, retann)
signode += desc_args(retann, retann)
return fullname
示例8: handle_signature
def handle_signature(self, sig, signode):
"""Transform a Lasso signature into RST nodes.
"""
sig = sig.strip().replace(' ', ' ').replace(' ::', '::').replace(':: ', '::')
if '(' in sig:
if ')::' in sig:
sig, returntype = sig.rsplit('::', 1)
else:
returntype = None
prefix, arglist = sig.split('(', 1)
prefix = prefix.strip()
arglist = arglist[:-1].strip().replace(' =', '=').replace('= ', '=')
else:
if '::' in sig:
sig, returntype = sig.rsplit('::', 1)
else:
returntype = None
prefix = sig
arglist = None
if '->' in prefix:
objectprefix, name = prefix.rsplit('->', 1)
objectprefix += '->'
else:
objectprefix = None
name = prefix
objectname = self.env.ref_context.get('ls:object')
if objectprefix:
fullname = objectprefix + name
elif objectname:
fullname = objectname + '->' + name
else:
objectname = ''
fullname = name
signode['object'] = objectname
signode['fullname'] = fullname
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if objectprefix:
signode += addnodes.desc_addname(objectprefix, objectprefix)
signode += addnodes.desc_name(name, name)
if self.needs_arglist():
if arglist:
_pseudo_parse_arglist(signode, arglist)
else:
signode += addnodes.desc_parameterlist()
if returntype:
signode += addnodes.desc_returns(returntype, returntype)
return fullname, objectprefix
示例9: handle_signature
def handle_signature(self, sig, signode):
m = plsql_sig_re.match(sig)
if m is None:
raise ValueError
name_prefix, name, arglist, retann = m.groups()
if not name_prefix:
name_prefix = ''
if self.env.temp_data.get('plsql:in_package'):
name_prefix = self.env.temp_data['plsql:current_package'] + '.'
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if not self.env.temp_data.get('plsql:in_package'):
signode += addnodes.desc_annotation(name_prefix, name_prefix)
fullname = ''
if name_prefix:
fullname += name_prefix
fullname += name
signode += addnodes.desc_name(name, name)
if arglist:
signode += addnodes.desc_parameterlist()
stack = [signode[-1]]
for token in arglist.split(','):
if not token or token == ',' or token.isspace():
pass
else:
token = token.strip()
stack[-1] += addnodes.desc_parameter(token, token)
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname
示例10: format_response_class
def format_response_class(self, response_class_name):
ret = n.container()
ret += addnodes.desc_returns(text=response_class_name)
model = self.models.get(response_class_name)
props = addnodes.desc_parameterlist()
for key, property in model["properties"].items():
pc = n.container()
if property["required"]:
pc += addnodes.desc_parameter(key, key)
else:
pc += addnodes.desc_optional(key, key)
pc += n.strong(text=" type: %s " % property["type"])
allowableValues = property.get("allowableValues")
if allowableValues:
allowableValues.pop("valueType", None)
pc += n.subscript(text=" %s" % allowableValues)
props += pc
ret += props
return ret
示例11: _handle_proc_signature
def _handle_proc_signature(self, sig, signode, m):
"Transform a Nim proc node into RST nodes."
name, arglist, rettype, pragmas = m.groups()
signode += addnodes.desc_type('proc', 'proc')
signode += addnodes.desc_name(name, name)
if arglist is None:
signode += addnodes.desc_parameterlist()
else:
arguments = nim_arg_sig_re.match(arglist).groups()[0]
signode += addnodes.desc_parameterlist(arguments, arguments)
if rettype is not None:
retnode = addnodes.desc_returns()
self._parse_type(retnode, nim_rettype_sig_re.match(rettype).groups()[0])
signode += retnode
if pragmas:
signode += addnodes.desc_addname(pragmas, pragmas)
return name
示例12: handle_signature
def handle_signature(self, sig, signode):
"""
Transform a PHP signature into RST nodes.
Returns (fully qualified name of the thing, classname if any).
If inside a class, the current class name is handled intelligently:
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present
"""
m = php_sig_re.match(sig)
if m is None:
raise ValueError
name_prefix, name, arglist, retann = m.groups()
if not name_prefix:
name_prefix = ""
# determine module and class name (if applicable), as well as full name
modname = self.options.get(
'namespace', self.env.temp_data.get('php:namespace'))
classname = self.env.temp_data.get('php:class')
separator = separators[self.objtype]
if self.objtype == 'global' or self.objtype == 'function':
add_module = False
modname = None
classname = None
fullname = name
else:
add_module = True
# name_prefix and a non-static method, means the classname was
# repeated. Trim off the <class>::
if name_prefix and self.objtype != 'staticmethod':
if name_prefix.startswith(classname):
name_prefix = name_prefix[len(classname):].rstrip('::')
classname = classname.rstrip('::')
fullname = name_prefix + classname + separator + name
elif name_prefix:
classname = classname.rstrip('::')
fullname = name_prefix + name
# Currently in a class, but not creating another class,
elif classname and not self.objtype in ['class', 'exception', 'interface', 'trait']:
if not self.env.temp_data['php:in_class']:
name_prefix = classname + separator
fullname = classname + separator + name
else:
classname = ''
fullname = name
signode['namespace'] = modname
signode['class'] = self.class_name = classname
signode['fullname'] = fullname
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if name_prefix:
if modname and not self.env.temp_data['php:in_class']:
name_prefix = modname + NS + name_prefix
signode += addnodes.desc_addname(name_prefix, name_prefix)
elif add_module and self.env.config.add_module_names:
if self.objtype == 'global':
nodetext = ''
signode += addnodes.desc_addname(nodetext, nodetext)
else:
modname = self.options.get(
'namespace', self.env.temp_data.get('php:namespace'))
if modname and not self.env.temp_data.get('php:in_class', False):
nodetext = modname + NS
signode += addnodes.desc_addname(nodetext, nodetext)
signode += addnodes.desc_name(name, name)
if not arglist:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname, name_prefix
signode += addnodes.desc_parameterlist()
stack = [signode[-1]]
for token in php_paramlist_re.split(arglist):
if token == '[':
opt = addnodes.desc_optional()
stack[-1] += opt
stack.append(opt)
elif token == ']':
try:
stack.pop()
except IndexError:
#.........这里部分代码省略.........
示例13: handle_signature
def handle_signature(self, sig, signode):
"""
Transform a TCP/IP signature into RST nodes.
Returns (fully qualified name of the thing, classname if any).
If inside a class, the current class name is handled intelligently:
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present
"""
m = tcpip_sig_re.match(sig)
if m is None:
print 'FAILED', sig
raise ValueError
name_prefix, name, arglist, retann = m.groups()
# determine module and class name (if applicable), as well as full name
modname = self.options.get(
'module', self.env.temp_data.get('tcpip:module'))
classname = self.env.temp_data.get('tcpip:class')
if classname:
add_module = False
if name_prefix and name_prefix.startswith(classname):
fullname = name_prefix + name
# class name is given again in the signature
name_prefix = name_prefix[len(classname):].lstrip('.')
elif name_prefix:
# class name is given in the signature, but different
# (shouldn't happen)
fullname = classname + '.' + name_prefix + name
else:
# class name is not given in the signature
fullname = classname + '.' + name
else:
add_module = True
if name_prefix:
classname = name_prefix.rstrip('.')
fullname = name_prefix + name
else:
classname = ''
fullname = name
signode['module'] = modname
signode['class'] = classname
signode['fullname'] = fullname
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if name_prefix:
signode += addnodes.desc_addname(name_prefix, name_prefix)
# exceptions are a special case, since they are documented in the
# 'exceptions' module.
elif add_module and self.env.config.add_module_names:
modname = self.options.get(
'module', self.env.temp_data.get('tcpip:module'))
if modname and modname != 'exceptions':
nodetext = modname + '.'
signode += addnodes.desc_addname(nodetext, nodetext)
signode += addnodes.desc_name(name, name)
if not arglist:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname, name_prefix
signode += addnodes.desc_parameterlist()
stack = [signode[-1]]
for token in tcpip_paramlist_re.split(arglist):
if token == '[':
opt = addnodes.desc_optional()
stack[-1] += opt
stack.append(opt)
elif token == ']':
try:
stack.pop()
except IndexError:
raise ValueError
elif not token or token == ',' or token.isspace():
pass
else:
token = token.strip()
stack[-1] += addnodes.desc_parameter(token, token)
if len(stack) != 1:
raise ValueError
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname, name_prefix
示例14: _handle_signature
def _handle_signature(self, cid, lineno, sig, signode):
# type: (str, addnodes.desc_signature) -> Tuple[str, str]
"""Transform a Python signature into RST nodes.
Return (fully qualified name of the thing, classname if any).
If inside a class, the current class name is handled intelligently:
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present
This is the xml string result of signode, whitespace is not
equivalent for readability.
<desc_signature
class=""
first="False"
fullname="com.google.fonts/check/all_glyphs_have_codepoints"
module="fontbakery.profiles.cmap"
>
<desc_annotation
xml:space="preserve">FontBakeryCheck </desc_annotation>
<desc_addname
xml:space="preserve">fontbakery.profiles.cmap.</desc_addname>
<desc_name
xml:space="preserve">com_google_fonts_check_all_glyphs_have_codepoints</desc_name>
<desc_parameterlist
xml:space="preserve">
<desc_parameter xml:space="preserve">ttFont</desc_parameter>
</desc_parameterlist>
</desc_signature>
"""
m = py_sig_re.match(sig)
if m is None:
# this is the immediate fail!!!
raise ValueError
prefix, name, arglist, retann = m.groups()
# print('prefix, name, arglist, retann =', prefix, name, arglist, retann)
# > prefix, name, arglist, retann = None com_google_fonts_check_all_glyphs_have_codepoints ttFont None
# determine module and class name (if applicable), as well as full name
modname = self.options.get('module', self.env.ref_context.get('py:module'))
classname = self.env.ref_context.get('py:class')
if classname:
add_module = False
if prefix and (prefix == classname or
prefix.startswith(classname + ".")):
fullname = prefix + name
# class name is given again in the signature
prefix = prefix[len(classname):].lstrip('.')
elif prefix:
# class name is given in the signature, but different
# (shouldn't happen)
fullname = classname + '.' + prefix + name
else:
# class name is not given in the signature
fullname = classname + '.' + name
else:
add_module = True
if prefix:
classname = prefix.rstrip('.')
fullname = prefix + name
else:
classname = ''
fullname = name
signode['module'] = modname
signode['class'] = classname
signode['fullname'] = fullname
signode.attributes['lineno'] = lineno
#sig_prefix = self.get_signature_prefix(sig)
#if sig_prefix:
# signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if prefix:
signode += addnodes.desc_addname(prefix, prefix)
elif add_module and self.env.config.add_module_names:
if modname and modname != 'exceptions':
# exceptions are a special case, since they are documented in the
# 'exceptions' module.
#nodetext = modname + ' ID: '
#signode += addnodes.desc_addname(nodetext, nodetext)
pass
signode += addnodes.desc_name(name, cid)
if arglist:
_pseudo_parse_arglist(signode, arglist)
else:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
#.........这里部分代码省略.........
示例15: handle_signature
def handle_signature(self, sig, signode):
s = sig.split(' ')
if True:
name_prefix = None
name = None
paramlist = None
first = True
for p in s:
p = p.replace('_', ' ')
if len(p) == 0:
continue
if not first:
if paramlist is None:
signode += addnodes.desc_annotation(' ', ' ')
else:
first = False
if p.startswith('L'): # param
if paramlist is None:
paramlist = desc_parameterlist()
paramlist += addnodes.desc_parameter(p[1:], p[1:])
else:
if paramlist is not None:
signode += paramlist
paramlist = None
signode += addnodes.desc_annotation(' ', ' ')
if p.startswith('S'): # sig_prefix
signode += addnodes.desc_annotation(p[1:] + ' ', p[1:] + ' ')
elif p.startswith('P'): # name_prefix
name_prefix = p[1:]
signode += addnodes.desc_addname(name_prefix, name_prefix)
elif p.startswith('N'): # name
name = p[1:]
np = name.split(' ')
for k in np[:-1]:
signode += addnodes.desc_name(k, k)
signode += addnodes.desc_annotation(' ', ' ')
signode += addnodes.desc_name(np[-1], np[-1])
elif p.startswith('A'): # annotation
signode += addnodes.desc_annotation(p[1:], p[1:])
elif p.startswith('R'): # returns
signode += addnodes.desc_returns(p[1:], p[1:])
if paramlist is not None:
signode += paramlist
paramlist = None
if name_prefix:
classname = name_prefix.lstrip(' ')
fullname = name + ' of ' + name_prefix
else:
classname = ''
fullname = name
modname = self.options.get('module', self.env.temp_data.get('tvpl:module'))
signode['module'] = modname
signode['class'] = classname
signode['fullname'] = fullname
return fullname, name_prefix
m = tvpl_sig_re.match(sig)
if m is None:
print 'FAILED', sig
raise ValueError
sig_prefix, name_prefix, name, arglist = m.groups()
arglist = arglist.strip()
if len(arglist) == 0:
arglist = None
# determine module and class name (if applicable), as well as full name
modname = self.options.get('module', self.env.temp_data.get('tvpl:module'))
classname = self.env.temp_data.get('tvpl:class')
if classname:
add_module = False
if name_prefix and name_prefix.startswith(classname):
fullname = name_prefix + name
# class name is given again in the signature
name_prefix = name_prefix[len(classname):].lstrip('.')
elif name_prefix:
# class name is given in the signature, but different
# (shouldn't happen)
fullname = classname + '.' + name_prefix + name
else:
# class name is not given in the signature
fullname = classname + '.' + name
else:
add_module = True
if name_prefix:
classname = name_prefix.rstrip(' ')
fullname = name_prefix + ' ' + name
else:
classname = ''
#.........这里部分代码省略.........