
    h                     >    d dl Z d dlZd dlmZ d Zd Zd Zd Zd Z	y)    N)asyncioc                     |dk(  ryt        | t              r| j                  d      } t        j                  |       dz  }dt        |      z  }t        ||z        S )zn
    Maps the value to a node value between 0 and 4095
    using CRC, then down to one of the ring nodes.
       r   utf8i  i   )
isinstancestrencodebinasciicrc32floatint)value	ring_sizebigvalring_divisors       P/var/www/Befach/backend/env/lib/python3.12/site-packages/channels_redis/utils.py_consistent_hashr      sX    
 A~%V$^^E"U*F%	**Lv$%%    c                 f     j                    fd}t        j                  |      _         y )Nc                     j                   v r;j                      }j                   = j                  |j                                | _         | j                  |i |S )N)_layersrun_until_completeflushclose)selfargskwargslayerlooporiginal_implproxys       r   _wrapperz_wrap_close.<locals>._wrapper   sZ    5== MM$'Ed###EKKM2"
tzz4*6**r   )r   types
MethodType)r!   r   r"   r    s   `` @r   _wrap_closer%      s'    JJM+ !!(D1DJr   c                    K   	 | j                  d       d{    y7 # t        $ r | j                  d       d{  7   Y yw xY ww)zF
    Handle compatibility with redis-py 4.x and 5.x close methods
    T)close_connection_poolN)acloseAttributeErrorr   )
connections    r   _close_redisr+   &   sG     ;d;;; ;T:::;s<   A! ! A! AA AAAAc                 4   | sddigS t        | t        t        f      rt        d      g }| D ]h  }t        |t              r|j                  |       %t        |t        t        f      r|j                  |d   |d   d       V|j                  d|i       j |S )z
    Takes the value of the "hosts" argument and returns
    a list of kwargs to use for the Redis connection constructor.
    addresszredis://localhost:6379z?You must pass a list of Redis hosts, even if there is only one.r   r   )hostport)r   r   bytes
ValueErrordictappendtuplelist)hostsresultentrys      r   decode_hostsr9   0   s     4566%#u&M
 	

 FeT"MM% t}-MM58U1X>?MM9e,-  Mr   c                    | j                         } d| v r1| j                  d      }t        j                  j                  |fi | S | j                  dd      }|c| j                  d      }| j                  dd      }t        j
                  j                  |t        j
                  j                  ||      fi | S t        j                  di | S )z~
    Takes the value of the "host" argument and returns a suited connection pool to
    the corresponding redis instance.
    r-   master_nameN	sentinelssentinel_kwargs)r=    )copypopaioredisConnectionPoolfrom_urlsentinelSentinelConnectionPoolSentinel)r.   r-   r;   r<   r=   s        r   create_poolrG   J   s     99;DD((9%&&//@4@@((=$/KHH[)	((#4d;  77&&y/&R
 
 	
 ""*T**r   )
r
   r#   redisr   rA   r   r%   r+   r9   rG   r>   r   r   <module>rI      s'      %& 2;4+r   