# HG changeset patch # User timeless # Date 1462931171 0 # Node ID c641b8dfb98c2ade6995ba3aa341fe4d7b154827 # Parent f8b87a779c87586aa043bcd6030369715edfc9c1 check-code: handle py3 open divergence open() really wants an encoding attribute diff -r f8b87a779c87 -r c641b8dfb98c contrib/check-code.py --- a/contrib/check-code.py Wed May 11 01:44:39 2016 +0000 +++ b/contrib/check-code.py Wed May 11 01:46:11 2016 +0000 @@ -26,6 +26,11 @@ 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 @@ 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