SQLite3 Context Manager
          
            
            
            
        context manager class for SQLite3 db connection
class SQLite():
    ''' Class is a wrapper for sqlite3 context manager. 
        Returs sqlite3.connection().cursor object ready to execute query
        Usage: with SQLite() as c:
                  c.execute('SELECT * FROM table')
    '''
    def __init__(self, db):
        self.db = db
    def __enter__(self):
        self.conn = sqlite3.connect(self.db)
        return self.conn.cursor()
    def __exit__(self, type, value, traceback):
        self.conn.commit()
        self.conn.close()