Read the accept-list file and return a compiled regex (or None).
(path)
| 408 | |
| 409 | |
| 410 | def load_accept_patterns(path): |
| 411 | """Read the accept-list file and return a compiled regex (or None).""" |
| 412 | if not path or not os.path.exists(path): |
| 413 | return None |
| 414 | raw_patterns = [] |
| 415 | with open(path, "r", encoding="utf-8") as fh: |
| 416 | for line in fh: |
| 417 | line = line.strip() |
| 418 | if not line or line.startswith("#"): |
| 419 | continue |
| 420 | raw_patterns.append(f"(?:{line})") |
| 421 | if not raw_patterns: |
| 422 | return None |
| 423 | combined = r"(?:" + "|".join(raw_patterns) + r")" |
| 424 | # Match must consume the entire flagged span and be at a word boundary. |
| 425 | return re.compile(rf"\A(?:{combined})\Z") |
| 426 | |
| 427 | |
| 428 | _CONTEXT_CODE_RE = re.compile(r"[._][a-zA-Z_][a-zA-Z0-9_]*") |