Yield match and matched lines for patterns found in file at location as a tuple of (key, found text, text line). `patterns` is a list of tuples (key, compiled regex). Note: the location can be a list of lines for testing convenience.
(location, patterns)
| 48 | |
| 49 | |
| 50 | def find(location, patterns): |
| 51 | """ |
| 52 | Yield match and matched lines for patterns found in file at location as a |
| 53 | tuple of (key, found text, text line). `patterns` is a list of tuples (key, |
| 54 | compiled regex). |
| 55 | |
| 56 | Note: the location can be a list of lines for testing convenience. |
| 57 | """ |
| 58 | if TRACE: |
| 59 | from pprint import pformat |
| 60 | loc = pformat(location) |
| 61 | logger_debug('find(location=%(loc)r,\n patterns=%(patterns)r)' % locals()) |
| 62 | |
| 63 | for line_number, line in analysis.numbered_text_lines(location, demarkup=False): |
| 64 | for key, pattern in patterns: |
| 65 | for match in pattern.findall(line): |
| 66 | |
| 67 | if TRACE: |
| 68 | logger_debug('find: yielding match: key=%(key)r, ' |
| 69 | 'match=%(match)r,\n line=%(line)r' % locals()) |
| 70 | yield key, toascii(match), line, line_number |
| 71 | |
| 72 | |
| 73 | def unique_filter(matches): |