#NEWLINE# def getDBConnector( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# configFile = 'config.xml' #NEWLINE# tree = ET . parse ( configFile ) #NEWLINE# root = tree . getroot ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# sys . exit ( 'Not a valid config XML file' ) #NEWLINE# #UNINDENT# for settings in root . findall ( './db' ) : #NEWLINE# #INDENT# for dbip in settings . findall ( './ip' ) : #NEWLINE# #INDENT# db_ip = dbip . text #NEWLINE# #UNINDENT# for dbname in settings . findall ( './db_name' ) : #NEWLINE# #INDENT# db_name = dbname . text #NEWLINE# #UNINDENT# for dbuser in settings . findall ( './user' ) : #NEWLINE# #INDENT# db_user = dbuser . text #NEWLINE# #UNINDENT# for dbpass in settings . findall ( './password' ) : #NEWLINE# #INDENT# db_pass = dbpass . text #NEWLINE# #UNINDENT# #UNINDENT# cnx = mysql . connector . connect ( user = db_user , password = db_pass , host = db_ip , database = db_name ) #NEWLINE# return cnx