コード例 #1
0
 def spilldescriptors(msg, attrs, predicate):
     ok, attrs = _split_list(attrs, predicate)
     if ok:
         header(msg)
         for name, kind, homecls, value in ok:
             push(self.docdata(value, name, mod))
     return attrs
コード例 #2
0
 def spilldescriptors(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         push(msg)
         for name, kind, homecls, value in ok:
             push(self._docdescriptor(name, value, mod))
     return attrs
コード例 #3
0
ファイル: stubs.py プロジェクト: BigMacchia/pymel
 def spill(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         for name, kind, homecls, value in ok:       #@UnusedVariable
             push(self.document(getattr(object, name),
                                name, mod, object))
     return attrs
コード例 #4
0
ファイル: pydocmk.py プロジェクト: twardoch/pydocmk2
        def spilldata(msg, attrs, predicate):
            # `ok` are attributes to handle, `attrs` is what's left
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:

                result = msg
                for name, kind, homecls, value in ok:
                    base = self.docother(getattr(object, name), name, mod)
                    if (hasattr(value, '__call__')
                            or inspect.isdatadescriptor(value)):
                        doc = getattr(value, "__doc__", None)
                    else:
                        doc = None
                    if doc is None:
                        result += '<dl><dt>%s</dt></dl>\n' % base
                    else:
                        doc = self.markup(self.getdoc(value), self.preformat,
                                          funcs, classes, mdict)
                        doc = '<dd>%s</dd>' % doc
                        result += '<dl><dt>%s%s</dl>\n' % (base, doc)

                # NOTE: this is that important side-effect you're looking for!
                components['docs'].append(result)

            return attrs
コード例 #5
0
 def spillproperties( msg, attrs, predicate ):
     ok, attrs = _split_list( attrs, predicate )
     if ok:
         hr.maybe()
         push( msg )
         for name, kind, homecls, value in ok:
             push( self._docproperty( name, value, mod ) )
     return attrs
コード例 #6
0
 def spill(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         for name, kind, homecls, value in ok:  #@UnusedVariable
             push(
                 self.document(getattr(object, name), name, mod,
                               object))
     return attrs
コード例 #7
0
 def spilldata(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         for name, kind, homecls, value in ok:  # @UnusedVariable
             if hasattr(value, "__call__") or inspect.isdatadescriptor(value):
                 doc = getdoc(value)
             else:
                 doc = None
             push(self.docother(getattr(object, name), name, mod, maxlen=70, doc=doc) + "\n")
     return attrs
コード例 #8
0
ファイル: make_docs.py プロジェクト: boube/minino
        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
		    if name.startswith('_') and name is not '__init__':
			continue
                    push(self.document(getattr(object, name), name, mod,
                                       funcs, classes, mdict, object))
                    push('\n')
            return attrs
コード例 #9
0
ファイル: make_docs.py プロジェクト: pombredanne/rox-lib
 def spill(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             if name.startswith('_') and name is not '__init__':
                 continue
             push(
                 self.document(getattr(object, name), name, mod, funcs,
                               classes, mdict, object))
             push('\n')
     return attrs
コード例 #10
0
ファイル: pydocmk.py プロジェクト: twardoch/pydocmk2
        def spilldescriptors(msg, attrs, predicate):

            # `ok` are attributes to handle, `attrs` is what's left
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                result = msg
                for name, kind, homecls, value in ok:
                    result += self._docdescriptor(name, value, mod)

                # NOTE: this is that important side-effect you're looking for!
                components['docs'].append(result)

            return attrs
コード例 #11
0
 def spilldata( msg, attrs, predicate ):
     ok, attrs = _split_list( attrs, predicate )
     if ok:
         hr.maybe()
         push( msg )
         for name, kind, homecls, value in ok:
             if callable( value ) or inspect.isdatadescriptor( value ):
                 doc = getdoc( value )
             else:
                 doc = None
             push( self.docother( getattr( object, name ), 
                                name, mod, 70, doc ) + '\n' )
     return attrs
コード例 #12
0
 def spill(msg, attrs, predicate):
     ok, attrs = _split_list(attrs, predicate)
     if ok:
         header(msg)
         for name, kind, homecls, value in ok:
             try:
                 value = getattr(object, name)
             except Exception:
                 # Some descriptors may meet a failure in their __get__.
                 # (bug #1785)
                 push(self.docdata(value, name, mod))
             else:
                 push(self.document(value, name, mod, object))
     return attrs
コード例 #13
0
 def spill( msg, attrs, predicate ):
     ok, attrs = _split_list( attrs, predicate )
     if ok:
         hr.maybe()
         #push(msg)
         docstr = []
         for name, kind, homecls, value in ok:
             if name.startswith( '__' ) and name.endswith( '__' ):
                 pass
             else:
                 docstr.append( self.document( getattr( object, name ), 
                                     name, mod, object ) )
         push( "\n".join( docstr ) )
             
     return attrs
コード例 #14
0
 def spilldata(msg, attrs, predicate):
     ok, attrs = _split_list(attrs, predicate)
     if ok:
         header(msg)
         for name, kind, homecls, value in ok:
             if callable(value) or inspect.isdatadescriptor(value):
                 doc = getdoc(value)
             else:
                 doc = None
             try:
                 obj = getattr(object, name)
             except AttributeError:
                 obj = homecls.__dict__[name]
             push(self.docother(obj, name, mod, maxlen=70, doc=doc))
     return attrs
コード例 #15
0
 def spilldata(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         for name, kind, homecls, value in ok:  #@UnusedVariable
             if (hasattr(value, '__call__')
                     or inspect.isdatadescriptor(value)):
                 doc = getdoc(value)
             else:
                 doc = None
             push(
                 self.docother(getattr(object, name),
                               name,
                               mod,
                               maxlen=70,
                               doc=doc) + '\n')
     return attrs
コード例 #16
0
ファイル: make_docs.py プロジェクト: pombredanne/rox-lib
 def spilldata(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             base = self.docother(getattr(object, name), name, mod)
             doc = getattr(value, "__doc__", None)
             if doc is None:
                 push('<dl><dt>%s</dl>\n' % base)
             else:
                 doc = self.markup(getdoc(value), self.preformat, funcs,
                                   classes, mdict)
                 doc = '<dd><tt>%s</tt>' % doc
                 push('<dl><dt>%s%s</dl>\n' % (base, doc))
             push('\n')
     return attrs
コード例 #17
0
ファイル: make_docs.py プロジェクト: boube/minino
 def spilldata(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             base = self.docother(getattr(object, name), name, mod)
             doc = getattr(value, "__doc__", None)
             if doc is None:
                 push('<dl><dt>%s</dl>\n' % base)
             else:
                 doc = self.markup(getdoc(value), self.preformat,
                                   funcs, classes, mdict)
                 doc = '<dd><tt>%s</tt>' % doc
                 push('<dl><dt>%s%s</dl>\n' % (base, doc))
             push('\n')
     return attrs
コード例 #18
0
 def spill(msg, attrs, predicate):
     ok, attrs = _split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             try:
                 value = getattr(object, name)
             except Exception:
                 # Some descriptors may meet a failure
                 # in their __get__.
                 # (bug aroberge/mod_pydoc#1785)
                 push(self._docdescriptor(name, value, mod))
             else:
                 push(
                     self.document(value, name, mod, funcs, classes,
                                   mdict, object))
             push('\n')
     return attrs
コード例 #19
0
ファイル: pydocmk.py プロジェクト: twardoch/pydocmk2
        def spill(msg, attrs, predicate):
            # `ok` are attributes to handle, `attrs` is what's left
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                result = msg
                for name, kind, homecls, value in ok:
                    try:
                        value = getattr(object, name)
                    except Exception:
                        # Some descriptors may meet a failure in their __get__.
                        # (bug #1785)
                        result += self._docdescriptor(name, value, mod)
                    else:
                        result += self.document(value, name, mod, funcs,
                                                classes, mdict, object)

                # NOTE: this is that important side-effect you're looking for!
                components['docs'].append(result)

            return attrs
コード例 #20
0
ファイル: make_docs.py プロジェクト: pombredanne/rox-lib
 def spillproperties(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             push('<dl><dt><strong>%s</strong></dt>\n' % name)
             if value.__doc__ is not None:
                 doc = self.markup(value.__doc__, self.preformat, funcs,
                                   classes, mdict)
                 push('<dd><tt>%s</tt></dd>\n' % doc)
             for attr, tag in [("fget", " getter"), ("fset", " setter"),
                               ("fdel", " deleter")]:
                 func = getattr(value, attr)
                 if func is not None:
                     base = self.document(func, name + tag, mod, funcs,
                                          classes, mdict, object)
                     push('<dd>%s</dd>\n' % base)
             push('</dl>\n')
     return attrs
コード例 #21
0
 def spilldata(msg, attrs, predicate):
     ok, attrs = _split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             base = self.docother(getattr(object, name), name, mod)
             if callable(value) or inspect.isdatadescriptor(value):
                 doc = getattr(value, "__doc__", None)
             else:
                 doc = None
             if doc is None:
                 push('<dl><dt>%s</dt><dd></dd></dl>\n' % base)
             else:
                 doc = self.markup(getdoc(value), self.preformat,
                                   funcs, classes, mdict)
                 doc = '<dd><code>%s</code></dd>' % doc
                 push('<dl><dt>%s%s</dt></dl>\n' % (base, doc))
             push('\n')
     return attrs
コード例 #22
0
ファイル: make_docs.py プロジェクト: boube/minino
 def spillproperties(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         hr.maybe()
         push(msg)
         for name, kind, homecls, value in ok:
             push('<dl><dt><strong>%s</strong></dt>\n' % name)
             if value.__doc__ is not None:
                 doc = self.markup(value.__doc__, self.preformat,
                                   funcs, classes, mdict)
                 push('<dd><tt>%s</tt></dd>\n' % doc)
             for attr, tag in [("fget", " getter"),
                               ("fset", " setter"),
                               ("fdel", " deleter")]:
                 func = getattr(value, attr)
                 if func is not None:
                     base = self.document(func, name + tag, mod,
                                          funcs, classes, mdict, object)
                     push('<dd>%s</dd>\n' % base)
             push('</dl>\n')
     return attrs
コード例 #23
0
 def update_event(self, inp=-1):
     self.set_output_val(0, pydoc._split_list(self.input(0), self.input(1)))
コード例 #24
0
ファイル: pydocmk.py プロジェクト: twardoch/pydocmk2
    def docclass(self,
                 object,
                 name=None,
                 mod=None,
                 funcs={},
                 classes={},
                 *ignored):
        """Produce HTML documentation for a class object."""

        level = 2  # FIXME: use passed level in the future

        realname = object.__name__
        name = name or realname
        bases = object.__bases__
        doc = self.getdoc(object)

        components = {}

        def spill(msg, attrs, predicate):
            # `ok` are attributes to handle, `attrs` is what's left
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                result = msg
                for name, kind, homecls, value in ok:
                    try:
                        value = getattr(object, name)
                    except Exception:
                        # Some descriptors may meet a failure in their __get__.
                        # (bug #1785)
                        result += self._docdescriptor(name, value, mod)
                    else:
                        result += self.document(value, name, mod, funcs,
                                                classes, mdict, object)

                # NOTE: this is that important side-effect you're looking for!
                components['docs'].append(result)

            return attrs

        def spilldescriptors(msg, attrs, predicate):

            # `ok` are attributes to handle, `attrs` is what's left
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                result = msg
                for name, kind, homecls, value in ok:
                    result += self._docdescriptor(name, value, mod)

                # NOTE: this is that important side-effect you're looking for!
                components['docs'].append(result)

            return attrs

        def spilldata(msg, attrs, predicate):
            # `ok` are attributes to handle, `attrs` is what's left
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:

                result = msg
                for name, kind, homecls, value in ok:
                    base = self.docother(getattr(object, name), name, mod)
                    if (hasattr(value, '__call__')
                            or inspect.isdatadescriptor(value)):
                        doc = getattr(value, "__doc__", None)
                    else:
                        doc = None
                    if doc is None:
                        result += '<dl><dt>%s</dt></dl>\n' % base
                    else:
                        doc = self.markup(self.getdoc(value), self.preformat,
                                          funcs, classes, mdict)
                        doc = '<dd>%s</dd>' % doc
                        result += '<dl><dt>%s%s</dl>\n' % (base, doc)

                # NOTE: this is that important side-effect you're looking for!
                components['docs'].append(result)

            return attrs

        mro = collections.deque(inspect.getmro(object))
        if len(mro) > 2:
            components[
                'mro'] = '<dl class="mro"><dt>Method resolution order:</dt>'
            for base in mro:
                components['mro'] += '<dd>%s</dd>' % self.classlink(
                    base, object.__module__)
            components['mro'] += '</dl>'

        attrs = filter(lambda data: pydoc.visiblename(data[0], obj=object),
                       pydoc.classify_class_attrs(object))
        mdict = {}
        for key, kind, homecls, value in attrs:
            mdict[key] = anchor = '#' + name + '-' + key
            try:
                value = getattr(object, name)
            except Exception:
                # Some descriptors may meet a failure in their __get__.
                # (bug #1785)
                pass
            try:
                # The value may not be hashable (e.g., a data attr with
                # a dict or list value).
                mdict[value] = anchor
            except TypeError:
                pass

        components['docs'] = []  # populated in spill* functions

        while attrs:
            if mro:
                thisclass = mro.popleft()
            else:
                thisclass = attrs[0][2]
            attrs, inherited = pydoc._split_list(attrs,
                                                 lambda t: t[2] is thisclass)

            # if thisclass is __builtin__.object: # 2.7 only, no clue why it wasn't just `object` in the first place.
            if thisclass is __builtin__.object:
                attrs = inherited
                continue
            elif thisclass is object:
                tag = ''
            else:
                tag = 'from %s' % self.classlink(thisclass, object.__module__)

            # Sort attrs by name.
            try:
                attrs.sort(key=lambda t: t[0])
            except TypeError:
                attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))  # 2.3 compat

            attrs = spill('<h4 class="head-methods">Methods %s</h4>' % tag,
                          attrs, lambda t: t[1] == 'method')
            attrs = spill(
                '<h4 class="head-class-methods">Class methods %s</h4>' % tag,
                attrs, lambda t: t[1] == 'class method')
            attrs = spill(
                '<h4 class="head-static-methods">Static methods %s</h4>' % tag,
                attrs, lambda t: t[1] == 'static method')
            attrs = spilldescriptors(
                '<h4 class="head-desc">Descriptors %s</h4>' % tag, attrs,
                lambda t: t[1] == 'data descriptor')
            attrs = spilldata(
                '<h4 class="head-attrs">Attributes %s</h4>' % tag, attrs,
                lambda t: t[1] == 'data')
            assert attrs == []
            attrs = inherited

        if name == realname:
            title = '<a name="%s" href="#%s">class <span class="class-name">%s</span></a>' % (
                name, name, realname)
        else:
            title = '<span class="class-name">%s</span> = <a name="%s" href="#%s">class %s</a>' % (
                name, name, name, realname)

        if bases:
            parents = []
            for base in bases:
                parents.append(self.classlink(base, object.__module__))
            title = title + '(%s)' % ', '.join(parents)

        result = '<dt class="class">%s</dt>' % self.heading(level, title)

        result += '<dd class="class">'
        result += '<dd>\n%s\n</dd>' % doc
        if 'mro' in components:
            result += '  <div class="mro">%(mro)s</div>' % components

        result += '\n  '.join(components['docs'])

        result += '</dd>'

        return result
コード例 #25
0
    def docclass(self, object, name=None, mod=None, *ignored):
        """Produce Markdown documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return pydoc.classname(c, m)

        if name == realname:
            title = 'class ' + realname
        else:
            title = name + ' = class ' + realname
        if bases:
            parents = map(makename, bases)
            title = title + '(%s)' % ', '.join(parents)
        title = self.header(title, self.hlevel, name, 'class')

        self.hlevel += 1

        doc = pydoc.getdoc(object)
        contents = doc and [doc + '\n'] or []
        push = contents.append

        # List the mro, if non-trivial.
        mro = pydoc.deque(inspect.getmro(object))
        if len(mro) > 2:
            push("Method resolution order:\n")
            for base in mro:
                push('* ' + makename(base))
            push('')

        # Cute little class to pump out a horizontal rule between sections.
        class HorizontalRule:
            def __init__(self):
                self.needone = 0

            def maybe(self):
                if self.needone:
                    push('-' * 70 + '\n')
                self.needone = 1

        hr = HorizontalRule()

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    try:
                        value = getattr(object, name)
                    except Exception:
                        # Some descriptors may meet a failure in their __get__.
                        # (bug #1785)
                        push(self._docdescriptor(name, value, mod))
                    else:
                        push(self.document(value, name, mod, object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    push(self._docdescriptor(name, value, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    if (hasattr(value, '__call__')
                            or inspect.isdatadescriptor(value)):
                        doc = pydoc.getdoc(value)
                    else:
                        doc = None
                    push(
                        self.docother(getattr(object, name),
                                      name,
                                      mod,
                                      maxlen=70,
                                      doc=doc) + '\n')
            return attrs

        attrs = filter(lambda data: pydoc.visiblename(data[0], obj=object),
                       pydoc.classify_class_attrs(object))
        while attrs:
            if mro:
                thisclass = mro.popleft()
            else:
                thisclass = attrs[0][2]
            attrs, inherited = pydoc._split_list(attrs,
                                                 lambda t: t[2] is thisclass)

            if thisclass is pydoc.__builtin__.object:
                attrs = inherited
                continue
            elif thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % pydoc.classname(
                    thisclass, object.__module__)

            # Sort attrs by name.
            attrs.sort()

            # Pump out the attrs, segregated by kind.
            attrs = spill("Methods %s:\n" % tag, attrs,
                          lambda t: t[1] == 'method')
            attrs = spill("Class methods %s:\n" % tag, attrs,
                          lambda t: t[1] == 'class method')
            attrs = spill("Static methods %s:\n" % tag, attrs,
                          lambda t: t[1] == 'static method')
            attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
                                     lambda t: t[1] == 'data descriptor')
            attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
                              lambda t: t[1] == 'data')
            assert attrs == []
            attrs = inherited

        self.hlevel -= 1

        contents = '\n'.join(contents)
        if not contents:
            return title
        return title + contents.rstrip() + '\n'
コード例 #26
0
    def docclass(self, object, name=None, mod=None, *ignored):
        """Produce text documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return classname(c, m)

        if name == realname:
            title = 'class ' + self.bold(realname)
        else:
            title = self.bold(name) + ' = class ' + realname
        if bases:
            parents = map(makename, bases)
            title = title + '(%s)' % ', '.join(parents)
        title += ':'

        contents = []
        push = contents.append

        doc = getdoc(object)
        if doc:
            push(f'"""\n{doc}\n"""')

        # List the mro, if non-trivial.
        mro = deque(inspect.getmro(object))
        if len(mro) > 2:
            push("\n## Method resolution order:")
            for i, base in enumerate(mro, 1):
                push(f'# {i}) ' + makename(base))
            push('')

        # Cute little class to pump out a horizontal rule between sections.
        class HorizontalRule:
            def __init__(self):
                self.needone = 0

            def maybe(self):
                if self.needone:
                    push('# ' + '-' * 68)
                self.needone = 1

        hr = HorizontalRule()

        def spill(msg, attrs, predicate):
            ok, attrs = _split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push('# ' + msg)
                for name, kind, homecls, value in ok:
                    try:
                        value = getattr(object, name)
                    except Exception:
                        # Some descriptors may meet a failure in their __get__.
                        # (bug #1785)
                        push(self._docdescriptor(name, value, mod))
                    else:
                        push(self.document(value, name, mod, object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = _split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push('# ' + msg)
                for name, kind, homecls, value in ok:
                    push(self._docdescriptor(name, value, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = _split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push('# ' + msg)
                for name, kind, homecls, value in ok:
                    if callable(value) or inspect.isdatadescriptor(value):
                        doc = getdoc(value)
                    else:
                        doc = None
                    try:
                        obj = getattr(object, name)
                    except AttributeError:
                        obj = homecls.__dict__[name]
                    push(
                        self.docother(obj, name, mod, maxlen=70, doc=doc) +
                        '\n')
            return attrs

        attrs = [(name, kind, cls, value)
                 for name, kind, cls, value in classify_class_attrs(object)
                 if visiblename(name, obj=object)]

        while attrs:
            if mro:
                thisclass = mro.popleft()
            else:
                thisclass = attrs[0][2]
            attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)

            if thisclass is builtins.object:
                attrs = inherited
                continue
            elif thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % classname(thisclass,
                                                      object.__module__)

            sort_attributes(attrs, object)

            # Pump out the attrs, segregated by kind.
            attrs = spill("Methods %s:\n" % tag, attrs,
                          lambda t: t[1] == 'method')
            attrs = spill("Class methods %s:\n" % tag, attrs,
                          lambda t: t[1] == 'class method')
            attrs = spill("Static methods %s:\n" % tag, attrs,
                          lambda t: t[1] == 'static method')
            attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
                                     lambda t: t[1] == 'data descriptor')
            attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
                              lambda t: t[1] == 'data')

            assert attrs == []
            attrs = inherited

        contents = '\n'.join(contents) or 'pass'
        return '\n' + title + '\n' + self.indent(contents.rstrip(),
                                                 '    ') + '\n'
コード例 #27
0
    def docclass(self, object, name=None, mod=None):
        """Produce text documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return self.classname(c, m)

        title = 'class ' + name

        if bases:
            parents = map(makename, bases)
            title = title + '(%s)' % join(parents, ', ')
        title += ':\n'

        doc = getdoc(object)
        contents = doc and [self.docstring(doc) + '\n'] or []
        push = contents.append

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:  #@UnusedVariable
                    push(
                        self.document(getattr(object, name), name, mod,
                                      object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:  #@UnusedVariable
                    push(self._docdescriptor(name, value, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:  #@UnusedVariable
                    if (hasattr(value, '__call__')
                            or inspect.isdatadescriptor(value)):
                        doc = getdoc(value)
                    else:
                        doc = None
                    push(
                        self.docother(getattr(object, name),
                                      name,
                                      mod,
                                      maxlen=70,
                                      doc=doc) + '\n')
            return attrs

        attrs = filter(lambda data: visiblename(data[0]),
                       classify_class_attrs(object))

        thisclass = object
        attrs, inherited = pydoc._split_list(attrs,
                                             lambda t: t[2] is thisclass)

        if thisclass is __builtin__.object:
            attrs = inherited
        else:
            if attrs:
                tag = None

                # Sort attrs by name.
                attrs.sort()

                # Pump out the attrs, segregated by kind.
                attrs = spill("Methods %s:\n" % tag, attrs,
                              lambda t: t[1] == 'method')
                attrs = spill("Class methods %s:\n" % tag, attrs,
                              lambda t: t[1] == 'class method')
                attrs = spill("Static methods %s:\n" % tag, attrs,
                              lambda t: t[1] == 'static method')
                attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
                                         lambda t: t[1] == 'data descriptor')
                attrs = spilldata("Data and other attributes %s:\n" % tag,
                                  attrs, lambda t: t[1] == 'data')
            else:
                contents.append('pass')

        contents = '\n'.join(contents)

        return title + self.indent(rstrip(contents), '    ') + '\n\n'
コード例 #28
0
ファイル: make_docs.py プロジェクト: pombredanne/rox-lib
    def docclass(self,
                 object,
                 name=None,
                 mod=None,
                 funcs={},
                 classes={},
                 *ignored):
        """Produce HTML documentation for a class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        contents = []
        push = contents.append

        # Cute little class to pump out a horizontal rule between sections.
        class HorizontalRule:
            def __init__(self):
                self.needone = 0

            def maybe(self):
                if self.needone:
                    push('<hr>\n')
                self.needone = 1

        hr = HorizontalRule()

        mro = list(inspect.getmro(object))

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    if name.startswith('_') and name is not '__init__':
                        continue
                    push(
                        self.document(getattr(object, name), name, mod, funcs,
                                      classes, mdict, object))
                    push('\n')
            return attrs

        def spillproperties(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    push('<dl><dt><strong>%s</strong></dt>\n' % name)
                    if value.__doc__ is not None:
                        doc = self.markup(value.__doc__, self.preformat, funcs,
                                          classes, mdict)
                        push('<dd><tt>%s</tt></dd>\n' % doc)
                    for attr, tag in [("fget", " getter"), ("fset", " setter"),
                                      ("fdel", " deleter")]:
                        func = getattr(value, attr)
                        if func is not None:
                            base = self.document(func, name + tag, mod, funcs,
                                                 classes, mdict, object)
                            push('<dd>%s</dd>\n' % base)
                    push('</dl>\n')
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    base = self.docother(getattr(object, name), name, mod)
                    doc = getattr(value, "__doc__", None)
                    if doc is None:
                        push('<dl><dt>%s</dl>\n' % base)
                    else:
                        doc = self.markup(getdoc(value), self.preformat, funcs,
                                          classes, mdict)
                        doc = '<dd><tt>%s</tt>' % doc
                        push('<dl><dt>%s%s</dl>\n' % (base, doc))
                    push('\n')
            return attrs

        attrs = inspect.classify_class_attrs(object)
        mdict = {}
        for key, kind, homecls, value in attrs:
            mdict[key] = anchor = '#' + name + '-' + key
            value = getattr(object, key)
            try:
                # The value may not be hashable (e.g., a data attr with
                # a dict or list value).
                mdict[value] = anchor
            except TypeError:
                pass

        while attrs:
            if mro:
                thisclass = mro.pop(0)
            else:
                thisclass = attrs[0][2]
            attrs, inherited = pydoc._split_list(attrs,
                                                 lambda t: t[2] is thisclass)

            if thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % self.classlink(
                    thisclass, object.__module__)
            tag += ':<br>\n'

            # Sort attrs by name.
            attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))

            # Pump out the attrs, segregated by kind.
            attrs = spill("Methods %s" % tag, attrs,
                          lambda t: t[1] == 'method')
            attrs = spill("Class methods %s" % tag, attrs,
                          lambda t: t[1] == 'class method')
            attrs = spill("Static methods %s" % tag, attrs,
                          lambda t: t[1] == 'static method')
            attrs = spillproperties("Properties %s" % tag, attrs,
                                    lambda t: t[1] == 'property')
            #attrs = spilldata("Data and non-method functions %s" % tag, attrs,
            #                  lambda t: t[1] == 'data')
            #assert attrs == []
            attrs = None

        contents = ''.join(contents)

        if name == realname:
            title = '<a name="%s">class <strong>%s</strong></a>' % (name,
                                                                    realname)
        else:
            title = '<strong>%s</strong> = <a name="%s">class %s</a>' % (
                name, name, realname)
        if bases:
            parents = []
            for base in bases:
                parents.append(self.classlink(base, object.__module__))
            title = title + '(%s)' % join(parents, ', ')
        doc = self.markup(getdoc(object), self.preformat, funcs, classes,
                          mdict)
        doc = doc and '<tt>%s<br>&nbsp;</tt>' % doc or '&nbsp;'

        return self.section(title, '#000000', '#ffc8d8', contents, 5, doc)
コード例 #29
0
ファイル: stubs.py プロジェクト: cgrebeld/pymel
    def docclass(self, object, name=None, mod=None):
        """Produce text documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return self.classname(c, m)

        title = 'class ' + name

        if bases:
            parents = map(makename, bases)
            title = title + '(%s)' % join(parents, ', ')
        title += ':\n'
        
        doc = getdoc(object)
        contents = doc and [self.docstring(doc) + '\n'] or []
        push = contents.append

#        # List the mro, if non-trivial.
        mro = deque(inspect.getmro(object))
#        if len(mro) > 2:
#            push("Method resolution order:")
#            for base in mro:
#                push('    ' + makename(base))
#            push('')

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:
                    push(self.document(getattr(object, name),
                                       name, mod, object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:
                    push(self._docdescriptor(name, value, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:
                    if (hasattr(value, '__call__') or
                            inspect.isdatadescriptor(value)):
                        doc = getdoc(value)
                    else:
                        doc = None
                    push(self.docother(getattr(object, name),
                                       name, mod, maxlen=70, doc=doc) + '\n')
            return attrs

        attrs = filter(lambda data: visiblename(data[0]),
                       classify_class_attrs(object))

        thisclass = object
        attrs, inherited = pydoc._split_list(attrs, lambda t: t[2] is thisclass)

        if thisclass is __builtin__.object:
            attrs = inherited
        else:
            if attrs:
                tag = None
        
                # Sort attrs by name.
                attrs.sort()
        
                # Pump out the attrs, segregated by kind.
                attrs = spill("Methods %s:\n" % tag, attrs,
                              lambda t: t[1] == 'method')
                attrs = spill("Class methods %s:\n" % tag, attrs,
                              lambda t: t[1] == 'class method')
                attrs = spill("Static methods %s:\n" % tag, attrs,
                              lambda t: t[1] == 'static method')
                attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
                                         lambda t: t[1] == 'data descriptor')
                attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
                                  lambda t: t[1] == 'data')
            else:
                contents.append('pass')

        contents = '\n'.join(contents)
        
        return title + self.indent(rstrip(contents), '    ') + '\n\n'
コード例 #30
0
        def docclass(self,
                     object,
                     name=None,
                     mod=None,
                     funcs={},
                     classes={},
                     *ignored):
            """Produce HTML documentation for a class object."""
            realname = object.__name__
            name = name or realname
            bases = object.__bases__

            contents = []
            push = contents.append

            # Cute little class to pump out a horizontal rule between sections.
            class HorizontalRule:
                def __init__(self):
                    self.needone = 0

                def maybe(self):
                    if self.needone:
                        push('<hr>\n')
                    self.needone = 1

            hr = HorizontalRule()

            # List the mro, if non-trivial.
            mro = deque(inspect.getmro(object))
            if len(mro) > 2:
                hr.maybe()
                push('<dl><dt>Method resolution order:</dt>\n')
                for base in mro:
                    push('<dd>%s</dd>\n' %
                         self.classlink(base, object.__module__))
                push('</dl>\n')

            def spill(msg, attrs, predicate):
                ok, attrs = _split_list(attrs, predicate)
                if ok:
                    hr.maybe()
                    push(msg)
                    for name, kind, homecls, value in ok:
                        try:
                            value = getattr(object, name)
                        except Exception:
                            # Some descriptors may meet a failure
                            # in their __get__.
                            # (bug aroberge/mod_pydoc#1785)
                            push(self._docdescriptor(name, value, mod))
                        else:
                            push(
                                self.document(value, name, mod, funcs, classes,
                                              mdict, object))
                        push('\n')
                return attrs

            def spilldescriptors(msg, attrs, predicate):
                ok, attrs = _split_list(attrs, predicate)
                if ok:
                    hr.maybe()
                    push(msg)
                    for name, kind, homecls, value in ok:
                        push(self._docdescriptor(name, value, mod))
                return attrs

            def spilldata(msg, attrs, predicate):
                ok, attrs = _split_list(attrs, predicate)
                if ok:
                    hr.maybe()
                    push(msg)
                    for name, kind, homecls, value in ok:
                        base = self.docother(getattr(object, name), name, mod)
                        if callable(value) or inspect.isdatadescriptor(value):
                            doc = getattr(value, "__doc__", None)
                        else:
                            doc = None
                        if doc is None:
                            push('<dl><dt>%s</dt><dd></dd></dl>\n' % base)
                        else:
                            doc = self.markup(getdoc(value), self.preformat,
                                              funcs, classes, mdict)
                            doc = '<dd><code>%s</code></dd>' % doc
                            push('<dl><dt>%s%s</dt></dl>\n' % (base, doc))
                        push('\n')
                return attrs

            attrs = [(name, kind, cls, value)
                     for name, kind, cls, value in classify_class_attrs(object)
                     if visiblename(name, obj=object)]

            mdict = {}
            for key, kind, homecls, value in attrs:
                mdict[key] = anchor = '#' + name + '-' + key
                try:
                    value = getattr(object, name)
                except Exception:
                    # Some descriptors may meet a failure in their __get__.
                    # (bug #1785)
                    pass
                try:
                    # The value may not be hashable (e.g., a data attr with
                    # a dict or list value).
                    mdict[value] = anchor
                except TypeError:
                    pass

            while attrs:
                if mro:
                    thisclass = mro.popleft()
                else:
                    thisclass = attrs[0][2]
                attrs, inherited = _split_list(attrs,
                                               lambda t: t[2] is thisclass)

                if thisclass is builtins.object:
                    attrs = inherited
                    continue
                elif thisclass is object:
                    tag = 'defined here'
                else:
                    tag = 'inherited from %s' % self.classlink(
                        thisclass, object.__module__)
                tag += ':<br>\n'

                # Sort attrs by name.
                attrs.sort(key=lambda t: t[0])

                # Pump out the attrs, segregated by kind.
                attrs = spill('Methods %s' % tag, attrs,
                              lambda t: t[1] == 'method')
                attrs = spill('Class methods %s' % tag, attrs,
                              lambda t: t[1] == 'class method')
                attrs = spill('Static methods %s' % tag, attrs,
                              lambda t: t[1] == 'static method')
                attrs = spilldescriptors('Data descriptors %s' % tag, attrs,
                                         lambda t: t[1] == 'data descriptor')
                attrs = spilldata('Data and other attributes %s' % tag, attrs,
                                  lambda t: t[1] == 'data')
                assert attrs == []
                attrs = inherited

            contents = ''.join(contents)

            if name == realname:
                title = '<span id="%s" class="signature"> class %s</span>' % (
                    name, realname)
            else:
                title = (
                    '%s = <span id="%s" class="signature">class %s</span>' %
                    (name, name, realname))
            if bases:
                parents = []
                for base in bases:
                    parents.append(self.classlink(base, object.__module__))
                title = title + '(%s)' % ', '.join(parents)
            doc = self.markup(getdoc(object), self.preformat, funcs, classes,
                              mdict)
            doc = doc and '<code>%s<br>&nbsp;</code>' % doc

            return self.html_section(title,
                                     contents,
                                     3,
                                     doc,
                                     css_class="docclass")
コード例 #31
0
    def docclass( self, object, name=None, mod=None ):
        """Produce tex documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename( c, m=object.__module__ ):
            return classname( c, m )

        if name == realname:
            title = self.texttt( 'class ' + realname )
        else:
            title = self.texttt( name + ' = class ' + realname )
        if bases:
            parents = map( makename, bases )
            title = title + '(%s)' % join( parents, ', ' )

        doc = getdoc( object )
        contents = doc and [doc + '\n'] or []
        push = contents.append

        # List the mro, if non-trivial.
        mro = deque( inspect.getmro( object ) )
#        if len(mro) > 2:
#            push("Method resolution order:")
#            for base in mro:
#                push('    ' + makename(base))
#            push('')

        #  class to pump out a horizontal rule between sections.
        class HorizontalRule:
            def __init__( self ):
                self.needone = 0
            def maybe( self ):
                if self.needone:
                    push( '%' * 40 )
                self.needone = 1
        hr = HorizontalRule()

        def spill( msg, attrs, predicate ):
            ok, attrs = _split_list( attrs, predicate )
            if ok:
                hr.maybe()
                #push(msg)
                docstr = []
                for name, kind, homecls, value in ok:
                    if name.startswith( '__' ) and name.endswith( '__' ):
                        pass
                    else:
                        docstr.append( self.document( getattr( object, name ), 
                                            name, mod, object ) )
                push( "\n".join( docstr ) )
                    
            return attrs

        def spillproperties( msg, attrs, predicate ):
            ok, attrs = _split_list( attrs, predicate )
            if ok:
                hr.maybe()
                push( msg )
                for name, kind, homecls, value in ok:
                    push( self._docproperty( name, value, mod ) )
            return attrs

        def spilldata( msg, attrs, predicate ):
            ok, attrs = _split_list( attrs, predicate )
            if ok:
                hr.maybe()
                push( msg )
                for name, kind, homecls, value in ok:
                    if callable( value ) or inspect.isdatadescriptor( value ):
                        doc = getdoc( value )
                    else:
                        doc = None
                    push( self.docother( getattr( object, name ), 
                                       name, mod, 70, doc ) + '\n' )
            return attrs

        attrs = filter( lambda ( name, kind, cls, value ): visiblename( name ), 
                       inspect.classify_class_attrs( object ) )
        while attrs:
            if mro:
                thisclass = mro.popleft()
            else:
                thisclass = attrs[0][2]
            attrs, inherited = _split_list( attrs, lambda t: t[2] is thisclass )

            if thisclass is __builtin__.object:
                attrs = inherited
                continue
            elif thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % classname( thisclass, 
                                                      object.__module__ )
            filter( lambda t: not t[0].startswith( '_' ), attrs )

            # Sort attrs by name.
            attrs.sort()

            # Pump out the attrs, segregated by kind.
            attrs = spill( "Methods %s:\n" % tag, attrs, 
                          lambda t: t[1] == 'method' )
            attrs = spill( "Class methods %s:\n" % tag, attrs, 
                          lambda t: t[1] == 'class method' )
            attrs = spill( "Static methods %s:\n" % tag, attrs, 
                          lambda t: t[1] == 'static method' )
#            attrs = spillproperties("Properties %s:\n" % tag, attrs,
#                                    lambda t: t[1] == 'property')
#            attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
#                              lambda t: t[1] == 'data')
#            assert attrs == []
#            attrs = inherited

        contents = '\n'.join( contents )
        if not contents:
            return title + '\n'
        return self.classdesc( realname, '\n' + self.indent( rstrip( contents ), '   ' ) )
コード例 #32
0
 def spilldescriptors(msg, attrs, predicate):
     ok, attrs = pydoc._split_list(attrs, predicate)
     if ok:
         for name, kind, homecls, value in ok:  # @UnusedVariable
             push(self._docdescriptor(name, value, mod))
     return attrs
コード例 #33
0
    def docclass(self, object, name=None, mod=None):
        """Produce text documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return self.classname(c, m)

        title = "class " + name

        if bases:
            parents = map(makename, bases)
            title = title + "(%s)" % join(parents, ", ")
        title += ":\n"

        doc = getdoc(object)
        contents = doc and [self.docstring(doc) + "\n"] or []
        push = contents.append

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:  # @UnusedVariable
                    push(self.document(getattr(object, name), name, mod, object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:  # @UnusedVariable
                    push(self._docdescriptor(name, value, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                for name, kind, homecls, value in ok:  # @UnusedVariable
                    if hasattr(value, "__call__") or inspect.isdatadescriptor(value):
                        doc = getdoc(value)
                    else:
                        doc = None
                    push(self.docother(getattr(object, name), name, mod, maxlen=70, doc=doc) + "\n")
            return attrs

        attrs = filter(lambda data: visiblename(data[0]), classify_class_attrs(object))

        thisclass = object
        attrs, inherited = pydoc._split_list(attrs, lambda t: t[2] is thisclass)

        if thisclass is __builtin__.object:
            attrs = inherited
        else:
            if attrs:
                tag = None

                # Sort attrs by name.
                attrs.sort()

                # Pump out the attrs, segregated by kind.
                attrs = spill("Methods %s:\n" % tag, attrs, lambda t: t[1] == "method")
                attrs = spill("Class methods %s:\n" % tag, attrs, lambda t: t[1] == "class method")
                attrs = spill("Static methods %s:\n" % tag, attrs, lambda t: t[1] == "static method")
                attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs, lambda t: t[1] == "data descriptor")
                attrs = spilldata("Data and other attributes %s:\n" % tag, attrs, lambda t: t[1] == "data")
            else:
                contents.append("pass")

        contents = "\n".join(contents)

        return title + self.indent(rstrip(contents), "    ") + "\n\n"
コード例 #34
0
    def docclass(self, object, name=None, mod=None, *ignored):
        """Produce text documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return classname(c, m)

        if name == realname:
            title = 'class ' + self.bold(realname)
        else:
            title = self.bold(name) + ' = class ' + realname
        if bases:
            parents = map(makename, bases)
            title = title + '(%s)' % ', '.join(parents)

        contents = []
        push = contents.append

        try:
            signature = inspect.signature(object)
        except (ValueError, TypeError):
            signature = None
        if signature:
            argspec = str(signature)
            if argspec and argspec != '()':
                push(name + argspec)

        doc = getdoc(object)
        if doc:
            push(self.indent(doc.splitlines()[0]))

        # List the mro, if non-trivial.
        mro = deque(inspect.getmro(object))
        if len(mro) > 2:
            push("Method resolution order:")
            for base in mro:
                push('    ' + makename(base))

        # List the built-in subclasses, if any:
        subclasses = sorted((str(cls.__name__)
                             for cls in type.__subclasses__(object)
                             if not cls.__name__.startswith("_")
                             and cls.__module__ == "builtins"),
                            key=str.lower)
        no_of_subclasses = len(subclasses)
        MAX_SUBCLASSES_TO_DISPLAY = 4
        if subclasses:
            push("Built-in subclasses:")
            for subclassname in subclasses[:MAX_SUBCLASSES_TO_DISPLAY]:
                push('    ' + subclassname)
            if no_of_subclasses > MAX_SUBCLASSES_TO_DISPLAY:
                push('    ... and ' +
                     str(no_of_subclasses - MAX_SUBCLASSES_TO_DISPLAY) +
                     ' other subclasses')
            push('')

        def header(msg):
            push(f"\n{msg}\n" + ("-" * len(msg)))

        def spill(msg, attrs, predicate):
            ok, attrs = _split_list(attrs, predicate)
            if ok:
                header(msg)
                for name, kind, homecls, value in ok:
                    try:
                        value = getattr(object, name)
                    except Exception:
                        # Some descriptors may meet a failure in their __get__.
                        # (bug #1785)
                        push(self.docdata(value, name, mod))
                    else:
                        push(self.document(value, name, mod, object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = _split_list(attrs, predicate)
            if ok:
                header(msg)
                for name, kind, homecls, value in ok:
                    push(self.docdata(value, name, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = _split_list(attrs, predicate)
            if ok:
                header(msg)
                for name, kind, homecls, value in ok:
                    if callable(value) or inspect.isdatadescriptor(value):
                        doc = getdoc(value)
                    else:
                        doc = None
                    try:
                        obj = getattr(object, name)
                    except AttributeError:
                        obj = homecls.__dict__[name]
                    push(self.docother(obj, name, mod, maxlen=70, doc=doc))
            return attrs

        attrs = [(name, kind, cls, value)
                 for name, kind, cls, value in classify_class_attrs(object)
                 if visiblename(name, obj=object)]

        while attrs:
            if mro:
                thisclass = mro.popleft()
            else:
                thisclass = attrs[0][2]
            attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)

            if object is not builtins.object and thisclass is builtins.object:
                attrs = inherited
                continue
            elif thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % classname(thisclass,
                                                      object.__module__)

            sort_attributes(attrs, object)

            # Pump out the attrs, segregated by kind.
            attrs = spill("Methods %s" % tag, attrs,
                          lambda t: t[1] == 'method')
            attrs = spill("Class methods %s" % tag, attrs,
                          lambda t: t[1] == 'class method')
            attrs = spill("Static methods %s" % tag, attrs,
                          lambda t: t[1] == 'static method')
            attrs = spilldescriptors("Readonly properties %s" % tag, attrs,
                                     lambda t: t[1] == 'readonly property')
            attrs = spilldescriptors("Data descriptors %s" % tag, attrs,
                                     lambda t: t[1] == 'data descriptor')
            attrs = spilldata("Data and other attributes %s" % tag, attrs,
                              lambda t: t[1] == 'data')

            assert attrs == []
            attrs = inherited

        contents = '\n'.join(contents)
        if not contents:
            return title + '\n'
        return title + '\n' + self.indent(contents.rstrip(), ' |  ') + '\n'
コード例 #35
0
    def docclass(self, object, name=None, mod=None):
        """Produce text documentation for a given class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        def makename(c, m=object.__module__):
            return pydoc.classname(c, m)

        if name == realname:
            title = '== class ' + self.bold(realname)
        else:
            title = '== ' + self.bold(name) + ' = class ' + realname
        if bases:
            parents = map(makename, bases)
            title += '(%s)' % join(parents, ', ')

        title += " =="

        classDoc = pydoc.getdoc(object)

        contents = []

        if classDoc:
            itrs = []
            for k in classDoc.split('\n'):
                if "@ivar " in k:
                    n = k.strip('@ivar ').split(':')
                    itrs.append(" * '''%s''': %s" % tuple(n))
                else:
                    itrs.append(k)

            contents.append('\n'.join(itrs) + '\n')
        push = contents.append

        # List the mro, if non-trivial.
        mro = deque(inspect.getmro(object))
        if len(mro) > 2:
            push("Method resolution order:")
            for base in mro:
                push('    ' + makename(base))
            push('')

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                push(msg)
                for name, kind, homecls, value in ok:
                    push(
                        self.document(getattr(object, name), name, mod,
                                      object))
            return attrs

        def spilldescriptors(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                push(msg)
                for name, kind, homecls, value in ok:
                    push(self._docdescriptor(name, value, mod))
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                push(msg)
                for name, kind, homecls, value in ok:
                    if callable(value) or inspect.isdatadescriptor(value):
                        doc = pydoc.getdoc(value)
                    else:
                        doc = None
                    push(
                        self.docother(getattr(object, name),
                                      name,
                                      mod,
                                      maxlen=70,
                                      doc=doc) + '\n')
            return attrs

        attrs = filter(
            lambda (name, kind, cls, value): pydoc.visiblename(name),
            inspect.classify_class_attrs(object))
        while attrs:
            if mro:
                thisclass = mro.popleft()
            else:
                thisclass = attrs[0][2]
            attrs, inherited = pydoc._split_list(attrs,
                                                 lambda t: t[2] is thisclass)

            if thisclass is __builtin__.object:
                attrs = inherited
                continue
            elif thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % pydoc.classname(
                    thisclass, object.__module__)
            filter(lambda t: not t[0].startswith('_'), attrs)

            # Sort attrs by name.
            attrs.sort()

            # Pump out the attrs, segregated by kind.
            attrs = spill("=== Methods %s: ===\n" % tag, attrs,
                          lambda t: t[1] == 'method')
            attrs = spill("=== Class methods %s: ===\n" % tag, attrs,
                          lambda t: t[1] == 'class method')
            attrs = spill("=== Static methods %s: ===\n" % tag, attrs,
                          lambda t: t[1] == 'static method')
            attrs = spilldescriptors("=== Data descriptors %s: ===\n" % tag,
                                     attrs,
                                     lambda t: t[1] == 'data descriptor')
            attrs = spilldata("=== Data and other attributes %s: ===\n" % tag,
                              attrs, lambda t: t[1] == 'data')
            assert attrs == []
            attrs = inherited

        contents = '\n'.join(contents)
        if not contents:
            return title + '\n'
        return title + '\n' + self.indent(rstrip(contents), '') + '\n'
コード例 #36
0
ファイル: make_docs.py プロジェクト: boube/minino
    def docclass(self, object, name=None, mod=None, funcs={}, classes={},
                 *ignored):
        """Produce HTML documentation for a class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        contents = []
        push = contents.append

        # Cute little class to pump out a horizontal rule between sections.
        class HorizontalRule:
            def __init__(self):
                self.needone = 0
            def maybe(self):
                if self.needone:
                    push('<hr>\n')
                self.needone = 1
        hr = HorizontalRule()

        mro = list(inspect.getmro(object))

        def spill(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
		    if name.startswith('_') and name is not '__init__':
			continue
                    push(self.document(getattr(object, name), name, mod,
                                       funcs, classes, mdict, object))
                    push('\n')
            return attrs

        def spillproperties(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    push('<dl><dt><strong>%s</strong></dt>\n' % name)
                    if value.__doc__ is not None:
                        doc = self.markup(value.__doc__, self.preformat,
                                          funcs, classes, mdict)
                        push('<dd><tt>%s</tt></dd>\n' % doc)
                    for attr, tag in [("fget", " getter"),
                                      ("fset", " setter"),
                                      ("fdel", " deleter")]:
                        func = getattr(value, attr)
                        if func is not None:
                            base = self.document(func, name + tag, mod,
                                                 funcs, classes, mdict, object)
                            push('<dd>%s</dd>\n' % base)
                    push('</dl>\n')
            return attrs

        def spilldata(msg, attrs, predicate):
            ok, attrs = pydoc._split_list(attrs, predicate)
            if ok:
                hr.maybe()
                push(msg)
                for name, kind, homecls, value in ok:
                    base = self.docother(getattr(object, name), name, mod)
                    doc = getattr(value, "__doc__", None)
                    if doc is None:
                        push('<dl><dt>%s</dl>\n' % base)
                    else:
                        doc = self.markup(getdoc(value), self.preformat,
                                          funcs, classes, mdict)
                        doc = '<dd><tt>%s</tt>' % doc
                        push('<dl><dt>%s%s</dl>\n' % (base, doc))
                    push('\n')
            return attrs

        attrs = inspect.classify_class_attrs(object)
        mdict = {}
        for key, kind, homecls, value in attrs:
            mdict[key] = anchor = '#' + name + '-' + key
            value = getattr(object, key)
            try:
                # The value may not be hashable (e.g., a data attr with
                # a dict or list value).
                mdict[value] = anchor
            except TypeError:
                pass

        while attrs:
            if mro:
                thisclass = mro.pop(0)
            else:
                thisclass = attrs[0][2]
            attrs, inherited = pydoc._split_list(attrs, lambda t: t[2] is thisclass)
	    
            if thisclass is object:
                tag = "defined here"
            else:
                tag = "inherited from %s" % self.classlink(thisclass,
                                                          object.__module__)
            tag += ':<br>\n'

            # Sort attrs by name.
            attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))

            # Pump out the attrs, segregated by kind.
            attrs = spill("Methods %s" % tag, attrs,
                          lambda t: t[1] == 'method')
            attrs = spill("Class methods %s" % tag, attrs,
                          lambda t: t[1] == 'class method')
            attrs = spill("Static methods %s" % tag, attrs,
                          lambda t: t[1] == 'static method')
            attrs = spillproperties("Properties %s" % tag, attrs,
                                    lambda t: t[1] == 'property')
            #attrs = spilldata("Data and non-method functions %s" % tag, attrs,
            #                  lambda t: t[1] == 'data')
            #assert attrs == []
            attrs = None

        contents = ''.join(contents)

        if name == realname:
            title = '<a name="%s">class <strong>%s</strong></a>' % (
                name, realname)
        else:
            title = '<strong>%s</strong> = <a name="%s">class %s</a>' % (
                name, name, realname)
        if bases:
            parents = []
            for base in bases:
                parents.append(self.classlink(base, object.__module__))
            title = title + '(%s)' % join(parents, ', ')
        doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
        doc = doc and '<tt>%s<br>&nbsp;</tt>' % doc or '&nbsp;'

        return self.section(title, '#000000', '#ffc8d8', contents, 5, doc)