fork(1) download
  1. import types
  2. def F1(func):
  3. def wrapped(*args, **kwargs):
  4. print "Called with args", args
  5. print "Called with kwargs", kwargs
  6. if isinstance(func, types.FunctionType):
  7. # We are the last decorator to execute before the function
  8. print "We executed right before test."
  9. return func(*args)
  10. print "Chainging down to the next decorator"
  11. return func(*args, **kwargs)
  12. return wrapped
  13.  
  14.  
  15. @F1
  16. @F1
  17. @F1
  18. def test(a,b):
  19. return a + b
  20.  
  21. print test(1,2,check=True)
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
Called with args (1, 2)
Called with kwargs {'check': True}
We executed right before test.
Called with args (1, 2)
Called with kwargs {}
We executed right before test.
Called with args (1, 2)
Called with kwargs {}
We executed right before test.
3