Try to obtain encoding information of the source of an object.
(obj)
| 362 | |
| 363 | |
| 364 | def get_encoding(obj) -> str: |
| 365 | """Try to obtain encoding information of the source of an object.""" |
| 366 | for line in inspect.findsource(obj)[0][:2]: |
| 367 | m = _get_encoding_line_re.search(line) |
| 368 | if m: |
| 369 | return m.group(1) |
| 370 | return "utf8" |
| 371 | |
| 372 | |
| 373 | def get_encoding_file(fname: str) -> str: |