3.1.8.7. c3po.services.wrapper module
Contain the functions buildWrappingClass() and wrapper().
- c3po.services.wrapper.buildWrappingClass(baseclass, objectAttr)
Return a wrapping class of baseclass.
The
__init__method of the returned class writes:def __init__(self, wrappedObject): self._wrappedObject = wrappedObject
_wrappedObjectis the only attribute of instances of the returned class.All methods of baseclass (inherited methods are also treated) are wrapped this way:
def methodA(self, *args, **kwargs): return self._wrappedObject.methodA(*args, **kwargs)
Instance attributes of the wrapped class can be provided using
objectAttr. They are made available in reading and writing using Python property.For example:
ClassAWrapper = c3po.buildWrappingClass(ClassA, ["toto"]) objectA = ClassA(...) wrapperA = ClassAWrapper(objectA)
Now,
wrapperA.totogives access to the same variable thanobjectA.totoorwrapperA._wrappedObject.toto.- Parameters:
baseclass – The class we want a wrapper for.
objectAttr (list) – List of the names of
baseclassinstance attributes for which you wish to retain direct access.
- Return type:
A wrapper class for baseclass.
- c3po.services.wrapper.wrapper(toWrap)
Return a wrapping object for
toWrap.wrapper()usesc3po.services.wrapper.buildWrappingClassin order to build a wrapping class fortoWraptype, and return an instance of this wrapping class (wrappingtoWrap).- Parameters:
toWrap – Object instance (not class) to be wrapped.
- Return type:
A wrapping object.