当前位置: 首页>>代码示例>>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;未经允许,请勿转载。