Skip to content

Instantly share code, notes, and snippets.

@berserker1

berserker1/wrapper.py

Last active Aug 22, 2019
Embed
What would you like to do?
def dbconnection(function):
"""Decorator for getting at the database connection.
Use this to avoid having to access the global `config.db.store`
attribute. This calls the function with `store` as the first argument.
"""
def wrapper(*args, **kws):
# args[0] is self, if there is one.
if len(args) > 0:
return function(args[0], config.db.store, *args[1:], **kws)
else:
return function(config.db.store, **kws)
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment