From 1ba2701c7ec7de3b6f3fed3e21f3699e5ef321fb Mon Sep 17 00:00:00 2001 From: timeless Date: Wed, 11 May 2016 01:46:11 +0000 Subject: [PATCH] check-code: handle py3 open divergence open() really wants an encoding attribute --- contrib/check-code.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/contrib/check-code.py b/contrib/check-code.py index 44ea0948fe..1ea2563b42 100755 --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -26,6 +26,11 @@ import optparse import os import re import sys +if sys.version_info[0] < 3: + opentext = open +else: + def opentext(f): + return open(f, encoding='ascii') try: xrange except NameError: @@ -491,8 +496,12 @@ def checkfile(f, logfunc=_defaultlogger.log, maxerr=None, warnings=False, result = True try: - with open(f) as fp: - pre = post = fp.read() + with opentext(f) as fp: + try: + pre = post = fp.read() + except UnicodeDecodeError as e: + print("%s while reading %s" % (e, f)) + return result except IOError as e: print("Skipping %s, %s" % (f, str(e).split(':', 1)[0])) return result