diff configmix/ini.py @ 166:b5ce9a8461bf

Use the filesystem encoding explicitely where appropriate.
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 14 Mar 2019 01:35:16 +0100
parents e2e8d21b4122
children b3b5ed34d180
line wrap: on
line diff
--- a/configmix/ini.py	Thu Mar 14 00:21:30 2019 +0100
+++ b/configmix/ini.py	Thu Mar 14 01:35:16 2019 +0100
@@ -32,7 +32,7 @@
     except ImportError:
         DictImpl = dict
 
-from .compat import PY2, u
+from .compat import PY2, u, u2fs
 
 
 __all__ = ["INIConfigParser", "NoSectionError", "NoOptionError",
@@ -50,16 +50,13 @@
         _ConfigParserBase.__init__(self)
         if executable is None:
             executable = sys.argv[0]
-        if PY2:
-            if isinstance(filename, str):
-                filename = filename.decode(locale.getpreferredencoding())
-            if isinstance(executable, str):
-                executable = executable.decode(locale.getpreferredencoding())
+        filename = u(filename, locale.getpreferredencoding())
+        executable = u(executable, locale.getpreferredencoding())
         self.executable = os.path.normpath(os.path.abspath(executable))
         if encoding is None:
             encoding = locale.getpreferredencoding()
         self.encoding = encoding
-        with io.open(filename, mode="rt", encoding=self.encoding) as cf:
+        with io.open(u2fs(filename), mode="rt", encoding=self.encoding) as cf:
             self.read_file(cf, filename)
 
     def optionxform(self, option):
@@ -91,9 +88,7 @@
         if hasattr(self, "filename"):
             raise RuntimeError("already initialized")
         filename = os.path.normpath(os.path.abspath(filename))
-        if PY2:
-            if isinstance(filename, str):
-                filename = filename.decode(locale.getpreferredencoding())
+        filename = u(filename, locale.getpreferredencoding())
         self.set(None, u("self"), filename)
         self.set(None, u("here"), os.path.dirname(filename))
         self.set(None, u("root"), os.path.dirname(self.executable))