| 39 | |
| 40 | |
| 41 | class FileSuffixSet: |
| 42 | def __init__(self, *patterns): |
| 43 | self._names = set() |
| 44 | self._prefixes = [] |
| 45 | self._suffixes = [] |
| 46 | for p in map(os.path.normcase, patterns): |
| 47 | if p.startswith("*."): |
| 48 | self._names.add(p[1:]) |
| 49 | elif p.startswith("*"): |
| 50 | self._suffixes.append(p[1:]) |
| 51 | elif p.endswith("*"): |
| 52 | self._prefixes.append(p[:-1]) |
| 53 | elif p.startswith("."): |
| 54 | self._names.add(p) |
| 55 | else: |
| 56 | self._names.add("." + p) |
| 57 | |
| 58 | def _make_name(self, f): |
| 59 | return os.path.normcase(f.suffix) |
| 60 | |
| 61 | def __contains__(self, f): |
| 62 | bn = self._make_name(f) |
| 63 | return ( |
| 64 | bn in self._names |
| 65 | or any(map(bn.startswith, self._prefixes)) |
| 66 | or any(map(bn.endswith, self._suffixes)) |
| 67 | ) |
| 68 | |
| 69 | |
| 70 | def _rglob(root, pattern, condition): |
no outgoing calls
no test coverage detected
searching dependent graphs…