本文整理匯總了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()