# HG changeset patch # User Paul Boddie # Date 1412445917 -7200 # Node ID 953c5b53d8accca1d2d517a2e8c77843a86e989e # Parent ea1c7b3a92cc466fac0852f9a2072fd230204f60 Propagate context information through selectors for pattern iterators; prevent the introduction of enumerations from datetime information that will unnecessarily constrain patterns. diff -r ea1c7b3a92cc -r 953c5b53d8ac vRecurrence.py --- a/vRecurrence.py Sat Oct 04 19:52:31 2014 +0200 +++ b/vRecurrence.py Sat Oct 04 20:05:17 2014 +0200 @@ -167,10 +167,7 @@ # Datetime value at wider resolution. if _pos < pos: - if have_q: - l.append(from_dt) - else: - context.append(from_dt.args["values"][0]) + context.append(from_dt.args["values"][0]) from_dt = get_next(iter_dt) # Qualifier at wider or same resolution as datetime value. @@ -178,8 +175,8 @@ else: if not have_q: if isinstance(from_q, Enum) and pos > 0: - repeat = Pattern(pos - 1, {"interval" : 1, "values" : [context[-1]]}, "REPEAT") - repeat.context = tuple(context[:-1]) + repeat = Pattern(pos - 1, {"interval" : 1}, "REPEAT") + repeat.context = tuple(context) l.append(repeat) else: from_q.context = tuple(context) @@ -193,7 +190,8 @@ # Or combine the qualifier and value details. else: - l.append(combine_value_with_qualifier(from_dt, from_q)) + context.append(from_dt.args["values"][0]) + l.append(combine_context_with_qualifier(context, from_q)) from_dt = get_next(iter_dt) from_q = get_next(iter_q) @@ -207,8 +205,8 @@ while from_q: if not have_q: if isinstance(from_q, Enum) and pos > 0: - repeat = Pattern(pos - 1, {"interval" : 1, "values" : [context[-1]]}, "REPEAT") - repeat.context = tuple(context[:-1]) + repeat = Pattern(pos - 1, {"interval" : 1}, "REPEAT") + repeat.context = tuple(context) l.append(repeat) else: from_q.context = tuple(context) @@ -218,15 +216,15 @@ return l -def combine_value_with_qualifier(from_dt, from_q): +def combine_context_with_qualifier(context, from_q): """ - Combine value information supplied by 'from_dt' (a datetime) and 'from_q' - (a qualifier), imposing the datetime value information on any qualifiers. + Combine 'context' information (a datetime) and 'from_q' (a qualifier), + imposing the datetime value information on any qualifiers. """ - if not from_q.args.has_key("values") and from_dt.args.has_key("values"): - from_q.args["values"] = from_dt.args["values"] + if not from_q.args.has_key("values"): + from_q.context = tuple(context) return from_q # Datetime arithmetic. @@ -309,7 +307,7 @@ class Pattern(Selector): def materialise_items(self, context, start, end, counter): - first = scale(self.args["values"][0], self.pos) + first = scale(self.context[self.pos], self.pos) # Define the step between items.