(path: Path, limit: int | None = None)
| 197 | |
| 198 | |
| 199 | def read_text(path: Path, limit: int | None = None) -> str: |
| 200 | data = path.read_bytes() |
| 201 | if limit is not None: |
| 202 | data = data[:limit] |
| 203 | for encoding in ("utf-8", "utf-8-sig", "gb18030", "latin-1"): |
| 204 | try: |
| 205 | return data.decode(encoding) |
| 206 | except UnicodeDecodeError: |
| 207 | continue |
| 208 | return data.decode("utf-8", errors="replace") |
| 209 | |
| 210 | |
| 211 | def read_json(path: Path) -> dict[str, Any]: |
no outgoing calls
no test coverage detected