Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/tomlkit/_compat.py: 54%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import annotations
3import contextlib
4import sys
7PY38 = sys.version_info >= (3, 8)
10def decode(string: str | bytes, encodings: list[str] | None = None) -> str:
11 if not isinstance(string, bytes):
12 return string
14 encodings = encodings or ["utf-8", "latin1", "ascii"]
16 for encoding in encodings:
17 with contextlib.suppress(UnicodeEncodeError, UnicodeDecodeError):
18 return string.decode(encoding)
20 return string.decode(encodings[0], errors="ignore")