o
    ?Zc                     @   s   d 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 )zText encoding utilities.

Utilities to encode text, and to safely emit text from running
applications without crashing from the infamous
:exc:`UnicodeDecodeError` exception.
    Nc                 C   s   | a dS )z'Set file used to get codec information.Ndefault_encoding_filefile r   J/var/www/chikooza/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_str0   s   
r   c                 O      | S )zGet str from utf-8 encoding.r   )r   argskwargsr   r   r   	from_utf87   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_encodeC   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_strH   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&   P   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%   Z   s
   
r%   )N)r   )r   N)__doc__r   r-   r   r   r	   platform
startswithr   r   r   r!   r"   r$   r'   r&   r%   r   r   r   r   <module>   s"    



