def _remove_deactivated(contexts):
 stack_contexts = tuple([h for h in contexts[0] if h.active])
 head = contexts[1]
 while ((head is not None) and (not head.active)):
  head = head.old_contexts[1]
 ctx = head
 while (ctx is not None):
  parent = ctx.old_contexts[1]
  while (parent is not None):
   if parent.active:
    break
   ctx.old_contexts = parent.old_contexts
   parent = parent.old_contexts[1]
  ctx = parent
 return (stack_contexts, head)

def _remove_deactivated ( contexts ) : stack_contexts = tuple ( [ h for h in contexts [ 0 ] if h . active ] ) head = contexts [ 1 ] while ( ( head is not None ) and ( not head . active ) ) : head = head . old_contexts [ 1 ] ctx = head while ( ctx is not None ) : parent = ctx . old_contexts [ 1 ] while ( parent is not None ) : if parent . active : break ctx . old_contexts = parent . old_contexts parent = parent . old_contexts [ 1 ] ctx = parent return ( stack_contexts , head )
remove deactivated handlers from the chain .