path: root/scripts/
diff options
authorJeremy Cline <>2018-08-17 15:44:01 -0700
committerLinus Torvalds <>2018-08-17 16:20:27 -0700
commitbed95c43c15eb6b1ccc5b09e5ae08cac726c456d (patch)
tree7e65fdd4f065437bbe1b534efb89fae47dc87ceb /scripts/
parentfde5e903fb5893415fa49d280e998be226d0898f (diff)
scripts: add Python 3 compatibility to
"dict.has_key(key)" on dictionaries has been replaced with "key in dict". Additionally, when run under Python 3 some files don't decode with the default encoding (tested with UTF-8). To handle that, don't open the file in text mode and decode text line-by-line, ignoring encoding errors. This remains compatible with Python 2 and should have no functional change. Link: Signed-off-by: Jeremy Cline <> Acked-by: Thomas Gleixner <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'scripts/')
1 files changed, 5 insertions, 2 deletions
diff --git a/scripts/ b/scripts/
index a6041f29b18e..839e190bbd7a 100755
--- a/scripts/
+++ b/scripts/
@@ -4,6 +4,7 @@
from argparse import ArgumentParser
from ply import lex, yacc
+import locale
import traceback
import sys
import git
@@ -102,7 +103,7 @@ class id_parser(object):
raise ParserException(tok, 'Invalid License ID')
self.lastid = id
elif tok.type == 'EXC':
- if not self.spdx.exceptions.has_key(id):
+ if id not in self.spdx.exceptions:
raise ParserException(tok, 'Invalid Exception ID')
if self.lastid not in self.spdx.exceptions[id]:
raise ParserException(tok, 'Exception not valid for license %s' %self.lastid)
@@ -167,6 +168,7 @@ class id_parser(object):
self.curline = 0
for line in fd:
+ line = line.decode(locale.getpreferredencoding(False), errors='ignore')
self.curline += 1
if self.curline > maxlines:
@@ -201,7 +203,8 @@ def scan_git_tree(tree):
if not os.path.isfile(el.path):
- parser.parse_lines(open(el.path), args.maxlines, el.path)
+ with open(el.path, 'rb') as fd:
+ parser.parse_lines(fd, args.maxlines, el.path)
def scan_git_subtree(tree, path):
for p in path.strip('/').split('/'):