diff 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
line wrap: on
line diff
--- a/configmix/ini.py	Thu Mar 29 12:37:20 2018 +0200
+++ b/configmix/ini.py	Thu Mar 29 12:38:52 2018 +0200
@@ -143,7 +143,8 @@
         return DictImpl(self.itemsx(section, options))
 
 
-def load(filename, extract=["config"]):
+def load(filename, extract=["config"],
+         encoding="utf-8"):
     """Load a single INI file and read/interpolate the sections given in
     `extract`.
 
@@ -152,9 +153,11 @@
     Then build a tree out of sections which start with any of the `extract`
     content value and a point ``.``.
 
+    The encoding of the file is given in `encoding`.
+
     """
     conf = DictImpl()
-    ini = INIConfigParser(filename)
+    ini = INIConfigParser(filename, encoding=encoding)
     for sect in extract:
         try:
             cfg = ini.options(sect)