Skip to content

Instantly share code, notes, and snippets.

@mharju
Created June 7, 2012 06:22
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 mharju/2886880 to your computer and use it in GitHub Desktop.
Save mharju/2886880 to your computer and use it in GitHub Desktop.
Demo
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