<s> import gettext <EOL> _ = gettext . gettext <EOL> import _base <EOL> class TreeWalker ( _base . NonRecursiveTreeWalker ) : <EOL> """<STR_LIT>""" <EOL> def getNodeDetails ( self , node ) : <EOL> if isinstance ( node , tuple ) : <EOL> parent , idx , parents = node <EOL> node = parent . childNodes [ idx ] <EOL> if node . type in ( <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> return ( _base . DOCUMENT , ) <EOL> elif node . type == <NUM_LIT:3> : <EOL> return _base . DOCTYPE , node . name , node . publicId , node . systemId <EOL> elif node . type == <NUM_LIT:4> : <EOL> return _base . TEXT , node . value <EOL> elif node . type == <NUM_LIT:5> : <EOL> attrs = { } <EOL> for name , value in node . attributes . items ( ) : <EOL> if isinstance ( name , tuple ) : <EOL> attrs [ ( name [ <NUM_LIT:2> ] , name [ <NUM_LIT:1> ] ) ] = value <EOL> else : <EOL> attrs [ ( None , name ) ] = value <EOL> return ( _base . ELEMENT , node . namespace , node . name , <EOL> attrs , node . hasContent ( ) ) <EOL> elif node . type == <NUM_LIT:6> : <EOL> return _base . COMMENT , node . data <EOL> else : <EOL> return _node . UNKNOWN , node . type <EOL> def getFirstChild ( self , node ) : <EOL> if isinstance ( node , tuple ) : <EOL> parent , idx , parents = node <EOL> parents . append ( ( parent , idx ) ) <EOL> node = parent . childNodes [ idx ] <EOL> else : <EOL> parents = [ ] <EOL> assert node . hasContent ( ) , "<STR_LIT>" <EOL> return ( node , <NUM_LIT:0> , parents ) <EOL> def getNextSibling ( self , node ) : <EOL> assert isinstance ( node , tuple ) , "<STR_LIT>" + str ( node ) <EOL> parent , idx , parents = node <EOL> idx += <NUM_LIT:1> <EOL> if len ( parent . childNodes ) > idx : <EOL> return ( parent , idx , parents ) <EOL> else : <EOL> return None <EOL> def getParentNode ( self , node ) : <EOL> assert isinstance ( node , tuple ) <EOL> parent , idx , parents = node <EOL> if parents : <EOL> parent , idx = parents . pop ( ) <EOL> return parent , idx , parents <EOL> else : <EOL> return None </s>
