[elbe-devel] [PATCH 5/5] Python3: use bytes() to convert unicode to binary

Christian Teklenborg chris at linutronix.de
Fri Jan 10 15:46:02 CET 2020


In Python3 str() are unprefixed strings whereas in Python2 str() are binary
strings. The dict-object contains binary strings so use bytes() to make sure
that find() will not compare binary strings with unicode strings.

Signed-off-by: Christian Teklenborg <chris at linutronix.de>
---
 elbepack/elbexml.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
index d75ad034..9029062a 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -193,12 +193,14 @@ class ElbeXML(object):
         ret = False
         if "srcstr" in r:
             for line in fp:
-                if line.find(r["srcstr"]) != -1:
+                needle = bytes(r["srcstr"])
+                if line.find(needle) != -1:
                     ret = True
                     break
         elif "binstr" in r:
             for line in fp:
-                if line.find(r["binstr"]) != -1:
+                needle = bytes(r["binstr"])
+                if line.find(needle) != -1:
                     ret = True
                     break
         else:
-- 
2.20.1




More information about the elbe-devel mailing list