def getTreeWalker(treeType, implementation=None, **kwargs):
 treeType = treeType.lower()
 if (treeType not in treeWalkerCache):
  if (treeType in ('dom', 'pulldom', 'simpletree')):
   mod = __import__(treeType, globals())
   treeWalkerCache[treeType] = mod.TreeWalker
  elif (treeType == 'genshi'):
   import genshistream
   treeWalkerCache[treeType] = genshistream.TreeWalker
  elif (treeType == 'beautifulsoup'):
   import soup
   treeWalkerCache[treeType] = soup.TreeWalker
  elif (treeType == 'lxml'):
   import lxmletree
   treeWalkerCache[treeType] = lxmletree.TreeWalker
  elif (treeType == 'etree'):
   import etree
   return etree.getETreeModule(implementation, **kwargs).TreeWalker
 return treeWalkerCache.get(treeType)

def getTreeWalker ( treeType , implementation = None , ** kwargs ) : treeType = treeType . lower ( ) if ( treeType not in treeWalkerCache ) : if ( treeType in ( 'dom' , 'pulldom' , 'simpletree' ) ) : mod = __import__ ( treeType , globals ( ) ) treeWalkerCache [ treeType ] = mod . TreeWalker elif ( treeType == 'genshi' ) : import genshistream treeWalkerCache [ treeType ] = genshistream . TreeWalker elif ( treeType == 'beautifulsoup' ) : import soup treeWalkerCache [ treeType ] = soup . TreeWalker elif ( treeType == 'lxml' ) : import lxmletree treeWalkerCache [ treeType ] = lxmletree . TreeWalker elif ( treeType == 'etree' ) : import etree return etree . getETreeModule ( implementation , ** kwargs ) . TreeWalker return treeWalkerCache . get ( treeType )
get a treewalker class for various types of tree with built-in support treetype - the name of the tree type required .