Пример #1
0
def simplegroupby(wrappers, modules = False, threads = False, classes = False):
    """Assign each object in wrappers to a module, thread or class.
    The values of "modules", "threads" and "classes" control whether those are
    included (for example, having modules = True, threads = classes = False
    will assign each object to a module only).
    
    Returns a dictionary mapping from module ID or id(noGroup)
    to module object.
    
    Also sets "group" and "time" fields for each object, and "members" for 
    each module."""

    def constfalse(w):
        return False
    
    if modules:
        def ismodule(w):
            return type(w.obj) is types.ModuleType
    else:
        ismodule = constfalse
        
    if threads:
        # threadlist is a list of id(thread)
        threadlist = map(id, rules.roots())
        def isthread(w):
            return id(w) in threadlist
    else:
        isthread = constfalse
        
    if classes:
        def isclass(w):
            # Check for old-style classes, modules and frames
            if type(w.obj) is types.InstanceType or type(w.obj) is types.ClassType \
            or type(w.obj) is types.ModuleType or type(w.obj) is types.FrameType:
                return True
    
            # This is the code that scanner.py uses to check for new-style classes
            try:
                attr_obj = w.obj.__getattribute__
                attr = type(w.obj).__getattribute__
                if attr == object.__getattribute__ or attr == type.__getattribute__:
                    return True
            except AttributeError:
                return False
            
            return False
    else:
        isclass = constfalse
        
    def isgroup(w):
        return ismodule(w) or isthread(w) or isclass(w)
    
    return groupby(wrappers, operations.filterd(wrappers, isgroup))
Пример #2
0
 def __init__(self, obj = rules.roots(), objs = None, head = None,
              verbosity = default, flags = None):
     if objs is None:
         objs = scan(obj, verbosity)
     if head is None:
         head = objs[id(obj)]
     if flags is None:
         flags = {}
         
     wrapper.ignored.__init__(self)        
     dict.__init__(self, objs)
     self.head = head
     self.flags = {}