Esempio n. 1
0
 def members(iterable):  # @IgnorePep8
     mro = getmro(iterable)
     names = iter(dir(iterable))
     beenthere = set()
     adder = beenthere.add
     try:
         OD = OrderedDict
         vz = vars
         cn = chain
         ga = getattr
         ic = isclass
         nx = next
         while 1:
             name = nx(names)
             # yes, it's really supposed to be a tuple
             for base in cn([iterable], mro):
                 var = vz(base)
                 if name in var:
                     obj = var[name]
                     break
             else:
                 obj = ga(iterable, name)
             if (name, obj) in beenthere:
                 continue
             else:
                 adder((name, obj))
             if ic(obj):
                 yield name, OD((k, v) for k, v in ifilter(
                     test, members(obj),
                 ))
             else:
                 yield name, obj
     except StopIteration:
         pass
Esempio n. 2
0
 def traverse(iterable):  # @IgnorePep8
     try:
         iterable = iter(iterable)
         OD = OrderedDict
         sn = selfname
         nx = next
         while 1:
             iterator = nx(iterable)
             chaining = ChainMap()
             chaining['classname'] = sn(iterator)
             cappend = chaining.maps.append
             for k, v in ifilter(test, members(iterator)):
                 if isinstance(v, OD):
                     v['classname'] = k
                     cappend(v)
                 else:
                     chaining[k] = v
             yield chaining
     except StopIteration:
         pass