[oe-commits] [openembedded-core] 58/60: devtool: fix handling of unicode characters from subprocess stdout

git at git.openembedded.org git at git.openembedded.org
Wed Nov 23 11:12:09 UTC 2016


rpurdie pushed a commit to branch master
in repository openembedded-core.

commit 1875ea92546d23abcab1b40b562477a0016f712d
Author: Jiajie Hu <jiajie.hu at intel.com>
AuthorDate: Fri Nov 11 14:02:18 2016 +0800

    devtool: fix handling of unicode characters from subprocess stdout
    
    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 at intel.com>
    Signed-off-by: Ross Burton <ross.burton at intel.com>
---
 scripts/lib/devtool/__init__.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py
index e675133..31ecb65 100644
--- a/scripts/lib/devtool/__init__.py
+++ b/scripts/lib/devtool/__init__.py
@@ -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()

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list