2
# wrapper.py: Small class to wrap an object, instantiated from a class
3
# or generated by a module.
5
# ===================================================================
6
# The contents of this file are dedicated to the public domain. To
7
# the extent that dedication to the public domain is not available,
8
# everyone is granted a worldwide, perpetual, royalty-free,
9
# non-exclusive license to exercise all rights associated with the
10
# contents of this file for any purpose whatsoever.
11
# No rights are reserved.
13
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
# ===================================================================
24
__all__ = [ 'Wrapper' ]
28
Wrapper for an object, instantiated from a class
29
or from a call to a new() function in a module.
31
def __init__(self, wrapped, *args):
33
wrapped is either a class or a module with a new() function.
35
if hasattr(wrapped, 'new'):
36
self._wrapped = wrapped.new(*args)
38
self._wrapped = wrapped(*args)
40
def __getattr__(self, name):
42
return getattr(getattr(self,'_wrapped'),name)
43
except AttributeError:
44
if hasattr(self, name):
45
return getattr(self,name)