def creat_nd(tree, *args): dflt = calc_next_id(tree) _id = eftl.optional_arg(dflt, *args) if (_id < 0): raise (ValueError('_id must >=0')) else: nd = { "_id": _id, "_fstch": None, } nd["_guid"] = cmmn.gen_guid() return (nd)
def indent(code,*args,**kwargs): ''' ''' indent = eftl.optional_arg(" ",*args) indent = (" "*indent) if(isinstance(indent,int)) else indent line_sp = '\n' lines = code.split(line_sp) ncode = '' length = lines.__len__() for i in range(0,length-1): line = indent + lines[i] + line_sp ncode = ncode + line ncode = ncode + indent + lines[length-1] return(ncode)
def creat_root(*args): _id = eftl.optional_arg(0, *args) if (_id < 0): raise (ValueError('root _id must >=0')) else: r = { "_id": _id, "_fstch": None, "_lsib": None, "_rsib": None, "_parent": None, "_tree": _id } r["_guid"] = cmmn.gen_guid() return (r)
def append_child(tree, nd, *args): dflt = creat_nd(tree) child = eftl.optional_arg(dflt, *args) child["_tree"] = nd["_tree"] child["_rsib"] = None cond = is_leaf(nd) if (cond): nd["_fstch"] = child["_id"] child["_lsib"] = None else: old_lstch = get_lstch(tree, nd) del old_lstch["_parent"] old_lstch["_rsib"] = child["_id"] child["_parent"] = nd["_id"] tree[child["_id"]] = child return (child)
def creat_tru_fls_mat(cnl, *args): rl = eftl.optional_arg([True, False], *args) count = len(cnl) m = product(rl, count) return (m)
def init_wfsmat(*args,**kwargs): r = eftl.optional_arg(init_root(),*args) orig_data = eftl.dflt_kwargs('orig_data',undefined,**kwargs) m = Wfsmat([[r]]) m._orig_data = orig_data return(m)
def add_method_to_inst(inst, func, *args): fname = eftl.optional_arg(func.__name__, *args) f = types.MethodType(func, inst) inst.__setattr__(fname, f) return (inst)