提供访问对象引用(子对象)的API。

sw.objectinspection的Python项目详细描述


软件对象检查

objectinspection是一个工具,它为您提供了一个要检查的通用api 对象的属性及其子对象。它有两个 基本检查员(BasicAttributesInspectorBasicChildrenInspector) 可以很容易地用你自己的检查员代替。

设置

创建一些稍后检查的对象:

>>> class Child1(object):
...     pass
>>> class Child2(object):
...     pass
>>> class Child3(object):
...     pass
>>> class Child4(object):
...     misc = Child1()
>>> class ToInspect(object):
...     some_var = ["some tupel", (Child2(), Child3())]
...     other_var = {"foo": "bar"}
...     _private_var = 10
...     desc = Child4()
...
...     def some_method(self):
...         pass

检查属性

通过适应IAttributesInspector,获得AttributesInspector

>>> from sw.objectinspection import IAttributesInspector
>>> inspector = IAttributesInspector(ToInspect())

因为注册的ToInspect对象没有专门的检查器, 使用BasicAttributesInspector

>>> inspector
<sw.objectinspection.BasicAttributesInspector object at 0x11f69d0
 used for ToInspect object at 0x11f6910>

要开始检查,只需致电检查员:

>>> inspector()
['desc', 'other_var', 'some_var']

儿童检查

检查子项的工作方式与检查属性的工作方式相同:

>>> from sw.objectinspection import IChildrenInspector
>>> inspector = IChildrenInspector(ToInspect())
>>> inspector
<sw.objectinspection.BasicChildrenInspector object at 0x11f6a10
 used for ToInspect object at 0x11f6910>
>>> sorted(inspector())
[<Child2 object at 0x119cc10>,
 <Child3 object at 0x11f5790>,
 <Child4 object at 0x11f5830>]

编写自己的检查员

您可以编写自己的检查器并将其注册为比 此软件包附带的基本功能:

>>> from sw.objectinspection import BasicInspector
>>> import zope.component
>>> import zope.interface
>>> class DummyAttributesInspector(BasicInspector):
...     zope.component.adapts(ToInspect)
...     zope.interface.implements(IAttributesInspector)
...
...     def __call__(self):
...         # The object, which is to be inspected, can be accessed
...         # with self._inspecting
...         return ['foo', 'bar']
>>> gsm = zope.component.getGlobalSiteManager()
>>> gsm.registerAdapter(DummyAttributesInspector)

现在,当检查属性时,我们得到 DummyAttributesInspector

>>> inspector = IAttributesInspector(ToInspect())
>>> inspector
<DummyAttributesInspector object at 0x11f69d0
 used for ToInspect object at 0x11f6910>
>>> inspector()
['foo', 'bar']

更改

1.0.1(2009-08-13)

  • 修复运行Windows的系统的内存地址检查程序。

1.0(2009-07-29)

  • 初次发布。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在通配符泛型类型和泛型类型之间未经检查的强制转换   java Eclipse SWT Hello world教程:无法将显示解析为类型   java如何向远程用户发送注销消息?   java RDD之后的空文件是什么。保存ASTEXTFILE?   用户界面在java中创建一个htmljs UI GCalendar   Java多个哈希映射指向同一个键   Java Dowhile循环不工作?   oraclejava类。组织。阿帕奇。梁sdk。util。UserCodeException:java。sql。SQLException:无法创建PoolableConnectionFactory   java是org类型。日食用户界面。文本编辑器。*看不见   java有没有从弹出窗口复制eclipse中变量值的插件或快捷方式?   java getSubimage为我提供了期望值null   java我想让它变得更简单   swing AWTEventQueue0一直在运行,java中的程序变得非常慢   java Solr实例化类时出错:自定义类   java将ListView适配器移植到RecyclerView适配器   c#测试混合web和桌面应用程序的安全性