3 �gaL � @ sl d dl mZ d dlmZ d dlmZ dZeeef Z e e d�dd�Ze e e d�d d �Ze e ed�dd�Z d S )� )�Union)� from_bytes)�TOO_SMALL_SEQUENCEzutf-8)�content�returnc C s. t }t| �tkr*tt| ��j� }|r*|j}|S )ap We default to UTF-8 if text too short, because the detection can return a random encoding leading to confusing results given the `charset_normalizer` version (< 2.0.5). >>> too_short = ']"foo"' >>> detected = from_bytes(too_short.encode()).best().encoding >>> detected 'ascii' >>> too_short.encode().decode(detected) ']"foo"' )�UTF8�lenr r �bytesZbest�encoding)r r �match� r �/usr/lib/python3.6/encoding.py�detect_encoding s r )r r r c C s |st | �}| j|d�S )z�Decode `content` using the given `encoding`. If no `encoding` is provided, the best effort is to guess it from `content`. Unicode errors are replaced. �replace)r �decode)r r r r r �smart_decode s r c C s | j |d�S )zTEncode `content` using the given `encoding`. Unicode errors are replaced. r )�encode)r r r r r �smart_encode, s r N)Ztypingr Zcharset_normalizerr Zcharset_normalizer.constantr r � bytearrayr ZContentBytes�strr r r r r r r �<module> s