human
Complete this python program:
def connect(dbn, **kw):
assistant
#Here is the Python program 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
        kw['password'] = kw['pw']
        del kw['pw']
        kw['database'] = kw['db']
        del kw['db']
    elif (dbn == 'mysql'):
        import MySQLdb as db
        kw['passwd'] = kw['pw']
        del kw['pw']
        db.paramstyle = 'pyformat'
    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, **kw)
        ctx.db = globals()['db'].connection()
    else:
        ctx.db = db.connect(**kw)
    ctx.dbq_count = 0
    if globals().get('db_printing'):
        def db_execute(cur, q, d=None):
            ctx.dbq_count += 1
            try:
                outq = (q % tuple(d))
            except:
                outq = q
            print >>debug, (str(ctx.dbq_count) + ':'), outq
            a = time.time()
            out = cur.execute(q, d)
            b = time.time()
            print >>debug, ('(%s)' % round((b - a), 2))
            return out
        ctx.db_execute = db_execute
    else:
        ctx.db_execute = (lambda cur, q, d=None: cur.execute(q, d))
    return ctx.db