Created
September 29, 2008 13:59
-
-
Save adammck/13604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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