comparison configmix/ini.py @ 120:ba5970a2dcef

The default file encoding when reading INI style files with configmix.ini.load() is now "UTF-8". Added unittests for proper Unicode handling.
author Franz Glasner <f.glasner@feldmann-mg.com>
date Thu, 29 Mar 2018 12:38:52 +0200
parents 1b4d95f60650
children be352645871c
comparison
equal deleted inserted replaced
119:eefde3288fb8 120:ba5970a2dcef
141 141
142 """ 142 """
143 return DictImpl(self.itemsx(section, options)) 143 return DictImpl(self.itemsx(section, options))
144 144
145 145
146 def load(filename, extract=["config"]): 146 def load(filename, extract=["config"],
147 encoding="utf-8"):
147 """Load a single INI file and read/interpolate the sections given in 148 """Load a single INI file and read/interpolate the sections given in
148 `extract`. 149 `extract`.
149 150
150 Flattens the given sections into the resulting dictionary. 151 Flattens the given sections into the resulting dictionary.
151 152
152 Then build a tree out of sections which start with any of the `extract` 153 Then build a tree out of sections which start with any of the `extract`
153 content value and a point ``.``. 154 content value and a point ``.``.
154 155
156 The encoding of the file is given in `encoding`.
157
155 """ 158 """
156 conf = DictImpl() 159 conf = DictImpl()
157 ini = INIConfigParser(filename) 160 ini = INIConfigParser(filename, encoding=encoding)
158 for sect in extract: 161 for sect in extract:
159 try: 162 try:
160 cfg = ini.options(sect) 163 cfg = ini.options(sect)
161 except NoSectionError: 164 except NoSectionError:
162 pass 165 pass