B
    ó±ô`Ì  ã               @   s`   d Z ddlmZmZmZ eZddlmZ	 dZ
edƒZddd	„Zdd
d„Zddd„Zddd„ZdS )z,Functions for encoding and decoding strings.é    )Úabsolute_importÚdivisionÚprint_functioné   )Útypeszutf-8Ú Ústrictc             C   s   | dkrdS t | |ƒS )zgReturn the given value as bytes encoded using UTF-8 if not already bytes, or None if the value is None.N)Úto_bytes)ÚvalueÚerrors© r   úN/home/dcms/DCMS/lib/python3.7/site-packages/ansible_test/_internal/encoding.pyÚto_optional_bytes   s    r   c             C   s   | dkrdS t | |ƒS )zeReturn the given value as text decoded using UTF-8 if not already text, or None if the value is None.N)Úto_text)r
   r   r   r   r   Úto_optional_text   s    r   c             C   s8   t | tƒr| S t | tƒr$|  t|¡S tdt| ƒ ƒ‚dS )zIReturn the given value as bytes encoded using UTF-8 if not already bytes.zvalue is not bytes or text: %sN)Ú
isinstanceÚbytesÚTextÚencodeÚENCODINGÚ	ExceptionÚtype)r
   r   r   r   r   r	      s
    

r	   c             C   s8   t | tƒr|  t|¡S t | tƒr$| S tdt| ƒ ƒ‚dS )zGReturn the given value as text decoded using UTF-8 if not already text.zvalue is not bytes or text: %sN)r   r   Údecoder   r   r   r   )r
   r   r   r   r   r   !   s
    

r   N)r   )r   )r   )r   )Ú__doc__Ú
__future__r   r   r   r   Ú__metaclass__r   r   Útr   r   r   r   r	   r   r   r   r   r   Ú<module>   s   


