示例#1
0
文件: TCommon.py 项目: melviso/beatle
 def inner(self, t, self_include=True):
     """Search through ancestors the first ancestor of some type"""
     import app
     if self_include:
         if (type(t) is list and app.isclass(type(self), *t)) or app.isclass(type(self), t):
             return self
     return self._parent and self._parent.inner(t)
示例#2
0
文件: TCommon.py 项目: melviso/beatle
    def __call__(self, *args, **kwargs):
        """___call__(type1,...,typeN, filter=lambda x: True, cut=False):
        Returns the list of nested childs of one of the types.

        filter: indicates a boolean filter method that must
                return True for valid elements.

        cut: stops traveling if filter is unsatisfied?
        """
        import app
        r = []
        fn = kwargs.get('filter', lambda x: True)
        cut = kwargs.get('cut', False)
        for k in self._child:
            if app.isclass(k, *args):
                r.extend(filter(fn, self[k]))
            if cut:
                for o in filter(fn, self[k]):
                    r.extend(o(*args, **kwargs))
            else:
                for o in self[k]:
                    r.extend(o(*args, **kwargs))
        return r