本文整理汇总了Python中sphinx.addnodes.desc_optional函数的典型用法代码示例。如果您正苦于以下问题:Python desc_optional函数的具体用法?Python desc_optional怎么用?Python desc_optional使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了desc_optional函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_macro
def parse_macro(env, sig, signode):
#import rpdb2 ; rpdb2.start_embedded_debugger('foo')
m = macro_sig_re.match(sig)
if not m:
signode += addnodes.desc_name(sig, sig)
return sig
name, args = m.groups()
signode += addnodes.desc_name(name, name)
plist = desc_cmake_argumentlist()
for m in macro_param_re.finditer(args):
arg = m.group(0)
if arg.startswith('['):
arg = arg[1:-1].strip()
x = desc_cmake_argument()
opt = addnodes.desc_optional()
x += opt
m = macro_param_re.match(arg)
assert m is not None, "%s does not match %s" % (arg, macro_param_re.pattern)
opt += _get_param_node(m)
plist += x
# elif arg.startswith('{') choice
else:
x = desc_cmake_argument()
x += _get_param_node(m)
plist += x
signode += plist
return name
示例2: parse_macro
def parse_macro(env, sig, signode):
m = macro_sig_re.match(sig)
if not m:
signode += addnodes.desc_name(sig, sig)
return sig
name, args = m.groups()
signode += addnodes.desc_name(name, name)
plist = desc_cmake_argumentlist()
for m in macro_param_re.finditer(args):
arg = m.group(0)
if arg.startswith('['):
arg = arg[1:-1].strip()
x = desc_cmake_argument()
opt = addnodes.desc_optional()
x += opt
m = macro_param_re.match(arg)
assert m is not None, "%s does not match %s" % (arg, macro_param_re.pattern)
opt += _get_param_node(m, True)
plist += x
else:
x = desc_cmake_argument()
x += _get_param_node(m, False)
plist += x
signode += plist
return name
示例3: _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
示例4: 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
示例5: _pseudo_parse_arglist
def _pseudo_parse_arglist(signode, argstart, arglist, argend):
""""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 = _desc_parameterlist(argstart, argend)
stack = [paramlist]
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(']'):
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
signode += paramlist
示例6: parse_arglist
def parse_arglist(self, signode, arglist):
"""parses argument lists
largely imported from sphinx.domains.python,
changes are mainly to make it work with space-separated
argument lists and to make it look so"""
paramlist = self._fix_paramlist(addnodes.desc_parameterlist())
stack = [paramlist]
try:
for argument in arglist.split(" "):
argument = argument.strip()
ends_open = ends_close = 0
while argument.startswith("["):
stack.append(self._fix_paramlist(addnodes.desc_optional(), False))
stack[-2] += stack[-1]
argument = argument[1:].strip()
while argument.startswith("]"):
stack.pop()
argument = argument[1:].strip()
while 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(self._fix_paramlist(addnodes.desc_optional(), False))
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
signode += self._fix_paramlist(addnodes.desc_parameterlist())
signode[-1] += addnodes.desc_parameter(arglist, arglist)
else:
signode += paramlist
示例7: _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
示例8: format_parameters
def format_parameters(self, parameters):
params = addnodes.desc_parameterlist()
for param in parameters:
node = n.container()
if param["required"]:
node += addnodes.desc_parameter(param["name"], param["name"])
else:
node += addnodes.desc_optional(param["name"], param["name"])
node += n.strong(text=" type: %s " % param["dataType"])
allowableValues = param.get("allowableValues")
if allowableValues:
allowableValues.pop("valueType", None)
node += n.emphasis(text=" %s" % allowableValues)
params += node
return params
示例9: handle_signature
def handle_signature(self, sig, signode):
m = http_method_sig_re.match(sig)
if m is None:
raise ValueError
verb, url, query = m.groups()
if verb is None:
verb = 'GET'
signode += addnodes.desc_addname(verb, verb)
signode += addnodes.desc_name(url, url)
if query:
params = query.strip().split()
for param in params:
signode += addnodes.desc_optional(param, param)
return url
示例10: _parse_parameter_list
def _parse_parameter_list(params):
"""Parse a SpeedCrunch parameter list into nodes."""
paramlist = sc_parameterlist()
stack = deque([paramlist])
for param in params.split(';'):
param = param.strip()
if param and param[-1] in '[]':
p = param[:-1].strip()
stack[-1] += addnodes.desc_parameter(p, p)
else:
stack[-1] += addnodes.desc_parameter(param, param)
if param.endswith('['):
node = addnodes.desc_optional()
stack[-1] += node
stack.append(node)
elif param.endswith(']'):
stack.pop()
return paramlist
示例11: 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
示例12: handle_signature
def handle_signature(self, sig, signode):
symbol_name = []
package = self.env.temp_data.get('cl:package')
objtype = self.get_signature_prefix(sig)
sig_split = sig.split(" ")
sig = sig_split[0]
signode.append(addnodes.desc_annotation(objtype, objtype))
lisp_args = ARGS[package].get(sig.upper(), "")
function_name = addnodes.desc_name(sig, sig)
if not lisp_args.strip() and self.objtype in ["function"]:
lisp_args = "()"
if lisp_args.strip():
types = []
if self.objtype in ["method"]:
types = self.arguments[0].split(' ')[1:]
sexp = SEXP(lisp_args,
types=types,
show_defaults=self.env.app.config.cl_show_defaults)
arg_list = sexp.as_parameterlist(function_name)
signode.append(arg_list)
else:
signode.append(function_name)
# Add Slots
slots = SLOTS[package].get(sig.upper())
if slots and "noinitargs" not in self.options:
# TODO add slot details if describing a class
for slot in slots:
initarg = slot.get(u'initarg')
if initarg and initarg.lower() != 'nil':
slotarg = addnodes.literal_emphasis(slot.get(u'name'), slot.get(u'name'))
slotsig = initarg.lower() + u' '
signode.append(addnodes.desc_optional(slotsig, slotsig, slotarg))
symbol_name = sig
if not symbol_name:
raise Exception("Unknown symbol type for signature %s" % sig)
record_use(package, symbol_name, self.objtype)
return objtype.strip(), symbol_name
示例13: 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:
#.........这里部分代码省略.........
示例14: parse_py_signature
def parse_py_signature(signode, sig, desctype, module, env):
"""
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
"""
m = py_sig_re.match(sig)
if m is None:
raise ValueError
classname, name, arglist, retann = m.groups()
if retann:
retann = u' \N{RIGHTWARDS ARROW} ' + retann.strip()[2:]
if env.currclass:
add_module = False
if classname and classname.startswith(env.currclass):
fullname = classname + name
# class name is given again in the signature
classname = classname[len(env.currclass):].lstrip('.')
elif classname:
# class name is given in the signature, but different
# (shouldn't happen)
fullname = env.currclass + '.' + classname + name
else:
# class name is not given in the signature
fullname = env.currclass + '.' + name
else:
add_module = True
fullname = classname and classname + name or name
if desctype == 'staticmethod':
signode += addnodes.desc_annotation('static ', 'static ')
if classname:
signode += addnodes.desc_addname(classname, classname)
# exceptions are a special case, since they are documented in the
# 'exceptions' module.
elif add_module and env.config.add_module_names and \
module and module != 'exceptions':
nodetext = module + '.'
signode += addnodes.desc_addname(nodetext, nodetext)
signode += addnodes.desc_name(name, name)
if not arglist:
if desctype in ('function', 'method', 'staticmethod'):
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_type(retann, retann)
return fullname, classname
signode += addnodes.desc_parameterlist()
stack = [signode[-1]]
for token in py_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_type(retann, retann)
return fullname, classname
示例15: 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