# HG changeset patch # User Paul Boddie # Date 1422741585 -3600 # Node ID 9ddd8ed3295a2c1c60b8abfe94dfca79c471af23 # Parent e2841274e1fbb6078ccdb12dbda164b5ff04856f Fixed conversion to dictionary for multivalued definitions (such as FREEBUSY). diff -r e2841274e1fb -r 9ddd8ed3295a vContent.py --- a/vContent.py Thu Oct 09 22:50:12 2014 +0200 +++ b/vContent.py Sat Jan 31 22:59:45 2015 +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):