def and_operator(str, loc, toks): """ method to support logical 'and' operator expression """ # print str, loc, toks # print toks[0][0::2] and_filter = AndFilter() for op_filter in toks[0][0::2]: and_filter.child_add(op_filter) return and_filter
def handle_filter_max_component_limit(handle, l_filter): """ Method checks the filter count and if the filter count exceeds the max_components(number of filters), then the given filter objects get distributed among small groups and then again binded together in complex filters(like and , or) so that the count of filters can be reduced. """ from ucscore import AbstractFilter from ucsfiltertype import AndFilter, OrFilter max_components = 10 if l_filter is None or l_filter.child_count() <= max_components: return l_filter if not isinstance(l_filter, AndFilter) and not isinstance(l_filter, OrFilter): return l_filter result_filter = None if isinstance(l_filter, AndFilter): parent_filter = AndFilter() child_filter = AndFilter() parent_filter.child_add(child_filter) for childf in l_filter.GetChild(): if isinstance(childf, AbstractFilter): if child_filter.child_count() == max_components: child_filter = AndFilter() parent_filter.child_add(child_filter) child_filter.child_add(childf) result_filter = parent_filter else: parent_filter = OrFilter() child_filter = OrFilter() parent_filter.child_add(child_filter) for childf in l_filter.GetChild(): if isinstance(childf, AbstractFilter): if child_filter.child_count() == max_components: child_filter = OrFilter() parent_filter.child_add(child_filter) child_filter.child_add(childf) result_filter = parent_filter return handle_filter_max_component_limit(handle, result_filter)