| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import collections |
| 6 import re |
| 7 |
| 8 |
| 9 # TODO(wrengr): write the coverage tests the old version was lacking. |
| 10 class Component(collections.namedtuple('Component', |
| 11 ['component_name', 'path_regex', 'function_regex'])): # pragma: no cover |
| 12 """A representation of a "component" in Chromium. |
| 13 |
| 14 For example: 'Blink>DOM' or 'Blink>HTML'. Notably, a component knows |
| 15 how to identify itself. Hence, given a stack frame or change list |
| 16 or whatever, we ask the Component whether it matches that frame, |
| 17 CL, etc.""" |
| 18 __slots__ = () |
| 19 |
| 20 def __new__(cls, component_name, path_regex, function_regex=None): |
| 21 return super(cls, Component).__new__(cls, |
| 22 component_name, |
| 23 re.compile(path_regex), |
| 24 re.compile(function_regex) if function_regex else None) |
| 25 |
| 26 |
| 27 def MatchesStackFrame(self, frame): |
| 28 """Return true if this component matches the frame.""" |
| 29 if not self.path_regex.match(frame.dep_path + frame.file_path): |
| 30 return False |
| 31 |
| 32 # We interpret function_regex=None to mean the regex that matches |
| 33 # everything. |
| 34 if not self.function_regex: |
| 35 return True |
| 36 return self.function_regex.match(frame.function) |
| 37 |
| OLD | NEW |