<s> import ElementTree <EOL> class TreeBuilder : <EOL> def __init__ ( self , html = <NUM_LIT:0> ) : <EOL> try : <EOL> import sgmlop <EOL> except ImportError : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . __builder = ElementTree . TreeBuilder ( ) <EOL> if html : <EOL> import htmlentitydefs <EOL> self . entitydefs . update ( htmlentitydefs . entitydefs ) <EOL> self . __parser = sgmlop . XMLParser ( ) <EOL> self . __parser . register ( self ) <EOL> def feed ( self , data ) : <EOL> self . __parser . feed ( data ) <EOL> def close ( self ) : <EOL> self . __parser . close ( ) <EOL> self . __parser = None <EOL> return self . __builder . close ( ) <EOL> def finish_starttag ( self , tag , attrib ) : <EOL> self . __builder . start ( tag , attrib ) <EOL> def finish_endtag ( self , tag ) : <EOL> self . __builder . end ( tag ) <EOL> def handle_data ( self , data ) : <EOL> self . __builder . data ( data ) </s>
