Find the text in `filename` between a line beginning with `start_prompt` and before `end_prompt`, removing empty lines.
(filename, start_prompt, end_prompt)
| 28 | |
| 29 | |
| 30 | def _find_text_in_file(filename, start_prompt, end_prompt): |
| 31 | """ |
| 32 | Find the text in `filename` between a line beginning with `start_prompt` and before `end_prompt`, removing empty |
| 33 | lines. |
| 34 | """ |
| 35 | with open(filename, "r", encoding="utf-8", newline="\n") as f: |
| 36 | lines = f.readlines() |
| 37 | # Find the start prompt. |
| 38 | start_index = 0 |
| 39 | while not lines[start_index].startswith(start_prompt): |
| 40 | start_index += 1 |
| 41 | start_index += 1 |
| 42 | |
| 43 | end_index = start_index |
| 44 | while not lines[end_index].startswith(end_prompt): |
| 45 | end_index += 1 |
| 46 | end_index -= 1 |
| 47 | |
| 48 | while len(lines[start_index]) <= 1: |
| 49 | start_index += 1 |
| 50 | while len(lines[end_index]) <= 1: |
| 51 | end_index -= 1 |
| 52 | end_index += 1 |
| 53 | return "".join(lines[start_index:end_index]), start_index, end_index, lines |
| 54 | |
| 55 | |
| 56 | # Add here suffixes that are used to identify models, separated by | |