This code was python 2 specific (string handling
has changed dramatically in python 3), and didn't
correctly decode utf-16 in python3. We should
instead read the file as bytes, then attempt a
utf-8 decode (the default), and try utf-16 if
encountering a decode failure.
The existing code actually throws an exception on
the initial file read when the data is utf-16,
since it tries to decode the bytes to a utf-8
string.
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
class gp_inf_ext(gp_ext):
def read(self, data_file):
- policy = open(data_file, 'r').read()
+ policy = open(data_file, 'rb').read()
inf_conf = ConfigParser()
inf_conf.optionxform = str
try:
- inf_conf.readfp(StringIO(policy))
- except:
+ inf_conf.readfp(StringIO(policy.decode()))
+ except UnicodeDecodeError:
inf_conf.readfp(StringIO(policy.decode('utf-16')))
return inf_conf
+++ /dev/null
-samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_inf_ext_utf