def getTreeBuilder(treeType, implementation=None, **kwargs):
 treeType = treeType.lower()
 if (treeType not in treeBuilderCache):
  if (treeType == 'dom'):
   import dom
   if (implementation == None):
    from xml.dom import minidom
    implementation = minidom
   return dom.getDomModule(implementation, **kwargs).TreeBuilder
  elif (treeType == 'simpletree'):
   import simpletree
   treeBuilderCache[treeType] = simpletree.TreeBuilder
  elif (treeType == 'beautifulsoup'):
   import soup
   treeBuilderCache[treeType] = soup.TreeBuilder
  elif (treeType == 'lxml'):
   import etree_lxml
   treeBuilderCache[treeType] = etree_lxml.TreeBuilder
  elif (treeType == 'etree'):
   if (implementation == None):
    try:
     import xml.etree.cElementTree as ET
    except ImportError:
     try:
      import xml.etree.ElementTree as ET
     except ImportError:
      try:
       import cElementTree as ET
      except ImportError:
       import elementtree.ElementTree as ET
    implementation = ET
   import etree
   return etree.getETreeModule(implementation, **kwargs).TreeBuilder
  else:
   raise ValueError(('Unrecognised treebuilder "%s" ' % treeType))
 return treeBuilderCache.get(treeType)

def getTreeBuilder ( treeType , implementation = None , ** kwargs ) : treeType = treeType . lower ( ) if ( treeType not in treeBuilderCache ) : if ( treeType == 'dom' ) : import dom if ( implementation == None ) : from xml . dom import minidom implementation = minidom return dom . getDomModule ( implementation , ** kwargs ) . TreeBuilder elif ( treeType == 'simpletree' ) : import simpletree treeBuilderCache [ treeType ] = simpletree . TreeBuilder elif ( treeType == 'beautifulsoup' ) : import soup treeBuilderCache [ treeType ] = soup . TreeBuilder elif ( treeType == 'lxml' ) : import etree_lxml treeBuilderCache [ treeType ] = etree_lxml . TreeBuilder elif ( treeType == 'etree' ) : if ( implementation == None ) : try : import xml . etree . cElementTree as ET except ImportError : try : import xml . etree . ElementTree as ET except ImportError : try : import cElementTree as ET except ImportError : import elementtree . ElementTree as ET implementation = ET import etree return etree . getETreeModule ( implementation , ** kwargs ) . TreeBuilder else : raise ValueError ( ( 'Unrecognised treebuilder "%s" ' % treeType ) ) return treeBuilderCache . get ( treeType )
get a treebuilder class for various types of tree with built-in support treetype - the name of the tree type required .