human
Complete this python program:
def connect(dbn, **keywords):
assistant
#Here is the Python code you requested.

    """Connects to the specified database.
    db currently must be "postgres" or "mysql".
    If DBUtils is installed, connection pooling will be used.
    """
    if (dbn == 'postgres'):
        try:
            import psycopg2 as db
        except ImportError:
            try:
                import psycopg as db
            except ImportError:
                import pgdb as db
        keywords['password'] = keywords['pw']
        del keywords['pw']
        keywords['database'] = keywords['db']
        del keywords['db']
    elif (dbn == 'mysql'):
        import MySQLdb as db
        keywords['passwd'] = keywords['pw']
        del keywords['pw']
        db.paramstyle = 'pyformat'
    elif (dbn == 'sqlite'):
        try:
            from pysqlite2 import dbapi2 as db
            db.paramstyle = 'qmark'
        except ImportError:
            import sqlite as db
        keywords['database'] = keywords['db']
        del keywords['db']
    else:
        raise UnknownDB, dbn
    ctx.db_name = dbn
    ctx.db_module = db
    ctx.db_transaction = False
    if _hasPooling:
        if ('db' not in globals()):
            globals()['db'] = PooledDB(dbapi=db, **keywords)
        ctx.db = globals()['db'].connection()
    else:
        ctx.db = db.connect(**keywords)
    ctx.dbq_count = 0
    if globals().get('db_printing'):
        def db_execute(cur, sql_query, d=None):
            'executes    an    sql    query'
            ctx.dbq_count += 1
            try:
                outq = (sql_query % tuple(d))
            except TypeError:
                outq = sql_query
            print >>debug, (str(ctx.dbq_count) + ':'), outq
            a = time.time()
            out = cur.execute(sql_query, d)
            b = time.time()
            print >>debug, ('(%s)' % round((b - a), 2))
            return out
        ctx.db_execute = db_execute
    else:
        ctx.db_execute = (lambda cur, sql_query, d=None: cur.execute(sql_query, d))
    return ctx.db