| 126 | |
| 127 | |
| 128 | class FilePatternMatcher(): |
| 129 | def __init__(self, signature): |
| 130 | self._signature = signature |
| 131 | self.__compiled = PatternMatcher.compile_patterns([signature])[0] |
| 132 | |
| 133 | def __repr__(self): |
| 134 | return f"<FilePatternMatcher({repr(self._signature)})>" |
| 135 | |
| 136 | def match(self, value: ScanLocation) -> bool: |
| 137 | if self._signature.get("target", "full") == "full": |
| 138 | targets = (str(value.location),) |
| 139 | elif self._signature["target"] == "part": |
| 140 | targets = value.location.parts |
| 141 | elif self._signature["target"] == "filename": |
| 142 | targets = (value.location.name,) |
| 143 | else: |
| 144 | raise ValueError(f"Unknown pattern target: '{self._signature['target']}'") |
| 145 | |
| 146 | return any(self.__compiled.match(x) for x in targets) |
| 147 | |
| 148 | |
| 149 | class RegexPattern(StringPatternMatcher): |
no outgoing calls