Scan a text blob; yield one dict per match.
(text: str, source: str = "<stdin>")
| 116 | |
| 117 | |
| 118 | def scan_text(text: str, source: str = "<stdin>"): |
| 119 | """Scan a text blob; yield one dict per match.""" |
| 120 | for line_no, line in enumerate(text.splitlines(), start=1): |
| 121 | for name, sev, cat, rx in COMPILED: |
| 122 | for m in rx.finditer(line): |
| 123 | yield { |
| 124 | "pattern": name, |
| 125 | "severity": sev, |
| 126 | "category": cat, |
| 127 | "match": m.group(0)[:80], # truncate to avoid huge dumps |
| 128 | "source": source, |
| 129 | "line": line_no, |
| 130 | } |
| 131 | |
| 132 | |
| 133 | def scan_path(path: str): |