Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/tomlkit/_compat.py: 57%
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
6from typing import Any
9PY38 = sys.version_info >= (3, 8)
12def decode(string: Any, encodings: list[str] | None = None):
13 if not isinstance(string, bytes):
14 return string
16 encodings = encodings or ["utf-8", "latin1", "ascii"]
18 for encoding in encodings:
19 with contextlib.suppress(UnicodeEncodeError, UnicodeDecodeError):
20 return string.decode(encoding)
22 return string.decode(encodings[0], errors="ignore")