#NEWLINE# def _process_filters( self , filters ) : #NEWLINE# #INDENT# 'Takes a list of filters and returns ES JSON API\n\n        :arg filters: list of F, (key, val) tuples, or dicts\n\n        :returns: list of ES JSON API filters\n\n        ' #NEWLINE# rv = [ ] #NEWLINE# for f in filters : #NEWLINE# #INDENT# if isinstance ( f , F ) : #NEWLINE# #INDENT# if f . filters : #NEWLINE# #INDENT# rv . extend ( self . _process_filters ( f . filters ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( f , dict ) : #NEWLINE# #INDENT# if six . PY3 : #NEWLINE# #INDENT# key = list ( f . keys ( ) ) [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key = f . keys ( ) [ 0 ] #NEWLINE# #UNINDENT# val = f [ key ] #NEWLINE# key = key . strip ( '_' ) #NEWLINE# if ( key not in ( 'or' , 'and' , 'not' , 'filter' ) ) : #NEWLINE# #INDENT# raise InvalidFieldActionError ( ( '%s is not a valid connector' % f . keys ( ) [ 0 ] ) ) #NEWLINE# #UNINDENT# if ( 'filter' in val ) : #NEWLINE# #INDENT# filter_filters = self . _process_filters ( val [ 'filter' ] ) #NEWLINE# if ( len ( filter_filters ) == 1 ) : #NEWLINE# #INDENT# filter_filters = filter_filters [ 0 ] #NEWLINE# #UNINDENT# rv . append ( { #NEWLINE# #INDENT# key : { #NEWLINE# #INDENT# 'filter' : filter_filters , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rv . append ( { #NEWLINE# #INDENT# key : self . _process_filters ( val ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ( key , val ) = f #NEWLINE# ( key , field_action ) = split_field_action ( key ) #NEWLINE# handler_name = 'process_filter_{0}' . format ( field_action ) #NEWLINE# if ( field_action and hasattr ( self , handler_name ) ) : #NEWLINE# #INDENT# rv . append ( getattr ( self , handler_name ) ( key , val , field_action ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( key . strip ( '_' ) in ( 'or' , 'and' , 'not' ) ) : #NEWLINE# #INDENT# connector = key . strip ( '_' ) #NEWLINE# rv . append ( { #NEWLINE# #INDENT# connector : self . _process_filters ( val . items ( ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_action is None ) : #NEWLINE# #INDENT# if ( val is None ) : #NEWLINE# #INDENT# rv . append ( { #NEWLINE# #INDENT# 'missing' : { #NEWLINE# #INDENT# 'field' : key , #NEWLINE# 'null_value' : True , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rv . append ( { #NEWLINE# #INDENT# 'term' : { #NEWLINE# #INDENT# key : val , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_action in ( 'startswith' , 'prefix' ) ) : #NEWLINE# #INDENT# rv . append ( { #NEWLINE# #INDENT# 'prefix' : { #NEWLINE# #INDENT# key : val , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_action == 'in' ) : #NEWLINE# #INDENT# rv . append ( { #NEWLINE# #INDENT# 'in' : { #NEWLINE# #INDENT# key : val , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_action in RANGE_ACTIONS ) : #NEWLINE# #INDENT# rv . append ( { #NEWLINE# #INDENT# 'range' : { #NEWLINE# #INDENT# key : { #NEWLINE# #INDENT# field_action : val , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_action == 'range' ) : #NEWLINE# #INDENT# ( lower , upper ) = val #NEWLINE# rv . append ( { #NEWLINE# #INDENT# 'range' : { #NEWLINE# #INDENT# key : { #NEWLINE# #INDENT# 'gte' : lower , #NEWLINE# 'lte' : upper , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_action == 'distance' ) : #NEWLINE# #INDENT# ( distance , latitude , longitude ) = val #NEWLINE# rv . append ( { #NEWLINE# #INDENT# 'geo_distance' : { #NEWLINE# #INDENT# 'distance' : distance , #NEWLINE# key : [ longitude , latitude ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise InvalidFieldActionError ( ( '%s is not a valid field action' % field_action ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return rv