#NEWLINE# @ app . route ( '/metrics/expand' , methods = methods ) #NEWLINE# def metrics_expand( ) : #NEWLINE# #INDENT# errors = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# group_by_expr = bool ( int ( RequestParams . get ( 'groupByExpr' , 0 ) ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# errors [ 'groupByExpr' ] = 'must be 0 or 1.' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# leaves_only = bool ( int ( RequestParams . get ( 'leavesOnly' , 0 ) ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# errors [ 'leavesOnly' ] = 'must be 0 or 1.' #NEWLINE# #UNINDENT# if ( 'query' not in RequestParams ) : #NEWLINE# #INDENT# errors [ 'query' ] = 'this parameter is required.' #NEWLINE# #UNINDENT# if errors : #NEWLINE# #INDENT# return jsonify ( { #NEWLINE# #INDENT# 'errors' : errors , #NEWLINE# #UNINDENT# } , status = 400 ) #NEWLINE# #UNINDENT# results = defaultdict ( set ) #NEWLINE# for query in RequestParams . getlist ( 'query' ) : #NEWLINE# #INDENT# for node in app . store . find ( query ) : #NEWLINE# #INDENT# if ( node . is_leaf or ( not leaves_only ) ) : #NEWLINE# #INDENT# results [ query ] . add ( node . path ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if group_by_expr : #NEWLINE# #INDENT# for ( query , matches ) in results . items ( ) : #NEWLINE# #INDENT# results [ query ] = sorted ( matches ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# new_results = set ( ) #NEWLINE# for value in results . values ( ) : #NEWLINE# #INDENT# new_results = new_results . union ( value ) #NEWLINE# #UNINDENT# results = sorted ( new_results ) #NEWLINE# #UNINDENT# return jsonify ( { #NEWLINE# #INDENT# 'results' : results , #NEWLINE# #UNINDENT# } )