• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python addnodes.desc_returns函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sphinx.addnodes.desc_returns函数的典型用法代码示例。如果您正苦于以下问题:Python desc_returns函数的具体用法?Python desc_returns怎么用?Python desc_returns使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了desc_returns函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:10173677,项目名称:jenkins-job-builder,代码行数:51,代码来源:yaml.py


示例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
开发者ID:capnrefsmmat,项目名称:sphinx-contrib,代码行数:49,代码来源:adadomain.py


示例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
开发者ID:Lemma1,项目名称:MINAMI,代码行数:49,代码来源:erlangdomain.py


示例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
开发者ID:StoiridhProject,项目名称:StoiridhTools,代码行数:31,代码来源:qbs.py


示例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
开发者ID:xmo-odoo,项目名称:odoo,代码行数:8,代码来源:directives.py


示例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)
开发者ID:daurnimator,项目名称:tarantool,代码行数:45,代码来源:LuaDomain.py


示例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
开发者ID:xushiwei,项目名称:pure-lang,代码行数:57,代码来源:puredomain.py


示例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
开发者ID:Lemma1,项目名称:MINAMI,代码行数:53,代码来源:lassodomain.py


示例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
开发者ID:meatballs,项目名称:sphinxcontrib-plsql,代码行数:43,代码来源:plsqldomain.py


示例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
开发者ID:ministryofjustice,项目名称:cla_backend,代码行数:21,代码来源:swag.py


示例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
开发者ID:mindriot101,项目名称:nimcfitsio,代码行数:22,代码来源:nim-domain.py


示例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:
#.........这里部分代码省略.........
开发者ID:Epixoft,项目名称:php-library2,代码行数:101,代码来源:phpdomain.py


示例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
开发者ID:flyeven,项目名称:doc,代码行数:91,代码来源:tcpipdomain.py


示例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)

#.........这里部分代码省略.........
开发者ID:googlefonts,项目名称:fontbakery,代码行数:101,代码来源:profile.py


示例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 = ''
#.........这里部分代码省略.........
开发者ID:flyeven,项目名称:doc,代码行数:101,代码来源:tvpldomain.py


示例16: parse_signature

    def parse_signature(self, sig, signode):
        """
            Returns (fully qualified name, classname if any).
        """
        m = ooc_sig_re.match(sig)
        if m is None:
            raise ValueError
        classname, name, arglist, retann = m.groups()
        if self.env.currclass:
            add_module = False
            if classname and classname.startswith(self.env.currclass):
                # classname is repeated in the signature
                classname = classname[len(self.env.currclass):].lstrip('/')
            elif classname:
                # class name given in the signature, but different,
                # should not happen
                fullname = self.env.currclass + '/' + classname + name
            else:
                # not given
                if isinstance(self, ClassmemberDesc):
                    fullname = self.env.currclass + ' ' + name
                else:
                    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()
            if retann:
                signode += addnodes.desc_returns('', '', *self._resolve_typeref(retann))
            return fullname, classname
        signode += addnodes.desc_parameterlist()

        stack = [signode[-1]]
        token_before = None
        for token in ooc_paramlist_re.split(arglist):
            if token_before is not None:
                if token == ',':
                    # add commas yay.
                    token_before += token
                    continue
                else:
                    token = token_before + token
                    print 'NOW TOKEN: %r' % token
                    token_before = None
            if token.count('<') != token.count('>'):
                # splitted in the middle of a <A, B, C> declaration :(
                token_before = token
            elif not token or token == ',' or token.isspace():
                pass
            else:
                token = token.strip()
                if ':' in token:
                    stack[-1] += addnodes.desc_parameter('', '', *self._resolve_typeref(token))
                else:
                    stack[-1] += addnodes.desc_parameter(token, token)
        if len(stack) != 1:
            raise ValueError
        if retann:
            ret_nodes = self.state.inline_text(retann, self.lineno)[0]
            signode += addnodes.desc_returns('', '', *self._resolve_typeref(retann))
        return fullname, classname
开发者ID:fasterthanlime,项目名称:ooc-docs,代码行数:80,代码来源:desc.py


示例17: 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

        visibility, modifiers, 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]

        # Method declared as Class::methodName
        if not classname and '::' in name_prefix:
            classname = name_prefix.rstrip('::')
        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

        if visibility:
            signode += addnodes.desc_annotation(visibility, visibility)

        sig_prefix = self.get_signature_prefix(sig)

        if modifiers and not (sig_prefix and 'static' in sig_prefix):
                signode += addnodes.desc_annotation(modifiers, modifiers)

        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

        _pseudo_parse_arglist(signode, arglist)

        if retann:
#.........这里部分代码省略.........
开发者ID:markstory,项目名称:sphinxcontrib-phpdomain,代码行数:101,代码来源:phpdomain.py


示例18: 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
        """
        m = py_sig_re.match(sig)
        if m is None:
            raise ValueError
        name_prefix, name, arglist, retann = m.gro 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python addnodes.desc_signature函数代码示例发布时间:2022-05-27
下一篇:
Python addnodes.desc_parameterlist函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap