def get_object_from_identifier(identifier, valid=None):
    """ Helper function to resolve an item identifier
        into a model instance.

        Raises StoreException if the identifier is invalid
        or the requested Model could not be found

        Raises <Model>.DoesNotExist if the object lookup fails

        Arguments (optional):

            valid
                One or more Django model classes to compare the
                returned model instance to.
    """
    try:
        model_str, pk = identifier.split('__')
    except __HOLE__:
        raise StoreException('Invalid identifier string')

    Model = get_model(*model_str.split('.'))
    if Model is None:
        raise StoreException('Model from identifier string "%s" not found' % model_str)

    if valid is not None:
        if not isinstance(valid, (list, tuple) ):
            valid = (valid,)
        if Model not in valid:
            raise StoreException('Model type mismatch')

    # This will raise Model.DoesNotExist if lookup fails
    return Model._default_manager.get(pk=pk)
dataset/ETHPy150Open klipstein/dojango/dojango/data/modelstore/utils.py/get_object_from_identifier