mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 05:01:14 -07:00
* Bump requests from 2.28.1 to 2.28.2 Bumps [requests](https://github.com/psf/requests) from 2.28.1 to 2.28.2. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.28.1...v2.28.2) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Update requests==2.28.2 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from typing import Dict, Optional, Union
|
|
|
|
from .api import from_bytes
|
|
from .constant import CHARDET_CORRESPONDENCE
|
|
|
|
|
|
def detect(byte_str: bytes) -> Dict[str, Optional[Union[str, float]]]:
|
|
"""
|
|
chardet legacy method
|
|
Detect the encoding of the given byte string. It should be mostly backward-compatible.
|
|
Encoding name will match Chardet own writing whenever possible. (Not on encoding name unsupported by it)
|
|
This function is deprecated and should be used to migrate your project easily, consult the documentation for
|
|
further information. Not planned for removal.
|
|
|
|
:param byte_str: The byte sequence to examine.
|
|
"""
|
|
if not isinstance(byte_str, (bytearray, bytes)):
|
|
raise TypeError( # pragma: nocover
|
|
"Expected object of type bytes or bytearray, got: "
|
|
"{0}".format(type(byte_str))
|
|
)
|
|
|
|
if isinstance(byte_str, bytearray):
|
|
byte_str = bytes(byte_str)
|
|
|
|
r = from_bytes(byte_str).best()
|
|
|
|
encoding = r.encoding if r is not None else None
|
|
language = r.language if r is not None and r.language != "Unknown" else ""
|
|
confidence = 1.0 - r.chaos if r is not None else None
|
|
|
|
# Note: CharsetNormalizer does not return 'UTF-8-SIG' as the sig get stripped in the detection/normalization process
|
|
# but chardet does return 'utf-8-sig' and it is a valid codec name.
|
|
if r is not None and encoding == "utf_8" and r.bom:
|
|
encoding += "_sig"
|
|
|
|
return {
|
|
"encoding": encoding
|
|
if encoding not in CHARDET_CORRESPONDENCE
|
|
else CHARDET_CORRESPONDENCE[encoding],
|
|
"language": language,
|
|
"confidence": confidence,
|
|
}
|