[docs]defraise_attrerror_from_property(prop,obj,exc):""" Because the exception calls some methods for better error reporting, those methods could be inside of unstable objects, so the call itself is wrapped """_,_,traceback=sys.exc_info()try:msg=str(exc)+" (within declarative.property named {0} of {1})".format(prop.__name__,repr(obj))exceptException:msg=str(exc)+" (within declarative.property named {0})".format(prop.__name__)raise_from_with_traceback(PropertyAttributeError(msg),cause=exc,traceback=traceback,)
[docs]deftry_name_file_line(func):""" Trashes current exception """d=dict()try:d["filename"]=func.__code__.co_filenameexceptException:d["filename"]="<unknown>"try:d["lineno"]=func.__code__.co_firstlinenoexceptException:d["lineno"]="<unknown>"returnd
[docs]defraise_msg_from_property(msg,t_exc,prop,obj,old_exc=None,if_from_file=None,**kwargs):""" """_,_,traceback=sys.exc_info()# print("FILE FROM: ", tb_mod.extract_tb(traceback)[-1][0])# raiseifif_from_fileisnotNoneand(tb_mod.extract_tb(traceback)[-1][0]!=if_from_file):returnFalsed=dict(name=prop.__name__)try:d["orepr"]=repr(obj)exceptException:d["orepr"]="<object of {0}>".format(obj.__class__.__name__)d.update(**kwargs)msg=msg.format(**d)raise_from_with_traceback(t_exc(msg),cause=old_exc,traceback=traceback,)