def adjust_split_point(split_point, log):
 sp = split_point
 while True:
  parent = sp.getparent()
  if ((parent is None) or (barename(parent.tag) in {u'body', u'html'}) or (parent.text and parent.text.strip()) or (parent.index(sp) > 0)):
   break
  sp = parent
 if (sp is not split_point):
  log.debug(u'Adjusted split point to ancestor')
 return sp

def adjust_split_point ( split_point , log ) : sp = split_point while True : parent = sp . getparent ( ) if ( ( parent is None ) or ( barename ( parent . tag ) in { u'body' , u'html' } ) or ( parent . text and parent . text . strip ( ) ) or ( parent . index ( sp ) > 0 ) ) : break sp = parent if ( sp is not split_point ) : log . debug ( u'Adjusted split point to ancestor' ) return sp
move the split point up its ancestor chain if it has no content before it .