U
    g                     @   s   d dl mZ G dd dZdS )   )	DataErrorc                   @   s.   e Zd ZdZdZdd Zdd Zddd	Zd
S )Encoderz=Encode strings to bytes-like and decode bytes-like to stringsencodingencoding_errorsdecode_responsesc                 C   s   || _ || _|| _d S )Nr   )selfr   r   r    r	   ;/tmp/pip-unpacked-wheel-f3sx1i9r/redis/_parsers/encoders.py__init__	   s    zEncoder.__init__c                 C   s   t |ttfr|S t |tr&tdn@t |ttfrBt| }n$t |t	sft
|j}td| dt |t	r|| j| j}|S )z=Return a bytestring or bytes-like representation of the valuezNInvalid input of type: 'bool'. Convert to a bytes, string, int or float first.zInvalid input of type: 'z2'. Convert to a bytes, string, int or float first.)
isinstancebytes
memoryviewboolr   intfloatreprencodestrtype__name__r   r   )r   valuetypenamer	   r	   r
   r      s     




zEncoder.encodeFc                 C   s:   | j s
|r6t|tr| }t|tr6|| j| j}|S )z:Return a unicode string from the bytes-like representation)r   r   r   tobytesr   decoder   r   )r   r   forcer	   r	   r
   r   %   s    


zEncoder.decodeN)F)r   
__module____qualname____doc__	__slots__r   r   r   r	   r	   r	   r
   r      s
   r   N)
exceptionsr   r   r	   r	   r	   r
   <module>   s   