[rtems-tools commit] rtemstoolkit/execute: Handle unicode input on python2

Chris Johns chrisj at rtems.org
Sun Mar 29 23:03:46 UTC 2020


Module:    rtems-tools
Branch:    master
Commit:    ca7b290f94a19238ed068aad229854cf67dee9b5
Changeset: http://git.rtems.org/rtems-tools/commit/?id=ca7b290f94a19238ed068aad229854cf67dee9b5

Author:    Chris Johns <chrisj at rtems.org>
Date:      Mon Mar 30 09:55:02 2020 +1100

rtemstoolkit/execute: Handle unicode input on python2

- Allow unicode as a type on python2. The unicode type is not
  present on python3 so make the support conditional.
- Add some more diag prints to aid debugging.

Closes #3964

---

 rtemstoolkit/execute.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py
index 3a79f50..ed81589 100755
--- a/rtemstoolkit/execute.py
+++ b/rtemstoolkit/execute.py
@@ -139,12 +139,20 @@ class execute(object):
                 tmp = bytes('temp', sys.stdin.encoding)
             except:
                 encoding = False
+            input_types = [str, bytes]
+            try:
+                # Unicode is not valid in python3, not added to the list
+                input_types += [unicode]
+            except:
+                pass
             try:
                 while True:
                     if trace_threads:
                         print('execute:_writethread: call input', input)
                     lines = input()
-                    if type(lines) == str or type(lines) == bytes:
+                    if trace_threads:
+                        print('execute:_writethread: input returned:', type(lines))
+                    if type(lines) in input_types:
                         try:
                             if encoding:
                                 lines = bytes(lines, sys.stdin.encoding)
@@ -216,6 +224,9 @@ class execute(object):
                     sd = sd[:-1]
                     if len(sd) > 0:
                         for l in sd:
+                            if trace_threads:
+                                print('execute:_readthread: output-line:',
+                                      count, type(l))
                             _output_line(l + '\n', exe, prefix, out, count)
                             count += 1
                         if count > 10:



More information about the vc mailing list