gpo: Parse GPT.INI with Latin-1
authorGarming Sam <garming@catalyst.net.nz>
Tue, 26 Feb 2019 02:35:44 +0000 (15:35 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 12 Mar 2019 00:42:20 +0000 (00:42 +0000)
For some reason the French version of RSAT turns accents into ISO-8859-1.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13806

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/gp_parse/gp_ini.py

index 58aee88a1e1de3add1a73d7c7e4fc25eb6037dbc..590b71b9a6c966c8a9dc19801a99458045b0bdb6 100644 (file)
@@ -105,6 +105,17 @@ class GPIniParser(GPParser):
 class GPTIniParser(GPIniParser):
     encoding = 'utf-8'
 
+    def parse(self, contents):
+        try:
+            super(GPTIniParser, self).parse(contents)
+        except UnicodeDecodeError:
+            # Required dict_type in Python 2.7
+            self.ini_conf = ConfigParser(dict_type=collections.OrderedDict)
+            self.ini_conf.optionxform = str
+
+            # Fallback to Latin-1 which RSAT appears to use
+            self.ini_conf.readfp(StringIO(contents.decode('iso-8859-1')))
+
 
 class GPScriptsIniParser(GPIniParser):
     def build_xml_parameter(self, section_xml, section, key_ini, val_ini):