#NEWLINE# def parse( self , query_str ) : #NEWLINE# #INDENT# avg_over_match = '^([0-9]*)(s|M|h|d|w|mo)$' #NEWLINE# def parse_val( query_str , predicate_match , value_match , value_default = None ) : #NEWLINE# #INDENT# match = re . search ( ( '\\b(%s%s)' % ( predicate_match , value_match ) ) , query_str ) #NEWLINE# value = value_default #NEWLINE# if ( match and ( match . groups ( ) > 0 ) ) : #NEWLINE# #INDENT# value = match . groups ( 1 ) [ 0 ] . replace ( predicate_match , '' ) #NEWLINE# query_str = ( query_str [ : match . start ( 1 ) ] + query_str [ match . end ( 1 ) : ] ) #NEWLINE# #UNINDENT# return ( query_str , value ) #NEWLINE# #UNINDENT# if ( '||' in query_str ) : #NEWLINE# #INDENT# ( query_str , _ , self [ 'events_query' ] ) = query_str . partition ( '||' ) #NEWLINE# #UNINDENT# ( query_str , self [ 'statement' ] ) = parse_val ( query_str , '^' , '(graph|list|stack|lines)\\b' , self [ 'statement' ] ) #NEWLINE# self [ 'statement' ] = self [ 'statement' ] . rstrip ( ) #NEWLINE# ( query_str , self [ 'to' ] ) = parse_val ( query_str , 'to ' , '[^ ]+' , self [ 'to' ] ) #NEWLINE# ( query_str , self [ 'from' ] ) = parse_val ( query_str , 'from ' , '[^ ]+' , self [ 'from' ] ) #NEWLINE# ( query_str , group_by_str ) = parse_val ( query_str , 'GROUP BY ' , '[^ ]+' ) #NEWLINE# ( query_str , extra_group_by_str ) = parse_val ( query_str , 'group by ' , '[^ ]+' ) #NEWLINE# ( query_str , sum_by_str ) = parse_val ( query_str , 'sum by ' , '[^ ]+' ) #NEWLINE# ( query_str , avg_by_str ) = parse_val ( query_str , 'avg by ' , '[^ ]+' ) #NEWLINE# ( query_str , avg_over_str ) = parse_val ( query_str , 'avg over ' , '[^ ]+' ) #NEWLINE# ( query_str , min_str ) = parse_val ( query_str , 'min ' , '[^ ]+' ) #NEWLINE# ( query_str , max_str ) = parse_val ( query_str , 'max ' , '[^ ]+' ) #NEWLINE# explicit_group_by = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( group_by_str is not None ) : #NEWLINE# #INDENT# explicit_group_by = Query . build_buckets ( group_by_str ) #NEWLINE# self [ 'group_by' ] = explicit_group_by #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( extra_group_by_str is not None ) : #NEWLINE# #INDENT# for k in self [ 'group_by' ] . keys ( ) : #NEWLINE# #INDENT# if ( not k . endswith ( '=' ) ) : #NEWLINE# #INDENT# del self [ 'group_by' ] [ k ] #NEWLINE# #UNINDENT# #UNINDENT# explicit_group_by = Query . build_buckets ( extra_group_by_str ) #NEWLINE# self [ 'group_by' ] . update ( explicit_group_by ) #NEWLINE# #UNINDENT# #UNINDENT# if ( sum_by_str is not None ) : #NEWLINE# #INDENT# self [ 'sum_by' ] = Query . build_buckets ( sum_by_str ) #NEWLINE# #UNINDENT# if ( avg_by_str is not None ) : #NEWLINE# #INDENT# self [ 'avg_by' ] = Query . build_buckets ( avg_by_str ) #NEWLINE# #UNINDENT# if ( min_str is not None ) : #NEWLINE# #INDENT# convert . parse_str ( min_str ) #NEWLINE# self [ 'min' ] = min_str #NEWLINE# #UNINDENT# if ( max_str is not None ) : #NEWLINE# #INDENT# convert . parse_str ( max_str ) #NEWLINE# self [ 'max' ] = max_str #NEWLINE# #UNINDENT# for tag in ( self [ 'sum_by' ] . keys ( ) + self [ 'avg_by' ] . keys ( ) ) : #NEWLINE# #INDENT# for tag_check in ( tag , ( '%s=' % tag ) ) : #NEWLINE# #INDENT# if ( ( tag_check in self [ 'group_by' ] ) and ( tag_check not in explicit_group_by . keys ( ) ) ) : #NEWLINE# #INDENT# del self [ 'group_by' ] [ tag_check ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( avg_over_str is not None ) : #NEWLINE# #INDENT# avg_over = re . match ( avg_over_match , avg_over_str ) #NEWLINE# if ( avg_over is not None ) : #NEWLINE# #INDENT# avg_over = avg_over . groups ( ) #NEWLINE# self [ 'avg_over' ] = ( int ( avg_over [ 0 ] ) , avg_over [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# ( query_str , self [ 'limit_targets' ] ) = parse_val ( query_str , 'limit ' , '[^ ]+' , self [ 'limit_targets' ] ) #NEWLINE# self [ 'limit_targets' ] = int ( self [ 'limit_targets' ] ) #NEWLINE# self [ 'patterns' ] += query_str . split ( )