def _immediately_before(node):
 try:
  pos = node.treeposition()
  tree = node.root()
 except AttributeError:
  return []
 idx = (len(pos) - 1)
 while ((0 <= idx) and (pos[idx] == 0)):
  idx -= 1
 if (idx < 0):
  return []
 pos = list(pos[:(idx + 1)])
 pos[(-1)] -= 1
 before = tree[pos]
 return ([before] + _rightmost_descendants(before))

def _immediately_before ( node ) : try : pos = node . treeposition ( ) tree = node . root ( ) except AttributeError : return [ ] idx = ( len ( pos ) - 1 ) while ( ( 0 <= idx ) and ( pos [ idx ] == 0 ) ) : idx -= 1 if ( idx < 0 ) : return [ ] pos = list ( pos [ : ( idx + 1 ) ] ) pos [ ( - 1 ) ] -= 1 before = tree [ pos ] return ( [ before ] + _rightmost_descendants ( before ) )
returns the set of all nodes that are immediately before the given node .