def connect(dbhandle, attach=None):
    """attempt to connect to database.

    If `dbhandle` is an existing connection to a database,
    it will be returned unchanged. Otherwise, this method
    will attempt to establish a connection.

    Arguments
    ---------
    dbhandle : object or string
        A database handle or a connection string.

    Returns
    -------
    dbhandle : object
        A DB-API2 conforming database handle
    """
    if type(dbhandle) is str:
        try:
            import sqlite3
        except __HOLE__:
            raise ValueError(
                "If an sqlite database location is passed"
                " directly the sqlite3 module must be installed")

        dbhandle = sqlite3.connect(dbhandle)

    cc = dbhandle.cursor()

    if attach is not None:
        if type(attach) is str:
            db_execute(cc, attach)
        elif isinstance(attach, (tuple, list)):
            for attach_statement in attach:
                db_execute(cc, attach_statement)

    return dbhandle
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Database.py/connect