本文整理汇总了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
示例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
示例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))
]
]
])
示例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
示例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
示例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()