aboutsummaryrefslogtreecommitdiff
path: root/debug_info_test/allowlist.py
diff options
context:
space:
mode:
Diffstat (limited to 'debug_info_test/allowlist.py')
-rw-r--r--debug_info_test/allowlist.py71
1 files changed, 35 insertions, 36 deletions
diff --git a/debug_info_test/allowlist.py b/debug_info_test/allowlist.py
index 9cf42af0..70bb776a 100644
--- a/debug_info_test/allowlist.py
+++ b/debug_info_test/allowlist.py
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
-# Copyright 2018 The Chromium OS Authors. All rights reserved.
+# Copyright 2018 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Allowlist functions."""
-from __future__ import print_function
import glob
import os
@@ -19,50 +18,50 @@ import re
# The performance bottleneck of this script is readelf. Unless this becomes
# slower than readelf, don't waste time here.
def is_allowlisted(list_name, pattern):
- """Check whether the given pattern is specified in the allowlist.
+ """Check whether the given pattern is specified in the allowlist.
- Args:
- list_name: name of the allowlist.
- pattern: the target string.
+ Args:
+ list_name: name of the allowlist.
+ pattern: the target string.
- Returns:
- True if matched otherwise False.
- """
- return pattern and allowlists[list_name].match(pattern)
+ Returns:
+ True if matched otherwise False.
+ """
+ return pattern and allowlists[list_name].match(pattern)
def prepare_allowlist(patterns):
- """Join and compile the re patterns.
+ """Join and compile the re patterns.
- Args:
- patterns: regex patterns.
+ Args:
+ patterns: regex patterns.
- Returns:
- A compiled re object.
- """
- return re.compile('|'.join(patterns))
+ Returns:
+ A compiled re object.
+ """
+ return re.compile("|".join(patterns))
def load_allowlists(dirname):
- """Load allowlists under dirname.
-
- An allowlist ends with .allowlist.
-
- Args:
- dirname: path to the dir.
-
- Returns:
- A dictionary of 'filename' -> allowlist matcher.
- """
- wlist = {}
- for fn in glob.glob(os.path.join(dirname, '*.allowlist')):
- 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_allowlist(patterns)
- return wlist
+ """Load allowlists under dirname.
+
+ An allowlist ends with .allowlist.
+
+ Args:
+ dirname: path to the dir.
+
+ Returns:
+ A dictionary of 'filename' -> allowlist matcher.
+ """
+ wlist = {}
+ for fn in glob.glob(os.path.join(dirname, "*.allowlist")):
+ 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_allowlist(patterns)
+ return wlist
allowlists = load_allowlists(os.path.dirname(__file__))