#NEWLINE# def RenderFiltered( self , filter_func , args , token ) : #NEWLINE# #INDENT# fd = aff4 . FACTORY . Open ( 'aff4:/hunts' , mode = 'r' , token = token ) #NEWLINE# children = list ( fd . ListChildren ( ) ) #NEWLINE# children . sort ( key = operator . attrgetter ( 'age' ) , reverse = True ) #NEWLINE# if ( not args . active_within ) : #NEWLINE# #INDENT# raise ValueError ( 'active_within filter has to be used when any kind of filtering is done (to prevent queries of death)' ) #NEWLINE# #UNINDENT# min_age = ( rdfvalue . RDFDatetime ( ) . Now ( ) - args . active_within ) #NEWLINE# active_children = [ ] #NEWLINE# for child in children : #NEWLINE# #INDENT# if ( child . age > min_age ) : #NEWLINE# #INDENT# active_children . append ( child ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# index = 0 #NEWLINE# hunt_list = [ ] #NEWLINE# active_children_map = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for hunt in fd . OpenChildren ( children = active_children ) : #NEWLINE# #INDENT# if ( ( not isinstance ( hunt , hunts . GRRHunt ) ) or ( not hunt . state ) or ( not filter_func ( hunt ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# active_children_map [ hunt . urn ] = hunt #NEWLINE# #UNINDENT# for urn in active_children : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# hunt = active_children_map [ urn ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( index >= args . offset ) : #NEWLINE# #INDENT# hunt_list . append ( hunt ) #NEWLINE# #UNINDENT# index += 1 #NEWLINE# if ( args . count and ( len ( hunt_list ) >= args . count ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return ApiListHuntsResult ( items = self . _RenderHuntList ( hunt_list ) )