def parse_day_period_rules(tree):
 day_periods = {}
 for ruleset in tree.findall('.//dayPeriodRuleSet'):
  ruleset_type = ruleset.attrib.get('type')
  for rules in ruleset.findall('dayPeriodRules'):
   locales = rules.attrib['locales'].split()
   for rule in rules.findall('dayPeriodRule'):
    type = rule.attrib['type']
    if (type in ('am', 'pm')):
     continue
    rule = _compact_dict(dict(((key, _time_to_seconds_past_midnight(rule.attrib.get(key))) for key in ('after', 'at', 'before', 'from', 'to'))))
    for locale in locales:
     dest_list = day_periods.setdefault(locale, {}).setdefault(ruleset_type, {}).setdefault(type, [])
     dest_list.append(rule)
 return day_periods

def parse_day_period_rules ( tree ) : day_periods = { } for ruleset in tree . findall ( './/dayPeriodRuleSet' ) : ruleset_type = ruleset . attrib . get ( 'type' ) for rules in ruleset . findall ( 'dayPeriodRules' ) : locales = rules . attrib [ 'locales' ] . split ( ) for rule in rules . findall ( 'dayPeriodRule' ) : type = rule . attrib [ 'type' ] if ( type in ( 'am' , 'pm' ) ) : continue rule = _compact_dict ( dict ( ( ( key , _time_to_seconds_past_midnight ( rule . attrib . get ( key ) ) ) for key in ( 'after' , 'at' , 'before' , 'from' , 'to' ) ) ) ) for locale in locales : dest_list = day_periods . setdefault ( locale , { } ) . setdefault ( ruleset_type , { } ) . setdefault ( type , [ ] ) dest_list . append ( rule ) return day_periods
parse dayperiodrule data into a dict .