Skip to content

Instantly share code, notes, and snippets.

@sophacles
Created August 24, 2010 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sophacles/548410 to your computer and use it in GitHub Desktop.
Save sophacles/548410 to your computer and use it in GitHub Desktop.
class N(object): # analogous to a Task class
def __init__(self, func):
self.run = func
self.a = ":("
self.b = ":("
self.c = ":("
self.d = ":("
def __call__(self, *args, **kw):
print 'N WRAPPED a:', self.a, 'b:', self.b, 'c:', self.c, 'd:', self.d
return self.run(*args, **kw)
def decodeco(f): #super meta decorator decorator
print 'A'
def inner(g):
print 'B'
if not isinstance(g, N):
return f(N(g))
else:
return f(g)
return inner
def deco(a,b):#similar to say... @hosts or @roles
print 'C'
@decodeco
def real_deco(f):
print 'D'
f.a = a
f.b = b
return f
return real_deco
def deco2(a, b): # similar to say... @hosts
print 'E'
@decodeco
def real_deco(f):
print 'F'
f.c = a
f.d = b
return f
return real_deco
@decodeco
def deco3(f): #similar to say... @default
f.c = 'x'
f.d = 'y'
return f
#@deco2('c','d')
@deco('a','b')
@deco3
def f(x, y): # a task
print "i am f! x:", x, "y:", y
f('x','y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment