def dbid_to_obj(inp, objclass, raise_errors=True):
    """
    Convert a #dbid to a valid object.

    Args:
        inp (str or int): A valid dbref.
        objclass (class): A valid django model to filter against.
        raise_errors (bool, optional): Whether to raise errors
            or return `None` on errors.

    Returns:
        obj (Object or None): An entity loaded from the dbref.

    Raises:
        Exception: If `raise_errors` is `True` and
            `objclass.objects.get(id=dbref)` did not return a valid
            object.

    """
    dbid = dbref(inp)
    if not dbid:
        # we only convert #dbrefs
        return inp
    try:
        if int(inp) < 0:
            return None
    except __HOLE__:
        return None

    # if we get to this point, inp is an integer dbref; get the matching object
    try:
        return objclass.objects.get(id=inp)
    except Exception:
        if raise_errors:
            raise
        return inp
dataset/ETHPy150Open evennia/evennia/evennia/utils/utils.py/dbid_to_obj