aboutsummaryrefslogtreecommitdiff
path: root/debug_info_test/whitelist.py
diff options
context:
space:
mode:
authorZhizhou Yang <zhizhouy@google.com>2020-02-11 16:56:57 -0800
committerZhizhou Yang <zhizhouy@google.com>2020-02-13 06:50:19 +0000
commit43c9066b1889baaa0a6077399deb6a4d503551e6 (patch)
treedb4575b4aea577e3da2d7bfb3ac17f386b257733 /debug_info_test/whitelist.py
parentc4615d189f6b0dc4c116fc0a78ac295f7427170e (diff)
downloadtoolchain-utils-43c9066b1889baaa0a6077399deb6a4d503551e6.tar.gz
toolchain-utils: migrate all in-use projects to python 3
This patch migrates all in-use projects left to python 3. BUG=chromium:1011676 TEST=Passed unittests and launched scripts manually. Change-Id: I7f2de4e1131c05bacfac80667f3064da8adaebfd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2051397 Reviewed-by: George Burgess <gbiv@chromium.org> Tested-by: Zhizhou Yang <zhizhouy@google.com> Auto-Submit: Zhizhou Yang <zhizhouy@google.com>
Diffstat (limited to 'debug_info_test/whitelist.py')
-rw-r--r--debug_info_test/whitelist.py77
1 files changed, 44 insertions, 33 deletions
diff --git a/debug_info_test/whitelist.py b/debug_info_test/whitelist.py
index 383fcc3d..b53387a8 100644
--- a/debug_info_test/whitelist.py
+++ b/debug_info_test/whitelist.py
@@ -1,11 +1,17 @@
+# -*- coding: utf-8 -*-
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+"""Whitelist functions."""
+
+from __future__ import print_function
+
import os
import glob
import re
+
# Matching a string of length m in an NFA of size n is O(mn^2), but the
# performance also depends largely on the implementation. It appears to be fast
# enough according to the tests.
@@ -13,45 +19,50 @@ import re
# The performance bottleneck of this script is readelf. Unless this becomes
# slower than readelf, don't waste time here.
def is_whitelisted(list_name, pattern):
- """chech whether the given pattern is specified in the whitelist.
+ """Check whether the given pattern is specified in the whitelist.
+
+ Args:
+ list_name: name of the whitelist.
+ pattern: the target string.
+
+ Returns:
+ True if matched otherwise False.
+ """
+ return pattern and whitelists[list_name].match(pattern)
- Args:
- list_name: name of the whitelist
- pattern: the target string
- Returns:
- True if matched otherwise False
- """
- return pattern and whitelists[list_name].match(pattern)
def prepare_whitelist(patterns):
- """Join and compile the re patterns.
+ """Join and compile the re patterns.
+
+ Args:
+ patterns: regex patterns.
+
+ Returns:
+ A compiled re object.
+ """
+ return re.compile('|'.join(patterns))
- Args:
- patterns: regex patterns.
- Return:
- A compiled re object
- """
- return re.compile('|'.join(patterns))
def load_whitelists(dirname):
- """Load whitelists under dirname.
-
- A whitelist ends with .whitelist.
-
- Args:
- dirname: path to the dir.
- Returns:
- A dictionary of 'filename' -> whitelist matcher.
- """
- wlist = {}
- for fn in glob.glob(os.path.join(dirname, '*.whitelist')):
- key = os.path.splitext(os.path.basename(fn))[0]
- with open(fn, 'r') as f:
- patterns = f.read().splitlines()
- patterns = [l for l in patterns if l != '']
- patterns = [l for l in patterns if l[0] != '#']
- wlist[key] = prepare_whitelist(patterns)
- return wlist
+ """Load whitelists under dirname.
+
+ A whitelist ends with .whitelist.
+
+ Args:
+ dirname: path to the dir.
+
+ Returns:
+ A dictionary of 'filename' -> whitelist matcher.
+ """
+ wlist = {}
+ for fn in glob.glob(os.path.join(dirname, '*.whitelist')):
+ key = os.path.splitext(os.path.basename(fn))[0]
+ with open(fn, 'r', encoding='utf-8') as f:
+ patterns = f.read().splitlines()
+ patterns = [l for l in patterns if l != '']
+ patterns = [l for l in patterns if l[0] != '#']
+ wlist[key] = prepare_whitelist(patterns)
+ return wlist
whitelists = load_whitelists(os.path.dirname(__file__))