]> code.ossystems Code Review - openembedded-core.git/commitdiff
devtool: fix handling of unicode characters from subprocess stdout
authorJiajie Hu <jiajie.hu@intel.com>
Fri, 11 Nov 2016 06:02:18 +0000 (14:02 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 23 Nov 2016 11:02:33 +0000 (11:02 +0000)
In previous implementation, a UnicodeDecodeError exception will be
raised if multi-byte encoded characters are printed by the subprocess.
As an example, the following command will fail in an en_US.UTF-8
environment because wget quotes its saving destination with '‘'(0xE2
0x80 0x98), while just the first byte is provided for decoding:

    devtool add recipe http://example.com/source.tar.xz

The patch fixes the issue by avoiding such kind of incomplete decoding.

Signed-off-by: Jiajie Hu <jiajie.hu@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
scripts/lib/devtool/__init__.py

index e675133f63bfb721f190299cedbde56420890fc6..31ecb65937c38b78d48e95743e2aaf68ad8e1908 100644 (file)
@@ -23,6 +23,7 @@ import sys
 import subprocess
 import logging
 import re
+import codecs
 
 logger = logging.getLogger('devtool')
 
@@ -67,10 +68,10 @@ def exec_watch(cmd, **options):
         cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **options
     )
 
+    reader = codecs.getreader('utf-8')(process.stdout)
     buf = ''
     while True:
-        out = process.stdout.read(1)
-        out = out.decode('utf-8')
+        out = reader.read(1, 1)
         if out:
             sys.stdout.write(out)
             sys.stdout.flush()