#NEWLINE# def _parse_slice( pattern ) : #NEWLINE# #INDENT# 'Return a slice() instance for a string:slice:pattern.' #NEWLINE# if ( ( pattern == ':' ) or ( pattern == '::' ) ) : #NEWLINE# #INDENT# return ( SLICE , slice ( None ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ':' not in pattern ) : #NEWLINE# #INDENT# if ( not pattern . startswith ( '-' ) ) : #NEWLINE# #INDENT# return ( NAME , pattern ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# offset = int ( pattern ) #NEWLINE# if ( offset == ( - 1 ) ) : #NEWLINE# #INDENT# return ( SLICE , slice ( offset , None ) ) #NEWLINE# #UNINDENT# return ( SLICE , slice ( offset , ( offset + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# segs = pattern . split ( ':' , 2 ) #NEWLINE# start = ( ( segs [ 0 ] and int ( segs [ 0 ] ) ) or 0 ) #NEWLINE# stop = ( ( segs [ 1 ] and int ( segs [ 1 ] ) ) or None ) #NEWLINE# if ( len ( segs ) < 3 ) : #NEWLINE# #INDENT# return ( SLICE , slice ( start , stop ) ) #NEWLINE# #UNINDENT# stride = ( ( segs [ 2 ] and int ( segs [ 2 ] ) ) or 1 ) #NEWLINE# if ( not segs [ 0 ] ) : #NEWLINE# #INDENT# start = None #NEWLINE# #UNINDENT# return ( SLICE , slice ( start , stop , stride ) )