def get_db_connection(path, timeout=30, okay_to_create=False):
 try:
  connect_time = time.time()
  conn = sqlite3.connect(path, check_same_thread=False, factory=GreenDBConnection, timeout=timeout)
  if ((path != ':memory:') and (not okay_to_create)):
   stat = os.stat(path)
   if ((stat.st_size == 0) and (stat.st_ctime >= connect_time)):
    os.unlink(path)
    raise DatabaseConnectionError(path, 'DB file created by connect?')
  conn.row_factory = sqlite3.Row
  conn.text_factory = str
  with closing(conn.cursor()) as cur:
   cur.execute('PRAGMA synchronous = NORMAL')
   cur.execute('PRAGMA count_changes = OFF')
   cur.execute('PRAGMA temp_store = MEMORY')
   cur.execute('PRAGMA journal_mode = DELETE')
  conn.create_function('chexor', 3, chexor)
 except sqlite3.DatabaseError:
  import traceback
  raise DatabaseConnectionError(path, traceback.format_exc(), timeout=timeout)
 return conn

def get_db_connection ( path , timeout = 30 , okay_to_create = False ) : try : connect_time = time . time ( ) conn = sqlite3 . connect ( path , check_same_thread = False , factory = GreenDBConnection , timeout = timeout ) if ( ( path != ':memory:' ) and ( not okay_to_create ) ) : stat = os . stat ( path ) if ( ( stat . st_size == 0 ) and ( stat . st_ctime >= connect_time ) ) : os . unlink ( path ) raise DatabaseConnectionError ( path , 'DB file created by connect?' ) conn . row_factory = sqlite3 . Row conn . text_factory = str with closing ( conn . cursor ( ) ) as cur : cur . execute ( 'PRAGMA synchronous = NORMAL' ) cur . execute ( 'PRAGMA count_changes = OFF' ) cur . execute ( 'PRAGMA temp_store = MEMORY' ) cur . execute ( 'PRAGMA journal_mode = DELETE' ) conn . create_function ( 'chexor' , 3 , chexor ) except sqlite3 . DatabaseError : import traceback raise DatabaseConnectionError ( path , traceback . format_exc ( ) , timeout = timeout ) return conn
returns a properly configured sqlite database connection .