def __iadd__(self, other): if is_non_str_itr(other): for o in other: self.objs.append(o) else: self.objs.append(other) return self
def toDict(self): import json d = self.__dict__ for k, value in d.items(): if isinstance(value, obj): d[k] = value.toDict() elif isinstsafe(value, JsonSerializable): d[k] = json.loads(value.to_json()) elif is_non_str_itr(value): # try: if not isinstance(value, dict) and len(arr(value).shape) == 0: d[k] = [] elif len(list(value)) > 0 and isinstance(list(value)[0], obj): d[k] = [v.toDict() for v in value] elif len(list(value)) > 0 and isinstsafe( list(value)[0], JsonSerializable): d[k] = [json.loads(v.to_json()) for v in value] # except: # breakpoint() return d
def recurse_rep_dict(d, o, n, use_is=False): c = 0 for k, v in listitems(d): if use_is: b = k is o else: b = k == o if b: d[n] = v del d[o] k = n c += 1 if is_non_str_itr(v): v, cc = recurse_rep_itr(v, o, n, use_is=use_is) c += cc if use_is: b = v is o else: b = v == o if b: d[k] = n c += 1 elif isdict(v): d[k], cc = recurse_rep_dict(v, o, n, use_is=use_is) c += cc return d, c
def __getitem__(self, k): r = self._d.__getitem__(k) if isdictsafe(r): r = RecursiveSubDictProxy(self, k, self.makeObjs) if self.makeObjs: r = ObjProxy(r) elif is_non_str_itr(r): r = RecursiveSubListProxy(self, k, self.makeObjs) if self.makeObjs: r = ObjProxy(r) return r
def command_list(*args): if len(args) == 0: return [''] elif len(args) > 1: return list(map(AbstractShell.com_arg, args)) elif is_non_str_itr(args[0]): return list(map(AbstractShell.com_arg, args[0])) elif isstr(args[0]): return listmap(AbstractShell.com_arg, args[0].split(' ')) else: return [AbstractShell.com_arg(args[0])]
def recurse_rep_itr(l, o, n, use_is=False): c = 0 for idx, e in enum(l): if is_non_str_itr(e): e, cc = recurse_rep_itr(e, o, n, use_is=use_is) c += cc if use_is: b = e is o else: b = e == o if b: l[idx] = n c += 1 elif isdict(e): l[idx], cc = recurse_rep_dict(e, o, n, use_is=use_is) c += cc return l, c