def initialize_engine_object(engine, endpoint, apikey=None, username=None, password=None, request=None):
    """
    Initialize a DatasetEngine object from a string that points at the engine class.
    """
    # Constants
    HYDROSHARE_OAUTH_PROVIDER_NAME = 'hydroshare'

    # Derive import parts from engine string
    engine_split = engine.split('.')
    module_string = '.'.join(engine_split[:-1])
    engine_class_string = engine_split[-1]

    # Import
    module = __import__(module_string, fromlist=[engine_class_string])
    EngineClass = getattr(module, engine_class_string)

    # Get Token for HydroShare interactions
    if EngineClass is HydroShareDatasetEngine:
        user = request.user

        try:
            # social = user.social_auth.get(provider='google-oauth2')
            social = user.social_auth.get(provider=HYDROSHARE_OAUTH_PROVIDER_NAME)
            apikey = social.extra_data['access_token']
        except __HOLE__:
            # User is not associated with that provider
            # Need to prompt for association
            raise AuthException("HydroShare authentication required. To automate the authentication prompt decorate "
                                "your controller function with the @ensure_oauth('hydroshare') decorator.")
        except AttributeError:
            # Anonymous User...
            raise
        except AuthAlreadyAssociated:
            raise
        except:
            raise

    # Create Engine Object
    engine_instance = EngineClass(endpoint=endpoint,
                                  apikey=apikey,
                                  username=username,
                                  password=password)
    return engine_instance
dataset/ETHPy150Open tethysplatform/tethys/tethys_services/utilities.py/initialize_engine_object