return self.scopefunc()
-def constructor_args(instance, **kwargs):
- """given an object instance and keyword arguments, inspects the
- argument signature of the instance's __init__ method and returns
- a tuple of list and keyword arguments, suitable for creating a new
- instance of the class. The returned arguments are drawn from the
- given keyword dictionary, or if not found are drawn from the
- corresponding attributes of the original instance."""
- classobj = instance.__class__
-
- argspec = inspect.getargspec(classobj.__init__.im_func)
-
- argnames = argspec[0] or []
- defaultvalues = argspec[3] or []
-
- (requiredargs, namedargs) = (
- argnames[0:len(argnames) - len(defaultvalues)],
- argnames[len(argnames) - len(defaultvalues):]
- )
-
- newparams = {}
-
- for arg in requiredargs:
- if arg == 'self':
- continue
- elif kwargs.has_key(arg):
- newparams[arg] = kwargs[arg]
- else:
- newparams[arg] = getattr(instance, arg)
-
- for arg in namedargs:
- if kwargs.has_key(arg):
- newparams[arg] = kwargs[arg]
- else:
- if hasattr(instance, arg):
- newparams[arg] = getattr(instance, arg)
- else:
- raise AssertionError("instance has no attribute '%s'" % arg)
-
- return newparams
-