Try to obtain encoding information from a Python source file.
(fname: str)
| 371 | |
| 372 | |
| 373 | def get_encoding_file(fname: str) -> str: |
| 374 | """Try to obtain encoding information from a Python source file.""" |
| 375 | with open(fname, encoding="ascii", errors="ignore") as f: |
| 376 | for _ in range(2): |
| 377 | line = f.readline() |
| 378 | match = _get_encoding_line_re.search(line) |
| 379 | if match: |
| 380 | return match.group(1) |
| 381 | return "utf8" |
| 382 | |
| 383 | |
| 384 | def getattr_safe(obj: Any, name: str) -> Any: |