o
    —¨Êhù  ã                   @  s    d Z ddlmZ ddlZddlZdadd„ Zdd„ Zej 	d¡r&dd	d
„Z
nddd
„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zddd„Zddd„ZdS ) z®Text encoding utilities.

Utilities to encode text, and to safely emit text from running
applications without crashing from the infamous
:exc:`UnicodeDecodeError` exception.
é    )ÚannotationsNc                 C  s   | a dS )z'Set file used to get codec information.N©Údefault_encoding_file©Úfile© r   úF/var/www/html/env/lib/python3.10/site-packages/kombu/utils/encoding.pyÚset_default_encoding_file   s   r	   c                   C  s   t S )z'Get file used to get codec information.r   r   r   r   r   Úget_default_encoding_file   ó   r
   Újavac                 C  s   dS )úGet default encoding.zutf-8r   r   r   r   r   Údefault_encoding    r   r   c                 C  s   | pt ƒ } t| ddƒpt ¡ S )r   ÚencodingN)r
   ÚgetattrÚsysÚgetfilesystemencodingr   r   r   r   r   %   s   
c                 C  s   t | tƒr	|  ¡ S | S )zConvert str to bytes.)Ú
isinstanceÚstrÚencode©Úsr   r   r   Ústr_to_bytes+   ó   
r   c                 C  s   t | tƒr| jdd�S | S )zConvert bytes to str.Úreplace)Úerrors)r   ÚbytesÚdecoder   r   r   r   Úbytes_to_str2   s   
r   c                 O  ó   | S )zGet str from utf-8 encoding.r   )r   ÚargsÚkwargsr   r   r   Ú	from_utf89   r   r"   c                 C  s   t | tƒs	t| ƒS | S )zEnsure s is bytes, not str.)r   r   r   r   r   r   r   Úensure_bytes>   r   r#   c                 C  r   )zEncode using default encoding.r   )Úobjr   r   r   Údefault_encodeE   r   r%   r   c                 C  s*   t | ƒ} t| ttfƒst| |ƒS t| |ƒS )z+Safe form of str(), void of unicode errors.)r   r   r   r   Ú	safe_reprÚ	_safe_str)r   r   r   r   r   Úsafe_strJ   s   

r(   c                 C  sZ   t | tƒr| S zt| ƒW S  ty, } zd t| ƒ|d t ¡ ¡¡W  Y d }~S d }~ww )Nz!<Unrepresentable {!r}: {!r} {!r}>Ú
)r   r   Ú	ExceptionÚformatÚtypeÚjoinÚ	tracebackÚformat_stack)r   r   r   Úexcr   r   r   r'   R   s   

ÿ€ÿr'   c                 C  s(   zt | ƒW S  ty   t| |ƒ Y S w )z*Safe form of repr, void of Unicode errors.)Úreprr*   r'   )Úor   r   r   r   r&   \   s
   
ÿr&   )N)r   )r   N)Ú__doc__Ú
__future__r   r   r.   r   r	   r
   ÚplatformÚ
startswithr   r   r   r"   r#   r%   r(   r'   r&   r   r   r   r   Ú<module>   s$    



