@contextlib.contextmanager<EOL>def db_connect(connection_string=None, **kwargs):
if connection_string is None:<EOL><INDENT>connection_string = get_current_registry().settings[CONNECTION_STRING]<EOL><DEDENT>db_conn = psycopg2.connect(connection_string, **kwargs)<EOL>try:<EOL><INDENT>with db_conn:<EOL><INDENT>yield db_conn<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>db_conn.close()<EOL><DEDENT>
Function to supply a database connection object.