def filter_entries(c_from, entries, options_map, context): """Filter the entries by the given compiled FROM clause. Args: c_from: A compiled From clause instance. entries: A list of directives. options_map: A parser's option_map. context: A prototype of RowContext to use for evaluation. Returns: A list of filtered entries. """ assert c_from is None or isinstance(c_from, query_compile.EvalFrom) assert isinstance(entries, list) context = copy.copy(context) if c_from is None: return entries # Process the OPEN clause. if c_from.open is not None: assert isinstance(c_from.open, datetime.date) open_date = c_from.open entries, index = summarize.open_opt(entries, open_date, options_map) # Process the CLOSE clause. if c_from.close is not None: if isinstance(c_from.close, datetime.date): close_date = c_from.close entries, index = summarize.close_opt(entries, close_date, options_map) elif c_from.close is True: entries, index = summarize.close_opt(entries, None, options_map) # Process the CLEAR clause. if c_from.clear is not None: entries, index = summarize.clear_opt(entries, None, options_map) # Filter the entries with the FROM clause's expression. c_expr = c_from.c_expr if c_expr is not None: # A simple function receives a context; how come close_date() is # accepted in the context of a FROM clause? It shouldn't be. new_entries = [] for entry in entries: context.entry = entry if c_expr(context): new_entries.append(entry) entries = new_entries return entries
def filter_entries(c_from, entries, options_map): """Filter the entries by the given compiled FROM clause. Args: c_from: A compiled From clause instance. entries: A list of directives. options_map: A parser's option_map. Returns: A list of filtered entries. """ assert c_from is None or isinstance(c_from, query_compile.EvalFrom) assert isinstance(entries, list) if c_from is None: return entries # Process the OPEN clause. if c_from.open is not None: assert isinstance(c_from.open, datetime.date) open_date = c_from.open entries, index = summarize.open_opt(entries, open_date, options_map) # Process the CLOSE clause. if c_from.close is not None: if isinstance(c_from.close, datetime.date): close_date = c_from.close entries, index = summarize.close_opt(entries, close_date, options_map) elif c_from.close is True: entries, index = summarize.close_opt(entries, None, options_map) # Process the CLEAR clause. if c_from.clear is not None: entries, index = summarize.clear_opt(entries, None, options_map) # Filter the entries with the FROM clause's expression. c_expr = c_from.c_expr if c_expr is not None: entries = [entry for entry in entries if c_expr(entry)] return entries
def do_close(self, entries, date, *args): return summarize.close_opt(entries, date, self.options_map)