U
    ‰dƒ  ã                   @   s@   d dl Z d dlZddlmZ dd„ Zdd„ Zdd	„ Zd
d„ ZdS )é    Né   ©Ú	nativestrc                    s   ‡ fdd„}|S )zUReplace serialized JSON values with objects in a
    bulk array response (list).
    c                    s*   t | ƒD ]\}}|d k	rˆ |ƒ| |< q| S )N)Ú	enumerate)ÚbÚindexÚitem©Úd© ú@/tmp/pip-unpacked-wheel-f5h5_hbx/redis/commands/json/decoders.pyÚ_f   s    zbulk_of_jsons.<locals>._fr   )r
   r   r   r	   r   Úbulk_of_jsons   s    r   c                 C   sB   t   | ¡}|  ¡ D ]*}t|tƒr|| || d¡< | |¡ q|S )z3Decode the keys of the given dictionary with utf-8.zutf-8)ÚcopyÚkeysÚ
isinstanceÚbytesÚdecodeÚpop)ÚobjZnewobjÚkr   r   r   Údecode_dict_keys   s    

r   c                 C   sL   d}t  || ¡}|g kr$t|d ƒS d}t  || ¡}|g krHt|d ƒS | S )z½
    Attempt to parse string to native integer formats.
    One can't simply call int/float in a try/catch because there is a
    semantic difference between (for example) 15.0 and 15.
    z	^\d+.\d+$r   z^\d+$)ÚreÚfindallÚfloatÚint)r   ZfloatregÚmatchZintregr   r   r   Úunstring   s    r   c                 C   sD   t | tƒrdd„ | D ƒS t | tƒr.tt| ƒƒS t | tƒr@t| ƒS | S )zf
    Given a non-deserializable object, make a best effort to
    return a useful set of results.
    c                 S   s   g | ]}t |ƒ‘qS r   r   )Ú.0r   r   r   r   Ú
<listcomp>7   s     zdecode_list.<locals>.<listcomp>)r   Úlistr   r   r   Ústr)r   r   r   r   Údecode_list1   s    


r"   )r   r   Zhelpersr   r   r   r   r"   r   r   r   r   Ú<module>   s   
