# HG changeset patch # User Paul Boddie # Date 1416936344 -3600 # Node ID 3a1b5b29938ca355168b14f861085c1eab44c928 # Parent 3aed12e8da7111a04eaacbab4985e8f8b22ef36a Fixed conversion to dictionary for multivalued definitions (such as FREEBUSY). diff -r 3aed12e8da71 -r 3a1b5b29938c vCalendar.py --- a/vCalendar.py Tue Nov 25 18:03:45 2014 +0100 +++ b/vCalendar.py Tue Nov 25 18:25:44 2014 +0100 @@ -276,7 +276,12 @@ return vContent.iterwrite(stream_or_string, write, encoding, line_length, vCalendarStreamWriter) -to_dict = vContent.to_dict +def to_dict(node): + + "Return the 'node' converted to a dictionary representation." + + return vContent.to_dict(node, SECTION_TYPES) + to_node = vContent.to_node # vim: tabstop=4 expandtab shiftwidth=4 diff -r 3aed12e8da71 -r 3a1b5b29938c vContent.py --- a/vContent.py Tue Nov 25 18:03:45 2014 +0100 +++ b/vContent.py Tue Nov 25 18:25:44 2014 +0100 @@ -620,19 +620,21 @@ else: return codecs.open(stream_or_string, "w", encoding=(encoding or default_encoding)) -def items_to_dict(items): +def items_to_dict(items, sections=None): """ Return the given 'items' as a dictionary mapping names to tuples of the form - (value, attributes). + (value, attributes). Where 'sections' is provided, only items whose names + occur in the given 'sections' collection will be treated as groups or + sections of definitions. """ d = {} for name, attr, value in items: if not d.has_key(name): d[name] = [] - if isinstance(value, list): - d[name].append((items_to_dict(value), attr)) + if isinstance(value, list) and (not sections or name in sections): + d[name].append((items_to_dict(value, sections), attr)) else: d[name].append((value, attr)) return d @@ -745,12 +747,12 @@ return (writer_cls or StreamWriter)(_writer) -def to_dict(node): +def to_dict(node, sections=None): "Return the 'node' converted to a dictionary representation." name, attr, items = node - return {name : (isinstance(items, list) and items_to_dict(items) or items, attr)} + return {name : (isinstance(items, list) and items_to_dict(items, sections) or items, attr)} def to_node(d):