def findNodeJustBefore(target, nodes):
 while (target is not None):
  node = target.previousSibling
  while (node is not None):
   if (node in nodes):
    return node
   node = node.previousSibling
  target = target.parentNode
 raise RuntimeError('Oops')

def findNodeJustBefore ( target , nodes ) : while ( target is not None ) : node = target . previousSibling while ( node is not None ) : if ( node in nodes ) : return node node = node . previousSibling target = target . parentNode raise RuntimeError ( 'Oops' )
find the last element which is a sibling of c{target} and is in c{nodes} .