From dd0076703b55ea14f15666c62759ea242906e4b7 Mon Sep 17 00:00:00 2001 From: Dirk Pranke Date: Wed, 19 May 2021 23:20:18 +0000 Subject: [PATCH] Try again to fix UnicodeDecodeError in CheckAuthorizedAuthor. This will attempt to do so in a Python2-compatible way. Bug: 1210746 Change-Id: I09edc21a5c47106803c0ac5ca449e0f8732efb24 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2906501 Auto-Submit: Dirk Pranke Reviewed-by: Edward Lesmes Commit-Queue: Edward Lesmes --- presubmit_canned_checks.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 0b9747eca..243912b59 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -126,10 +126,14 @@ def CheckAuthorizedAuthor(input_api, output_api, bot_allowlist=None): authors_path = input_api.os_path.join( input_api.PresubmitLocalPath(), 'AUTHORS') - valid_authors = ( - input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line) - for line in open(authors_path)) - valid_authors = [item.group(1).lower() for item in valid_authors if item] + author_re = input_api.re.compile(r'[^#]+\s+\<(.+?)\>\s*$') + valid_authors = [] + with open(authors_path, 'rb') as fp: + for line in fp: + m = author_re.match(line.decode('utf8')) + if m: + valid_authors.append(m.group(1)).lower() + if not any(input_api.fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors): input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))