]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
run.py: fix codec type used to decode stdout, stderr
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 23 Feb 2022 13:43:33 +0000 (19:13 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 24 Feb 2022 16:31:45 +0000 (09:31 -0700)
Codec 'ascii' only decodes English and can't understand other characters
and raise an UnicodeDecodeError. For example, consider running 'mkdir' on
an already existing directory, it would trigger:

err.strip().decode('ascii')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 31: ordinal not in range(128)

fix it by using 'UTF-8' as Codec for decoding, with the patch stderr
will be:

err.strip().decode('UTF-8')
'mkdir: cannot create directory ‘out’: File exists'

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests/run.py

index ef837083f83079cb43691a2abeee1e7a8a068003..1144986abbb18887e314434d6c5143f4b62e4c0a 100644 (file)
@@ -41,8 +41,8 @@ class Run(object):
         out, err = subproc.communicate()
         ret = subproc.returncode
 
-        out = out.strip().decode('ascii')
-        err = err.strip().decode('ascii')
+        out = out.strip().decode('UTF-8')
+        err = err.strip().decode('UTF-8')
 
         if shell_bool:
             Log.log_debug(