Skip to content

Instantly share code, notes, and snippets.

@adammck
Created September 29, 2008 13:59
Show Gist options
  • Save adammck/13604 to your computer and use it in GitHub Desktop.
Save adammck/13604 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# vim: noet
def keyword(regex):
def decorator(meth):
def wrapper(*args, **kwargs):
print "in wrapper func"
meth(*args, **kwargs)
return wrapper
return decorator
class Test():
@keyword("^alpha (\w+)$")
def alpha(self, a):
pass
@keyword("^beta (\d+)$")
def beta(self, a):
pass
@keyword("^gamma (\w+) (\d+)$")
def gamma(self, a, b):
pass
def dispatch(self, str):
# how can i match "str" with t.beta?
pass
t = Test()
t.dispatch("beta 123")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment