(option: str, subject_is_regex: bool)
| 34 | |
| 35 | |
| 36 | def parse_modify_spec(option: str, subject_is_regex: bool) -> ModifySpec: |
| 37 | flow_filter, subject_str, replacement = parse_spec(option) |
| 38 | |
| 39 | subject = strutils.escaped_str_to_bytes(subject_str) |
| 40 | if subject_is_regex: |
| 41 | try: |
| 42 | re.compile(subject) |
| 43 | except re.error as e: |
| 44 | raise ValueError(f"Invalid regular expression {subject!r} ({e})") |
| 45 | |
| 46 | spec = ModifySpec(flow_filter, subject, replacement) |
| 47 | |
| 48 | try: |
| 49 | spec.read_replacement() |
| 50 | except OSError as e: |
| 51 | raise ValueError(f"Invalid file path: {replacement[1:]} ({e})") |
| 52 | |
| 53 | return spec |
| 54 | |
| 55 | |
| 56 | class ModifyHeaders: |
searching dependent graphs…