def _replace_node(node, replace_node):
 prev_node = node.getprevious()
 parent_node = node.getparent()
 node_tail = (node.tail or '')
 if isinstance(replace_node, basestring):
  if (prev_node is not None):
   prev_text = (prev_node.tail or '')
   prev_node.tail = ((prev_text + replace_node) + node_tail)
  elif (parent_node is not None):
   parent_text = (parent_node.text or '')
   parent_node.text = ((parent_text + replace_node) + node_tail)
 else:
  replace_node.tail = node_tail
  node.addprevious(replace_node)
 if (parent_node is not None):
  parent_node.remove(node)

def _replace_node ( node , replace_node ) : prev_node = node . getprevious ( ) parent_node = node . getparent ( ) node_tail = ( node . tail or '' ) if isinstance ( replace_node , basestring ) : if ( prev_node is not None ) : prev_text = ( prev_node . tail or '' ) prev_node . tail = ( ( prev_text + replace_node ) + node_tail ) elif ( parent_node is not None ) : parent_text = ( parent_node . text or '' ) parent_node . text = ( ( parent_text + replace_node ) + node_tail ) else : replace_node . tail = node_tail node . addprevious ( replace_node ) if ( parent_node is not None ) : parent_node . remove ( node )
a utility method for replacing a node with another node .