(path: Path, encoding: str)
| 792 | |
| 793 | |
| 794 | def _read_text_content(path: Path, encoding: str) -> tuple[str, str]: |
| 795 | if encoding != "auto": |
| 796 | return path.read_text(encoding=encoding), encoding |
| 797 | |
| 798 | raw = path.read_bytes() |
| 799 | for candidate in _candidate_encodings(): |
| 800 | try: |
| 801 | return raw.decode(candidate), candidate |
| 802 | except UnicodeDecodeError: |
| 803 | continue |
| 804 | return raw.decode("utf-8", errors="replace"), "utf-8" |
| 805 | |
| 806 | |
| 807 | def _candidate_encodings() -> List[str]: |
no test coverage detected