# HG changeset patch # User Franz Glasner # Date 1522319932 -7200 # Node ID ba5970a2dcefe70769df033b10a9a4d950f37cf4 # Parent eefde3288fb80725db39c0c941ce5fa39c7af737 The default file encoding when reading INI style files with configmix.ini.load() is now "UTF-8". Added unittests for proper Unicode handling. diff -r eefde3288fb8 -r ba5970a2dcef CHANGES.txt --- a/CHANGES.txt Thu Mar 29 12:37:20 2018 +0200 +++ b/CHANGES.txt Thu Mar 29 12:38:52 2018 +0200 @@ -23,6 +23,15 @@ shallow copy. .. change:: + :tags: breaking, feature + + The default file encoding when reading INI style files with + :py:func:`configmix.ini.load` is now "UTF-8". Previously it was + undefined and therefore dependent on the user's locale. + + An `encoding` keyword argument can be specified explicitely now. + + .. change:: :tags: doc Begin the documentation with `Sphinx `_ diff -r eefde3288fb8 -r ba5970a2dcef configmix/ini.py --- 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) diff -r eefde3288fb8 -r ba5970a2dcef doc/changes.rst --- a/doc/changes.rst Thu Mar 29 12:37:20 2018 +0200 +++ b/doc/changes.rst Thu Mar 29 12:38:52 2018 +0200 @@ -25,3 +25,7 @@ The public signature of :py:func:`configmix.safe_merge` has *not* changed. + +- The default file encoding when reading INI style files with + :py:func:`configmix.ini.load` is now "UTF-8". Previously it was undefined + and therefore dependent on the user's locale. diff -r eefde3288fb8 -r ba5970a2dcef tests/data/conf1.ini --- a/tests/data/conf1.ini Thu Mar 29 12:37:20 2018 +0200 +++ b/tests/data/conf1.ini Thu Mar 29 12:38:52 2018 +0200 @@ -7,3 +7,4 @@ key4 = :bool:yes key5 = :bool:off key6 = :int:0o377 +key7 = Umlaute: ÄÖÜäöüß diff -r eefde3288fb8 -r ba5970a2dcef tests/data/conf1.py --- a/tests/data/conf1.py Thu Mar 29 12:37:20 2018 +0200 +++ b/tests/data/conf1.py Thu Mar 29 12:38:52 2018 +0200 @@ -6,3 +6,4 @@ key4 = True key5 = False key6 = 0o377 +key7 = u"Umlaute: ÄÖÜäöüß" diff -r eefde3288fb8 -r ba5970a2dcef tests/data/conf1.yml --- a/tests/data/conf1.yml Thu Mar 29 12:37:20 2018 +0200 +++ b/tests/data/conf1.yml Thu Mar 29 12:38:52 2018 +0200 @@ -8,3 +8,4 @@ key4: true key5: false key6: 0377 +key7: 'Umlaute: ÄÖÜäöüß' diff -r eefde3288fb8 -r ba5970a2dcef tests/test.py --- a/tests/test.py Thu Mar 29 12:37:20 2018 +0200 +++ b/tests/test.py Thu Mar 29 12:38:52 2018 +0200 @@ -39,6 +39,8 @@ self.assertFalse(cfg.get("key5")) self.assertTrue(isinstance(cfg.get("key5"), bool)) self.assertEqual(255, cfg.get("key6")) + self.assertEqual(u("Umlaute: ÄÖÜäöüß"), + cfg.get("key7")) def __check_tree(self, cfg): self.assertEqual(u("in the root namespace"),