def insert_hyphens(node, hyphenator):
 textattrs = (u'text', u'tail')
 if isinstance(node, lxml.etree._Entity):
  textattrs = (u'tail',)
 for attr in textattrs:
  text = getattr(node, attr)
  if (not text):
   continue
  new_data = u' '.join([hyphenator.inserted(w, hyphen=u'\xad') for w in text.split(u' ')])
  if text[0].isspace():
   new_data = (u' ' + new_data)
  if text[(-1)].isspace():
   new_data += u' '
  setattr(node, attr, new_data)
 for child in node.iterchildren():
  insert_hyphens(child, hyphenator)

def insert_hyphens ( node , hyphenator ) : textattrs = ( u'text' , u'tail' ) if isinstance ( node , lxml . etree . _Entity ) : textattrs = ( u'tail' , ) for attr in textattrs : text = getattr ( node , attr ) if ( not text ) : continue new_data = u' ' . join ( [ hyphenator . inserted ( w , hyphen = u'\xad' ) for w in text . split ( u' ' ) ] ) if text [ 0 ] . isspace ( ) : new_data = ( u' ' + new_data ) if text [ ( - 1 ) ] . isspace ( ) : new_data += u' ' setattr ( node , attr , new_data ) for child in node . iterchildren ( ) : insert_hyphens ( child , hyphenator )
insert hyphens into a node .