# HG changeset patch # User Paul Boddie # Date 1425681128 -3600 # Node ID 5f14e612c1deb2646be6fecd7de07630d20d5cc6 # Parent 4a55201d7985addac69c16a49ca84422d6305eac Forbid trailing data when parsing iCalendar date/datetime/duration values. Propagated attributes to datetimes when interpreting period value details. diff -r 4a55201d7985 -r 5f14e612c1de imiptools/dates.py --- a/imiptools/dates.py Fri Mar 06 21:41:56 2015 +0100 +++ b/imiptools/dates.py Fri Mar 06 23:32:08 2015 +0100 @@ -26,14 +26,16 @@ # iCalendar date and datetime parsing (from DateSupport in MoinSupport). -date_icalendar_regexp_str = ur'(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})' -datetime_icalendar_regexp_str = date_icalendar_regexp_str + \ +_date_icalendar_regexp_str = ur'(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})' +date_icalendar_regexp_str = _date_icalendar_regexp_str + '$' + +datetime_icalendar_regexp_str = _date_icalendar_regexp_str + \ ur'(?:' \ ur'T(?P[0-2][0-9])(?P[0-5][0-9])(?P[0-6][0-9])' \ ur'(?PZ)?' \ - ur')?' + ur')?$' -duration_time_icalendar_regexp_str = \ +_duration_time_icalendar_regexp_str = \ ur'T' \ ur'(?:' \ ur'([0-9]+H)(?:([0-9]+M)([0-9]+S)?)?' \ @@ -50,7 +52,7 @@ ur'(?:%s)' \ ur'|' \ ur'([0-9]+D)(?:%s)?' \ - ur')' % (duration_time_icalendar_regexp_str, duration_time_icalendar_regexp_str) + ur')$' % (_duration_time_icalendar_regexp_str, _duration_time_icalendar_regexp_str) match_date_icalendar = re.compile(date_icalendar_regexp_str, re.UNICODE).match match_datetime_icalendar = re.compile(datetime_icalendar_regexp_str, re.UNICODE).match @@ -203,11 +205,17 @@ if len(t) != 2: return None - start = get_datetime(t[0]) + dtattr = {} + if attr: + dtattr.update(attr) + if dtattr.has_key("VALUE"): + del dtattr["VALUE"] + + start = get_datetime(t[0], dtattr) if t[1].startswith("P"): end = start + get_duration(t[1]) else: - end = get_datetime(t[1]) + end = get_datetime(t[1], dtattr) return start, end