[OpenPower-Firmware] [RFC PATCH 2/6] securityRegListGen: use io.open and read in text mode.

Marty E. Plummer hanetzer at startmail.com
Fri May 10 19:35:05 AEST 2019


io.open is compatible with python3.x's open builtin. Open in text mode
(no 'b') as this is a plain csv file, and specify the encoding as utf8.

Without this change, building with python3.x (python3.5 tested) as
/usr/bin/python will result in the following error:

File "sbe/src/build/security/securityRegListGen.py", line 695, in <module>
  main(sys.argv)
File "sbe/src/build/security/securityRegListGen.py", line 592, in main
  for idx, row in enumerate(reader):
File "/usr/lib/python3.5/csv.py", line 109, in __next__
  self.fieldnames
File "/usr/lib/python3.5/csv.py", line 96, in fieldnames
  self._fieldnames = next(self.reader)
_csv.Error: iterator should return strings, not bytes
(did you open the file in text mode?)

Signed-off-by: Marty E. Plummer <hanetzer at startmail.com>
---
 src/build/security/securityRegListGen.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/build/security/securityRegListGen.py b/src/build/security/securityRegListGen.py
index 35cf0fb7..a6cec196 100644
--- a/src/build/security/securityRegListGen.py
+++ b/src/build/security/securityRegListGen.py
@@ -27,6 +27,7 @@ import getopt
 import sys
 import os
 import csv
+import io
 
 # Exit codes
 SUCCESS       = 0
@@ -587,7 +588,7 @@ def main(argv):
     whitelist = []
     blacklist = []
     greylist = []
-    with open(SECURITY_LIST, 'rbU') as f:
+    with io.open(SECURITY_LIST, 'r', encoding="utf8") as f:
         reader = csv.DictReader(f)
         for idx, row in enumerate(reader):
             try:
-- 
2.21.0



More information about the OpenPower-Firmware mailing list