<s> """<STR_LIT>""" <EOL> import time <EOL> import mysql_conf as conf <EOL> class DatabaseManager ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , database_env = '<STR_LIT:test>' , conf_creds = None ) : <EOL> """<STR_LIT>""" <EOL> import MySQLdb <EOL> db_server , db_user , db_pass , db_schema = conf . APP_CREDS [ conf . Apps . TESTCASE_REPOSITORY ] [ database_env ] <EOL> retry_count = <NUM_LIT:3> <EOL> backoff = <NUM_LIT> <EOL> count = <NUM_LIT:0> <EOL> while count < retry_count : <EOL> try : <EOL> self . conn = MySQLdb . connect ( host = db_server , <EOL> user = db_user , <EOL> passwd = db_pass , <EOL> db = db_schema ) <EOL> self . conn . autocommit ( True ) <EOL> self . cursor = self . conn . cursor ( ) <EOL> return <EOL> except Exception : <EOL> time . sleep ( backoff ) <EOL> count = count + <NUM_LIT:1> <EOL> if retry_count == <NUM_LIT:3> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def fetchall_query_and_close ( self , query , values ) : <EOL> """<STR_LIT>""" <EOL> self . cursor . execute ( query , values ) <EOL> retval = self . cursor . fetchall ( ) <EOL> self . __close_db ( ) <EOL> return retval <EOL> def fetchone_query_and_close ( self , query , values ) : <EOL> """<STR_LIT>""" <EOL> self . cursor . execute ( query , values ) <EOL> retval = self . cursor . fetchone ( ) <EOL> self . __close_db ( ) <EOL> return retval <EOL> def execute_query_and_close ( self , query , values ) : <EOL> """<STR_LIT>""" <EOL> retval = self . cursor . execute ( query , values ) <EOL> self . __close_db ( ) <EOL> return retval <EOL> def __close_db ( self ) : <EOL> self . cursor . close ( ) <EOL> self . conn . close ( ) </s>
