Process the replacement str. This usually just involves converting it to bytes. However, if it starts with `@`, we interpret the rest as a file path to read from. Raises: - IOError if the file cannot be read.
(self)
| 19 | replacement_str: str |
| 20 | |
| 21 | def read_replacement(self) -> bytes: |
| 22 | """ |
| 23 | Process the replacement str. This usually just involves converting it to bytes. |
| 24 | However, if it starts with `@`, we interpret the rest as a file path to read from. |
| 25 | |
| 26 | Raises: |
| 27 | - IOError if the file cannot be read. |
| 28 | """ |
| 29 | if self.replacement_str.startswith("@"): |
| 30 | return Path(self.replacement_str[1:]).expanduser().read_bytes() |
| 31 | else: |
| 32 | # We could cache this at some point, but unlikely to be a problem. |
| 33 | return strutils.escaped_str_to_bytes(self.replacement_str) |
| 34 | |
| 35 | |
| 36 | def parse_modify_spec(option: str, subject_is_regex: bool) -> ModifySpec: |