#NEWLINE# def __init__( self , path ) : #NEWLINE# #INDENT# tokens = xpath_tokenizer ( tag ) #NEWLINE# self . path = [ ] #NEWLINE# self . tag = None #NEWLINE# if ( tokens and ( tokens [ 0 ] [ 0 ] == '/' ) ) : #NEWLINE# #INDENT# raise SyntaxError ( 'cannot use absolute path on element' ) #NEWLINE# #UNINDENT# while tokens : #NEWLINE# #INDENT# ( op , tag ) = tokens . pop ( 0 ) #NEWLINE# if ( tag or ( op == '*' ) ) : #NEWLINE# #INDENT# self . path . append ( ( tag or op ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( op == '.' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( op == '/' ) : #NEWLINE# #INDENT# self . path . append ( xpath_descendant_or_self ( ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise SyntaxError ( ( 'unsupported path syntax (%s)' % op ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if tokens : #NEWLINE# #INDENT# ( op , tag ) = tokens . pop ( 0 ) #NEWLINE# if ( op != '/' ) : #NEWLINE# #INDENT# raise SyntaxError ( ( 'expected path separator (%s)' % ( op or tag ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( self . path and isinstance ( self . path [ ( - 1 ) ] , xpath_descendant_or_self ) ) : #NEWLINE# #INDENT# raise SyntaxError ( 'path cannot end with //' ) #NEWLINE# #UNINDENT# if ( ( len ( self . path ) == 1 ) and isinstance ( self . path [ 0 ] , type ( '' ) ) ) : #NEWLINE# #INDENT# self . tag = self . path [ 0 ]