1.1 --- a/vCalendar.py Tue Nov 25 18:03:45 2014 +0100
1.2 +++ b/vCalendar.py Tue Nov 25 18:25:44 2014 +0100
1.3 @@ -276,7 +276,12 @@
1.4
1.5 return vContent.iterwrite(stream_or_string, write, encoding, line_length, vCalendarStreamWriter)
1.6
1.7 -to_dict = vContent.to_dict
1.8 +def to_dict(node):
1.9 +
1.10 + "Return the 'node' converted to a dictionary representation."
1.11 +
1.12 + return vContent.to_dict(node, SECTION_TYPES)
1.13 +
1.14 to_node = vContent.to_node
1.15
1.16 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/vContent.py Tue Nov 25 18:03:45 2014 +0100
2.2 +++ b/vContent.py Tue Nov 25 18:25:44 2014 +0100
2.3 @@ -620,19 +620,21 @@
2.4 else:
2.5 return codecs.open(stream_or_string, "w", encoding=(encoding or default_encoding))
2.6
2.7 -def items_to_dict(items):
2.8 +def items_to_dict(items, sections=None):
2.9
2.10 """
2.11 Return the given 'items' as a dictionary mapping names to tuples of the form
2.12 - (value, attributes).
2.13 + (value, attributes). Where 'sections' is provided, only items whose names
2.14 + occur in the given 'sections' collection will be treated as groups or
2.15 + sections of definitions.
2.16 """
2.17
2.18 d = {}
2.19 for name, attr, value in items:
2.20 if not d.has_key(name):
2.21 d[name] = []
2.22 - if isinstance(value, list):
2.23 - d[name].append((items_to_dict(value), attr))
2.24 + if isinstance(value, list) and (not sections or name in sections):
2.25 + d[name].append((items_to_dict(value, sections), attr))
2.26 else:
2.27 d[name].append((value, attr))
2.28 return d
2.29 @@ -745,12 +747,12 @@
2.30
2.31 return (writer_cls or StreamWriter)(_writer)
2.32
2.33 -def to_dict(node):
2.34 +def to_dict(node, sections=None):
2.35
2.36 "Return the 'node' converted to a dictionary representation."
2.37
2.38 name, attr, items = node
2.39 - return {name : (isinstance(items, list) and items_to_dict(items) or items, attr)}
2.40 + return {name : (isinstance(items, list) and items_to_dict(items, sections) or items, attr)}
2.41
2.42 def to_node(d):
2.43