U
    .e                     @  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rLd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.
    )annotationsNc                 C  s   | a dS )z'Set file used to get codec information.Ndefault_encoding_filefile r   8/tmp/pip-unpacked-wheel-48hrr5dg/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   s    r
   javac                 C  s   dS )Get default encoding.zutf-8r   r   r   r   r   default_encoding    s    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+   s    
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   | S )zGet str from utf-8 encoding.r   )r   argskwargsr   r   r   	from_utf89   s    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>   s    
r    c                 C  s   | S )zEncode using default encoding.r   )objr   r   r   default_encodeE   s    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  s`   t | tr| S z
t| W S  tk
rZ } z$dt| |dt  W Y S d }~X Y nX d S )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k
r(   t| | Y S X dS )z*Safe form of repr, void of Unicode errors.N)reprr'   r$   )or   r   r   r   r#   \   s    
r#   )N)N)r   )r   N)r   )__doc__
__future__r   r   r+   r   r	   r
   platform
startswithr   r   r   r   r    r"   r%   r$   r#   r   r   r   r   <module>   s"   



