U
    dN	                     @   s   d dl mZ d dlmZ d dlmZmZmZmZ zd dl	Z	dZ
W n ek
rX   dZ
Y nX zd dlZdZW n ek
r   dZY nX dd Zed	d
 Zeeef edddZdd Zeeef eeef dddZdd Zdd ZdddZdddZdS )    )contextmanagerwraps)AnyDictMappingUnionNTFc                 K   s   ddl m} |j| f|S )z
    Returns an active Redis client generated from the given database URL.

    Will attempt to extract the database id from the path url fragment, if
    none is provided.
    r   )Redis)Zredis.clientr	   from_url)urlkwargsr	    r   //tmp/pip-unpacked-wheel-f5h5_hbx/redis/utils.pyr
      s    r
   c                 c   s   |   }|V  |  d S N)pipelineexecute)Z	redis_objpr   r   r   r       s    r   )valuereturnc                 C   s   t | tr| jdddS | S )Nzutf-8replace)errors)
isinstancebytesdecoder   r   r   r   str_if_bytes'   s    r   c                 C   s   t t| S r   )strr   r   r   r   r   safe_str-   s    r   )dictsr   c                  G   s   i }| D ]}| | q|S )za
    Merge all provided dicts into 1 dict.
    *dicts : `dict`
        dictionaries to merge
    )update)r   mergeddr   r   r   
dict_merge1   s    r"   c                 C   s   t | |S r   )dictfromkeys)Zkey_listcallbackr   r   r   list_keys_to_dict?   s    r&   c                 C   s0   t  }| D ]}|D ]}|| qqt|S )z
    Merge all items in `res` into a list.

    This command is used when sending a command to multiple nodes
    and the result from each node should be merged into a single list.

    res : 'dict'
    )setvaluesaddlist)commandresresultvr   r   r   r   merge_resultC   s
    	r/       c                 C   sP   dd l }d|  d}|r(|d| d7 }|r<|d| d7 }|j|t|d d S )Nr   zCall to deprecated .z ()z -- Deprecated since version )category
stacklevel)warningswarnDeprecationWarning)namereasonversionr5   r6   msgr   r   r   warn_deprecatedU   s    r=   c                    s    fdd}|S )z5
    Decorator to mark a function as deprecated.
    c                    s   t   fdd}|S )Nc                     s    t p
 jdd  | |S )N   )r5   )r=   __name__)argsr   )funcr9   r:   r;   r   r   wrapperf   s    z7deprecated_function.<locals>.decorator.<locals>.wrapperr   )rA   rB   r9   r:   r;   )rA   r   	decoratore   s    z&deprecated_function.<locals>.decoratorr   )r:   r;   r9   rD   r   rC   r   deprecated_function`   s    rE   )r0   r0   r1   )r0   r0   N)
contextlibr   	functoolsr   typingr   r   r   r   ZhiredisZHIREDIS_AVAILABLEImportErrorZcryptographyZCRYPTOGRAPHY_AVAILABLEr
   r   r   r   r   r   r"   r&   r/   r=   rE   r   r   r   r   <module>   s,   


 
