def func_wrapper(func, level, *vargs, static=False, prop=False, prop_type="fget", **kwargs): import arjuna from arjuna import log_error name = func.__name__ qualname = func.__qualname__ level = name.startswith("_") and "debug" or level log_call = getattr(arjuna, "log_{}".format(level.strip().lower())) if name != qualname and not static: pvargs = vargs[1:] else: pvargs = vargs if prop: msg_1 = prop_dict_msg[prop_type][0] msg_2 = prop_dict_msg[prop_type][1].format(pvargs, kwargs) log_call("{} {}{}".format(qualname, msg_1, msg_2)) else: log_call("{}:: Started with args {} and kwargs {}.".format(qualname, pvargs, kwargs)) ret = None try: ret = func(*vargs, **kwargs) except Exception as e: import traceback log_error("{}:: Exception: {}. Trace: {}".format(qualname, e, traceback.format_exc())) raise else: if prop: msg_1 = prop_dict_msg[prop_type][0] msg_3 = prop_dict_msg[prop_type][2].format(ret) log_call("{}:: Finished.{}".format(qualname, msg_3, msg_3)) else: log_call("{}:: Finished. Returning: {}".format(qualname, ret)) return ret
def format_args(self, name, vargs, kwargs): if not self.has_locator(name): raise Exception( "No WithX locator with name {} found.".format(name)) # Critical to create a copy fmt = copy.deepcopy(self.__xdict[name]) if kwargs: repl_dict = {k.lower(): v for k, v in kwargs.items()} else: repl_dict = {} try: return fmt["wtype"], _format(fmt["wvalue"], vargs, repl_dict) # if fmt["wtype"] in {'ATTR', 'FATTR', 'BATTR', 'EATTR', 'NODE', 'BNODE', 'FNODE'}: # out = dict() # for k,v in fmt["wvalue"].items(): # if type(v) in {list, tuple}: # out[_format(k, repl_dict)] = [_format(v_entry, repl_dict) for v_entry in v] # else: # out[_format(k, repl_dict)] = _format(v, repl_dict) # #out[k.format(**kwargs)] = v.format(**kwargs) # return fmt["wtype"], out # else: # return fmt["wtype"], _format(["wvalue"], repl_dict) #fmt["wvalue"].format(*vargs, **kwargs) except Exception as e: from arjuna import log_error log_error( f"Error in processing withx {name} : {fmt} for vargs {vargs} and kwargs {kwargs}" ) raise
def format_args(self, name, vargs, kwargs): if not self.has_locator(name): raise Exception("No WithX locator with name {} found.".format(name)) # Critical to create a copy fmt = copy.deepcopy(self.__xdict[name]) try: if fmt["wtype"] in {'ATTR', 'FATTR'}: for k,v in fmt["wvalue"].items(): fmt["wvalue"][k] = v.format(**kwargs) return fmt["wtype"], fmt["wvalue"] else: return fmt["wtype"], fmt["wvalue"].format(*vargs, **kwargs) except Exception as e: from arjuna import log_error log_error(f"Error in processing withx {name} : {fmt} for vargs {vargs} and kwargs {kwargs}") raise