當前位置: 首頁>>代碼示例>>Python>>正文


Python inspect.getclasstree方法代碼示例

本文整理匯總了Python中inspect.getclasstree方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.getclasstree方法的具體用法?Python inspect.getclasstree怎麽用?Python inspect.getclasstree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inspect的用法示例。


在下文中一共展示了inspect.getclasstree方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: formattree

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getclasstree [as 別名]
def formattree(self, tree, modname, parent=None):
        """Produce HTML for a class tree as given by inspect.getclasstree()."""
        result = ''
        for entry in tree:
            if type(entry) is type(()):
                c, bases = entry
                result = result + '<dt><font face="helvetica, arial">'
                result = result + self.classlink(c, modname)
                if bases and bases != (parent,):
                    parents = []
                    for base in bases:
                        parents.append(self.classlink(base, modname))
                    result = result + '(' + ', '.join(parents) + ')'
                result = result + '\n</font></dt>'
            elif type(entry) is type([]):
                result = result + '<dd>\n%s</dd>\n' % self.formattree(
                    entry, modname, c)
        return '<dl>\n%s</dl>\n' % result 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:20,代碼來源:pydoc.py

示例2: formattree

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getclasstree [as 別名]
def formattree(self, tree, modname, parent=None):
        """Produce HTML for a class tree as given by inspect.getclasstree()."""
        result = ''
        for entry in tree:
            if type(entry) is type(()):
                c, bases = entry
                result = result + '<dt><font face="helvetica, arial">'
                result = result + self.classlink(c, modname)
                if bases and bases != (parent,):
                    parents = []
                    for base in bases:
                        parents.append(self.classlink(base, modname))
                    result = result + '(' + join(parents, ', ') + ')'
                result = result + '\n</font></dt>'
            elif type(entry) is type([]):
                result = result + '<dd>\n%s</dd>\n' % self.formattree(
                    entry, modname, c)
        return '<dl>\n%s</dl>\n' % result 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:20,代碼來源:pydoc.py

示例3: test_getclasses

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getclasstree [as 別名]
def test_getclasses(self):
        classes = inspect.getmembers(mod, inspect.isclass)
        self.assertEqual(classes,
                         [('FesteringGob', mod.FesteringGob),
                          ('MalodorousPervert', mod.MalodorousPervert),
                          ('ParrotDroppings', mod.ParrotDroppings),
                          ('StupidGit', mod.StupidGit)])
        tree = inspect.getclasstree([cls[1] for cls in classes], 1)
        self.assertEqual(tree,
                         [(mod.ParrotDroppings, ()),
                          (mod.StupidGit, ()),
                          [(mod.MalodorousPervert, (mod.StupidGit,)),
                           [(mod.FesteringGob, (mod.MalodorousPervert,
                                                   mod.ParrotDroppings))
                            ]
                           ]
                          ]) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:19,代碼來源:test_inspect.py

示例4: adapts

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getclasstree [as 別名]
def adapts(*args):
    """Class decorator for supporting adapts of interfaces."""

    def cls_adapts(cls):
        """Actually make class to implement the interfaces."""

        def inheritAdapts(cls, adapts):
            """Lookup the parents to inherit of adapts interfaces."""

            tree = inspect.getclasstree([cls])
            return _inherit(cls, '__adapts__', tree, adapts)


        adapts = inheritAdapts(cls, list(args))
        setattr(cls, '__adapts__', adapts)

        return cls

    return cls_adapts 
開發者ID:OfflineIMAP,項目名稱:imapfw,代碼行數:21,代碼來源:interface.py

示例5: implements

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getclasstree [as 別名]
def implements(*args):
    """Class decorator for supporting interfaces."""

    def cls_implements(cls):
        """Actually make class to implement the interfaces."""

        def inheritImplements(tree, implements):
            """Lookup the parents to inherit their interfaces."""

            tree = inspect.getclasstree([cls])
            return _inherit(cls, '__implements__', tree, implements)


        interfaces = inheritImplements(cls, list(args))
        setattr(cls, '__implements__', interfaces)

        return cls

    return cls_implements 
開發者ID:OfflineIMAP,項目名稱:imapfw,代碼行數:21,代碼來源:interface.py

示例6: _ensureCompatLoaded

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getclasstree [as 別名]
def _ensureCompatLoaded():
    if not _versionsMap:

        def flattenClassTree(tree):
            root = tree[0][0]
            assert isinstance(root, type), root
            yield root
            if len(tree) > 1:
                assert len(tree) == 2
                rest = tree[1]
                assert isinstance(rest, list), rest
                for c in flattenClassTree(rest):
                    yield c

        classes = []
        regex = re.compile(r'^MxCompatibility[0-9a-z]*$')
        for name, clazz in inspect.getmembers(sys.modules[__name__], inspect.isclass):
            m = regex.match(name)
            if m:
                classes.append(clazz)

        previousVersion = None
        for clazz in flattenClassTree(inspect.getclasstree(classes)):
            if clazz == object:
                continue
            assert previousVersion is None or previousVersion < clazz.version()
            previousVersion = clazz.version()
            _versionsMap[previousVersion] = clazz() 
開發者ID:graalvm,項目名稱:mx,代碼行數:30,代碼來源:mx_compat.py


注:本文中的inspect.getclasstree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。