defsafe_jinja(s): s = s.replace('(', '').replace(')', '') blacklist = ['config', 'self'] return''.join(['{{% set {}=None%}}'.format(c) for c in blacklist]) + s
elif isinstance(obj, type): if obj in visited_clss: return visited_clss.append(obj) print(obj)
else: if obj in visited_objs: return visited_objs.append(obj) # attributes for name in dir(obj): if name.startswith('__') and name.endswith('__'): if name notin ('__globals__', '__class__', '__self__', '__weakref__', '__objclass__', '__module__'): continue attr = getattr(obj, name) yieldfrom visit(attr, '{}.{}'.format(path, name), depth + 1) # dict values if hasattr(obj, 'items') and callable(obj.items): try: for k, v in obj.items(): yieldfrom visit(v, '{}[{}]'.format(path, repr(k)), depth) except: pass # items elif isinstance(obj, (set, list, tuple, frozenset)): for i, v in enumerate(obj): yieldfrom visit(v, '{}[{}]'.format(path, repr(i)), depth) yieldfrom visit(obj)