11#------------------------------------------------------------------------------#
2- # hsd: package for manipulating HSD-formatted data #
3- # Copyright (C) 2011 - 2020 DFTB+ developers group #
4- # #
5- # See the LICENSE file for terms of usage and distribution. #
2+ # hsd-python: package for manipulating HSD-formatted data in Python #
3+ # Copyright (C) 2011 - 2021 DFTB+ developers group #
4+ # Licensed under the BSD 2-clause license. #
65#------------------------------------------------------------------------------#
76#
87"""
2625
2726
2827class HsdDictBuilder (HsdEventHandler ):
29- """Deserializes HSD into nested dictionaries
30-
31- Note: hsdattrib passed by the generating events are ignored.
28+ """Specific HSD event handler, which builds a nested Python dictionary.
29+
30+ Args:
31+ flatten_data: Whether multiline data in the HSD input should be
32+ flattened into a single list. Othewise a list of lists is created,
33+ with one list for every line (default).
34+ include_hsd_attribs: Whether the HSD-attributes (processing related
35+ attributes, like original tag name, line information, etc.) should
36+ be stored.
3237 """
3338
34- def __init__ (self , flatten_data = False , include_hsd_attribs = False ):
39+ def __init__ (self , flatten_data : bool = False ,
40+ include_hsd_attribs : bool = False ):
3541 super ().__init__ ()
3642 self ._hsddict = {}
3743 self ._curblock = self ._hsddict
@@ -41,6 +47,12 @@ def __init__(self, flatten_data=False, include_hsd_attribs=False):
4147 self ._include_hsd_attribs = include_hsd_attribs
4248
4349
50+ @property
51+ def hsddict (self ):
52+ """The dictionary which has been built"""
53+ return self ._hsddict
54+
55+
4456 def open_tag (self , tagname , attrib , hsdattrib ):
4557 if attrib is not None :
4658 self ._curblock [tagname + ATTRIB_SUFFIX ] = attrib
@@ -72,12 +84,6 @@ def add_text(self, text):
7284 self ._data = self ._text_to_data (text )
7385
7486
75- @property
76- def hsddict (self ):
77- """Returns the dictionary which has been built"""
78- return self ._hsddict
79-
80-
8187 def _text_to_data (self , txt ):
8288 data = []
8389 for line in txt .split ("\n " ):
0 commit comments