#NEWLINE# def generate_getconn( engine , user , password , host , port , dbname , dirname = None ) : #NEWLINE# #INDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( engine == 'mysql' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import MySQLdb #NEWLINE# assert ( MySQLdb is not None ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# import pymysql_sa #NEWLINE# pymysql_sa . make_default_mysql_dialect ( ) #NEWLINE# #UNINDENT# kwargs [ 'client_flag' ] = 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( engine == 'sqlite' ) : #NEWLINE# #INDENT# kwargs [ 'timeout' ] = 90 #NEWLINE# if ( dbname == ':memory:' ) : #NEWLINE# #INDENT# kwargs [ 'check_same_thread' ] = False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# import sqlalchemy.dialects as dialects #NEWLINE# __import__ ( ( 'sqlalchemy.dialects.%s' % engine ) ) #NEWLINE# dbi = getattr ( dialects , engine ) . base . dialect . dbapi ( ) #NEWLINE# if ( engine == 'sqlite' ) : #NEWLINE# #INDENT# def getconn_sqlite( ) : #NEWLINE# #INDENT# return dbi . connect ( database = get_sqlite_dbname ( dbname , dirname ) , ** kwargs ) #NEWLINE# #UNINDENT# getconn = getconn_sqlite #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# def getconn_else( ) : #NEWLINE# #INDENT# kwargs . update ( dict ( user = user , passwd = password , host = host , db = dbname ) ) #NEWLINE# if ( port is not None ) : #NEWLINE# #INDENT# kwargs [ 'port' ] = port #NEWLINE# #UNINDENT# return dbi . connect ( ** kwargs ) #NEWLINE# #UNINDENT# getconn = getconn_else #NEWLINE# #UNINDENT# return getconn