#NEWLINE# def dbid_to_obj( inp , objclass , raise_errors = True ) : #NEWLINE# #INDENT# '\n    Convert a #dbid to a valid object.\n\n    Args:\n        inp (str or int): A valid dbref.\n        objclass (class): A valid django model to filter against.\n        raise_errors (bool, optional): Whether to raise errors\n            or return `None` on errors.\n\n    Returns:\n        obj (Object or None): An entity loaded from the dbref.\n\n    Raises:\n        Exception: If `raise_errors` is `True` and\n            `objclass.objects.get(id=dbref)` did not return a valid\n            object.\n\n    ' #NEWLINE# dbid = dbref ( inp ) #NEWLINE# if ( not dbid ) : #NEWLINE# #INDENT# return inp #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( int ( inp ) < 0 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# return objclass . objects . get ( id = inp ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# if raise_errors : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# return dbid