1.1 --- a/vContent.py Tue Nov 25 18:03:45 2014 +0100
1.2 +++ b/vContent.py Tue Nov 25 18:25:44 2014 +0100
1.3 @@ -620,19 +620,21 @@
1.4 else:
1.5 return codecs.open(stream_or_string, "w", encoding=(encoding or default_encoding))
1.6
1.7 -def items_to_dict(items):
1.8 +def items_to_dict(items, sections=None):
1.9
1.10 """
1.11 Return the given 'items' as a dictionary mapping names to tuples of the form
1.12 - (value, attributes).
1.13 + (value, attributes). Where 'sections' is provided, only items whose names
1.14 + occur in the given 'sections' collection will be treated as groups or
1.15 + sections of definitions.
1.16 """
1.17
1.18 d = {}
1.19 for name, attr, value in items:
1.20 if not d.has_key(name):
1.21 d[name] = []
1.22 - if isinstance(value, list):
1.23 - d[name].append((items_to_dict(value), attr))
1.24 + if isinstance(value, list) and (not sections or name in sections):
1.25 + d[name].append((items_to_dict(value, sections), attr))
1.26 else:
1.27 d[name].append((value, attr))
1.28 return d
1.29 @@ -745,12 +747,12 @@
1.30
1.31 return (writer_cls or StreamWriter)(_writer)
1.32
1.33 -def to_dict(node):
1.34 +def to_dict(node, sections=None):
1.35
1.36 "Return the 'node' converted to a dictionary representation."
1.37
1.38 name, attr, items = node
1.39 - return {name : (isinstance(items, list) and items_to_dict(items) or items, attr)}
1.40 + return {name : (isinstance(items, list) and items_to_dict(items, sections) or items, attr)}
1.41
1.42 def to_node(d):
1.43