#NEWLINE# def __new__( cls , path ) : #NEWLINE# #INDENT# 'Construct new EPath. ' #NEWLINE# if isinstance ( path , EPath ) : #NEWLINE# #INDENT# return path #NEWLINE# #UNINDENT# if ( not path ) : #NEWLINE# #INDENT# raise ValueError ( 'empty EPath' ) #NEWLINE# #UNINDENT# _path = obj #NEWLINE# if ( path [ 0 ] == '/' ) : #NEWLINE# #INDENT# path = path [ 1 : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise NotImplementedError ( 'non-root EPath' ) #NEWLINE# #UNINDENT# epath = [ ] #NEWLINE# for selector in path . split ( '/' ) : #NEWLINE# #INDENT# selector = selector . strip ( ) #NEWLINE# if ( not selector ) : #NEWLINE# #INDENT# raise ValueError ( 'empty selector' ) #NEWLINE# #UNINDENT# index = 0 #NEWLINE# for c in selector : #NEWLINE# #INDENT# if ( c . isalnum ( ) or ( c == '_' ) or ( c == '|' ) or ( c == '?' ) ) : #NEWLINE# #INDENT# index += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# attrs = [ ] #NEWLINE# types = [ ] #NEWLINE# if index : #NEWLINE# #INDENT# elements = selector [ : index ] #NEWLINE# selector = selector [ index : ] #NEWLINE# for element in elements . split ( '|' ) : #NEWLINE# #INDENT# element = element . strip ( ) #NEWLINE# if ( not element ) : #NEWLINE# #INDENT# raise ValueError ( 'empty element' ) #NEWLINE# #UNINDENT# if element . endswith ( '?' ) : #NEWLINE# #INDENT# attrs . append ( element [ : ( - 1 ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# types . append ( element ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# span = None #NEWLINE# if ( selector == '*' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if selector . startswith ( '[' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# i = selector . index ( ']' ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise ValueError ( "expected ']', got EOL" ) #NEWLINE# #UNINDENT# ( _span , span ) = ( selector [ 1 : i ] , [ ] ) #NEWLINE# if ( ':' not in _span ) : #NEWLINE# #INDENT# span = int ( _span ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for elt in _span . split ( ':' , 3 ) : #NEWLINE# #INDENT# if ( not elt ) : #NEWLINE# #INDENT# span . append ( None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# span . append ( int ( elt ) ) #NEWLINE# #UNINDENT# #UNINDENT# span = slice ( * span ) #NEWLINE# #UNINDENT# selector = selector [ ( i + 1 ) : ] #NEWLINE# #UNINDENT# if selector : #NEWLINE# #INDENT# raise ValueError ( 'trailing characters in selector' ) #NEWLINE# #UNINDENT# #UNINDENT# epath . append ( ( attrs , types , span ) ) #NEWLINE# #UNINDENT# obj = object . __new__ ( cls ) #NEWLINE# obj . _path = _path #NEWLINE# obj . _epath = epath #NEWLINE# return obj