Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_signature(self,sig,signode):
sig = sig.strip()
type_name, name, arglist = protobuf_sig_regex.match(sig).groups()
if self.prefix:
signode += addnodes.desc_annotation(self.prefix+' ', self.prefix+' ')
if type_name:
signode += addnodes.desc_type(type_name, type_name)
if name:
signode += addnodes.desc_name(name,name)
if arglist:
paramlist = addnodes.desc_parameterlist()
for arg in arglist.split(','):
argtype, argname = arg.split(None,1)
param = addnodes.desc_parameter(noemph=True)
param += nodes.Text(argtype,argtype)
param += nodes.emphasis(' '+argname,' '+argname)
paramlist += param
signode += paramlist
# class name is given again in the signature
classname = classname[len(self.env.currclass):].lstrip('.')
elif classname:
# class name is given in the signature, but different
# (shouldn't happen)
fullname = self.env.currclass + '.' + classname + name
else:
# class name is not given in the signature
fullname = self.env.currclass + '.' + name
else:
add_module = True
fullname = classname and classname + name or name
prefix = self.get_signature_prefix(sig)
if prefix:
signode += addnodes.desc_annotation(prefix, prefix)
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 self.env.config.add_module_names:
modname = self.options.get('module', self.env.currmodule)
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()
def get_pre_post(self, client, node, replaceEnt):
pre, post = FontHandler.get_pre_post(self, client, node, replaceEnt)
if node.hasattr('noemph'):
pre = ', ' + pre
else:
pre = ', <i>' + pre
post += '</i>'
return pre, post
class HandleSphinxDescOpt(SphinxListHandler, SphinxFont, sphinx.addnodes.desc_optional):
fontstyle = "optional"
def get_pre_post(self, client, node, replaceEnt):
prepost = FontHandler.get_pre_post(self, client, node, replaceEnt)
return '%s[%s, ' % prepost, '%s]%s' % prepost
class HandleDescAnnotation(SphinxHandler, HandleEmphasis, sphinx.addnodes.desc_annotation):
pass
class HandleSphinxIndex(SphinxHandler, sphinx.addnodes.index):
def gather_elements(self, client, node, style):
try:
for entry in node['entries']:
client.pending_targets.append(docutils.nodes.make_id(entry[2]))
except IndexError:
if node['entries']:
log.error("Can't process index entry: %s [%s]",
node['entries'], nodeid(node))
return []
if sphinx.__version__ < '1.0':
class HandleSphinxModule(SphinxHandler, sphinx.addnodes.module):
def gather_elements(self, client, node, style):
def describe_signature(self, signode, func):
self.attach_modifiers(signode, func)
if func.explicit:
signode += addnodes.desc_annotation('explicit', 'explicit')
signode += nodes.Text(' ')
if func.virtual:
signode += addnodes.desc_annotation('virtual', 'virtual')
signode += nodes.Text(' ')
# return value is None for things with a reverse return value
# such as casting operator definitions or constructors
# and destructors.
if func.rv is not None:
self.attach_type(signode, func.rv)
signode += nodes.Text(u' ')
self.attach_function(signode, func)
def render_sub(self, app, doctree, objs, n1, n2):
if objs:
#pni = nodes.list_item()
pni = nodes.paragraph()
pni = nodes.definition_list_item()
prub = nodes.rubric(text=n1)
st = nodes.strong()
st.append(prub)
pni.append(st)
pbl = nodes.bullet_list()
pni.append(pbl)
for (n, be) in objs.iteritems():
ni = nodes.list_item()
ni += addnodes.desc_annotation('class ', 'class ')
ni += addnodes.desc_name(n, n)
ni += be.render(app, doctree)
pbl += ni
return pni
# someone documenting the method of an attribute of the current
# object? shouldn't happen but who knows...
nameprefix = objectname + '.' + nameprefix
fullname = nameprefix + '.' + name
elif objectname:
fullname = objectname + '.' + name
else:
# just a function or constructor
objectname = ''
fullname = name
signode['object'] = objectname
signode['fullname'] = fullname
if self.display_prefix:
signode += addnodes.desc_annotation(self.display_prefix,
self.display_prefix)
if nameprefix:
signode += addnodes.desc_addname(nameprefix + '.', nameprefix + '.')
signode += addnodes.desc_name(name, name)
if self.has_arguments:
if not arglist:
signode += addnodes.desc_parameterlist()
else:
_pseudo_parse_arglist(signode, arglist)
return fullname, nameprefix
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)
anno = self.options.get('annotation')
if anno:
signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
return cid, prefix
def describe_signature(self, signode, obj):
self.attach_modifiers(signode, obj)
signode += addnodes.desc_annotation('type ', 'type ')
if obj.typename is not None:
self.attach_type(signode, obj.typename)
signode += nodes.Text(' ')
self.attach_name(signode, obj.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('py:module'))
if modname and modname != 'exceptions':
nodetext = modname + '.'
signode += addnodes.desc_addname(nodetext, nodetext)
anno = self.options.get('annotation')
signode += addnodes.desc_name(name, name)
if not arglist: