sw.objectinspection
ObjectInspection is a tool, that provides you with a generic API to inspect objects for their attributes and their children objects. It comes with two basic inspectors (BasicAttributesInspector and BasicChildrenInspector) which can be easily replaced with your own inspectors.
Setup
Create some objects, which are inspected later on:
>>> 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
Inspecting for attributes
Get the AttributesInspector by adapting to IAttributesInspector:
>>> from sw.objectinspection import IAttributesInspector >>> inspector = IAttributesInspector(ToInspect())
Because there is no specialized inspector for the ToInspect object registered, the BasicAttributesInspector is used:
>>> inspector <sw.objectinspection.BasicAttributesInspector object at 0x11f69d0 used for ToInspect object at 0x11f6910>
To start the inspection, simply call the inspector:
>>> inspector() ['desc', 'other_var', 'some_var']
Inspecting for children
Inspection for children works the same way like inspection for attributes:
>>> 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>]
Writing own inspectors
You can write your own inspector and register it as a more special adapter than the basic ones which come with this package:
>>> 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)
Now, when inspecting ToInspect for attributes, we get our DummyAttributesInspector:
>>> inspector = IAttributesInspector(ToInspect()) >>> inspector <DummyAttributesInspector object at 0x11f69d0 used for ToInspect object at 0x11f6910> >>> inspector() ['foo', 'bar']
CHANGES
1.0.1 (2009-08-13)
Fix the checker for the memory address for systems running windows.
1.0 (2009-07-29)
Initial release.
Metadata
Release files for sw.objectinspection 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sw.objectinspection-1.0.1.tar.gz | 6.2 kB | Without provenance | Details for sw.objectinspection-1.0.1.tar.gz |
Release files / sw.objectinspection-1.0.1.tar.gz
| Download URL | sw.objectinspection-1.0.1.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b1706b842ce031968bb38858eec9053a9ced316a755f1af78c77a264b6e6eea
|
|
BLAKE2b-256 checksum How to use checksums |
72870aa066ed3d1cce67d46e7cdb7c93f6177c6963e4014d6dc6922c2a137a1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sw.objectinspection 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.