Created
June 7, 2012 06:22
-
-
Save mharju/2886880 to your computer and use it in GitHub Desktop.
Demo
This file contains 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
from functools import wraps | |
def db(selector): | |
def _funcall(function): | |
@wraps(function) | |
def _wrapper(row): | |
got_args = { | |
'primary': { '1': ('baba', 15), '2': ('gaga', 16) }, | |
'secondary': { '1': ('foo', 17), '2': ('bar', 18) }, | |
} | |
return function(*got_args[selector][row]) | |
return _wrapper | |
return _funcall | |
def foo(a, b): | |
print "Gots me", a, b | |
foo_db = db('primary')(foo) | |
foo_db_sec = db('secondary')(foo) | |
foo_db('1') | |
foo_db('2') | |
foo_db_sec('1') | |
foo_db_sec('2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment