Skip to content

Instantly share code, notes, and snippets.

@AndresMWeber
Last active March 10, 2017 22:45
Show Gist options
  • Save AndresMWeber/b4c79069078b4ad25ccf4109a4a73b95 to your computer and use it in GitHub Desktop.
Save AndresMWeber/b4c79069078b4ad25ccf4109a4a73b95 to your computer and use it in GitHub Desktop.
Function wrap and Register example
class Registry(object):
pass
def register_wrapper(func):
print 'adding function %s to registry.' % func.__name__
setattr(Registry, func.__name__, classmethod(func))
return func
def wrapper(**kwargs_outer):
print 'in outside wrapper with kwargs', kwargs_outer
def decorator(f):
print 'in decorator with function', f.__name__
def final_wrap(*args, **kwargs):
kwargs_final = kwargs.update(kwargs_outer)
print 'in wrapped function with args, kwargs and function', args, kwargs, f.__name__
print 'input outer kwargs is ', kwargs_outer
return curve_builder(f(), *args, **kwargs)
return final_wrap
return decorator
def curve_builder(positions, *args, **kwargs):
print 'curve_builder: ', kwargs, args
return 'curve is degree %d and positions'%kwargs.get('degree', 1), positions
@register_wrapper
@wrapper(test=1)
def curve_info():
return [[0,1,0],[0,0,0]]
print 'normal curve_info', curve_info(mess=4)
#print 'Registry.test: ', Registry.test()
#print 'Registry.test2: ', Registry.test2()()
print [func for func in dir(Registry) if not func.startswith('__')]
print 'running the whole shebang!!!!!', Registry.final_wrap()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment