482 |
482 |
483 class patternmatcher(basematcher): |
483 class patternmatcher(basematcher): |
484 """Matches a set of (kind, pat, source) against a 'root' directory. |
484 """Matches a set of (kind, pat, source) against a 'root' directory. |
485 |
485 |
486 >>> kindpats = [ |
486 >>> kindpats = [ |
487 ... (b're', b'.*\.c$', b''), |
487 ... (b're', br'.*\.c$', b''), |
488 ... (b'path', b'foo/a', b''), |
488 ... (b'path', b'foo/a', b''), |
489 ... (b'relpath', b'b', b''), |
489 ... (b'relpath', b'b', b''), |
490 ... (b'glob', b'*.h', b''), |
490 ... (b'glob', b'*.h', b''), |
491 ... ] |
491 ... ] |
492 >>> m = patternmatcher(b'foo', kindpats) |
492 >>> m = patternmatcher(b'foo', kindpats) |
649 |
649 |
650 class exactmatcher(basematcher): |
650 class exactmatcher(basematcher): |
651 r'''Matches the input files exactly. They are interpreted as paths, not |
651 r'''Matches the input files exactly. They are interpreted as paths, not |
652 patterns (so no kind-prefixes). |
652 patterns (so no kind-prefixes). |
653 |
653 |
654 >>> m = exactmatcher([b'a.txt', b're:.*\.c$']) |
654 >>> m = exactmatcher([b'a.txt', br're:.*\.c$']) |
655 >>> m(b'a.txt') |
655 >>> m(b'a.txt') |
656 True |
656 True |
657 >>> m(b'b.txt') |
657 >>> m(b'b.txt') |
658 False |
658 False |
659 |
659 |
662 ['a.txt', 're:.*\\.c$'] |
662 ['a.txt', 're:.*\\.c$'] |
663 |
663 |
664 So pattern 're:.*\.c$' is not considered as a regex, but as a file name |
664 So pattern 're:.*\.c$' is not considered as a regex, but as a file name |
665 >>> m(b'main.c') |
665 >>> m(b'main.c') |
666 False |
666 False |
667 >>> m(b're:.*\.c$') |
667 >>> m(br're:.*\.c$') |
668 True |
668 True |
669 ''' |
669 ''' |
670 |
670 |
671 def __init__(self, files, badfn=None): |
671 def __init__(self, files, badfn=None): |
672 super(exactmatcher, self).__init__(badfn) |
672 super(exactmatcher, self).__init__(badfn) |
1073 return ('<unionmatcher matchers=%r>' % self._matchers) |
1073 return ('<unionmatcher matchers=%r>' % self._matchers) |
1074 |
1074 |
1075 def patkind(pattern, default=None): |
1075 def patkind(pattern, default=None): |
1076 '''If pattern is 'kind:pat' with a known kind, return kind. |
1076 '''If pattern is 'kind:pat' with a known kind, return kind. |
1077 |
1077 |
1078 >>> patkind(b're:.*\.c$') |
1078 >>> patkind(br're:.*\.c$') |
1079 're' |
1079 're' |
1080 >>> patkind(b'glob:*.c') |
1080 >>> patkind(b'glob:*.c') |
1081 'glob' |
1081 'glob' |
1082 >>> patkind(b'relpath:test.py') |
1082 >>> patkind(b'relpath:test.py') |
1083 'relpath' |
1083 'relpath' |