@contextmanager
def transaction(path_or_connection, mode=None):
    'A context manager that yields a cursor that runs in an\n    isolated transaction. If the context manager exits without\n    errors, the transaction is committed. If an exception is\n    raised, all changes are rolled-back.\n    '
    if isinstance(path_or_connection, sqlite3.Connection):
        connection = path_or_connection
        connection_close = (lambda : None)
    else:
        connection = connect(path_or_connection, mode=mode)
        connection_close = connection.close
    cursor = connection.cursor()
    try:
        with savepoint(cursor):
            (yield cursor)
    finally:
        cursor.close()
        connection_close()
A context manager that yields a cursor that runs in an
isolated transaction. If the context manager exits without
errors, the transaction is committed. If an exception is
raised, all changes are rolled-back.
@contextmanager
def transaction(path_or_connection, mode=None):
    'A context manager that yields a cursor that runs in an\n    isolated transaction. If the context manager exits without\n    errors, the transaction is committed. If an exception is\n    raised, all changes are rolled-back.\n    '
    if isinstance(path_or_connection, sqlite3.Connection):
        connection = path_or_connection
        connection_close = (lambda : None)
    else:
        connection = connect(path_or_connection, mode=mode)
        connection_close = connection.close
    cursor = connection.cursor()
    try:
        with savepoint(cursor):
            (yield cursor)
    finally:
        cursor.close()
        connection_close()