utils.py
branchstable
changeset 3882 addc715f4fcd
parent 3851 3a18a0a24411
child 3890 d7a270f50f54
child 3902 a0efb0326021
equal deleted inserted replaced
3881:a192bc3c13b7 3882:addc715f4fcd
   144 def merge_dicts(dict1, dict2):
   144 def merge_dicts(dict1, dict2):
   145     """update a copy of `dict1` with `dict2`"""
   145     """update a copy of `dict1` with `dict2`"""
   146     dict1 = dict(dict1)
   146     dict1 = dict(dict1)
   147     dict1.update(dict2)
   147     dict1.update(dict2)
   148     return dict1
   148     return dict1
       
   149 
       
   150 
       
   151 # use networkX instead ?
       
   152 # http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
       
   153 def transitive_closure_of(entity, relname, _seen=None):
       
   154     if _seen is None:
       
   155         _seen = set()
       
   156     _seen.add(entity.eid)
       
   157     yield entity
       
   158     for child in getattr(entity, relname):
       
   159         if child.eid in _seen:
       
   160             continue
       
   161         for subchild in transitive_closure_of(child, relname, _seen):
       
   162             yield subchild
   149 
   163 
   150 
   164 
   151 class SizeConstrainedList(list):
   165 class SizeConstrainedList(list):
   152     """simple list that makes sure the list does not get bigger
   166     """simple list that makes sure the list does not get bigger
   153     than a given size.
   167     than a given size.