
    i                     ~    S SK r S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr   " S	 S
\5      rg)    N)Iterable)contextmanager)	timedelta)Any)Redis)ExampleDatabase)
check_typec            	       >  ^  \ rS rSrSr\" SS9SSS.S\S	\S
\S\4U 4S jjjr	S\4S jr
S\S\4S jr\SSSS.S j5       rS rS\S\4S jrS\S\4S jrS\S\\   4S jrS\S\SS4S jrS\S\SS4S jrS\S\S\SS4S jrS \SS4S! jrS%S" jrS%S# jrS$rU =r$ )&RedisExampleDatabase   a~  Store Hypothesis examples as sets in the given :class:`~redis.Redis` datastore.

This is particularly useful for shared databases, as per the recipe
for a :class:`~hypothesis.database.MultiplexedDatabase`.

.. note::

    If a test has not been run for ``expire_after``, those examples will be allowed
    to expire.  The default time-to-live persists examples between weekly runs.
   )dayss   hypothesis-example:zhypothesis-changes)expire_after
key_prefixlistener_channelredisr   r   r   c                   > [         TU ]  5         [        [        US5        [        [        US5        [        [
        US5        [        [        US5        Xl        X l        X0l	        X@l
        S U l        g )Nr   r   r   r   )super__init__r	   r   r   bytesstrr   _expire_after_prefixr   _pubsub)selfr   r   r   r   	__class__s        U/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/hypothesis/extra/redis.pyr   RedisExampleDatabase.__init__$   s_     	5%)9lN;5*l33(*<=
)! 0     returnc                 @    SU R                   < SU R                  < S3$ )NzRedisExampleDatabase(z, expire_after=))r   r   r   s    r   __repr__RedisExampleDatabase.__repr__7   s%    #DJJ>ASAS@VVWX	
r   otherc                     [        U[        5      =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ N)
isinstancer   r   r   r   )r   r&   s     r   __eq__RedisExampleDatabase.__eq__<   sZ    u23 @

ekk)@-@ %%)?)??		
r   TN)execute_and_publish
event_type
to_publishc             '   b  #    U R                   R                  5       nUv   U H,  nUR                  U R                  U-   U R                  5        M.     U(       aT  UR                  5       nUS [        U5      *  n[        S U 5       5      (       a  Uc   eUc   eU R                  X#45        g g g 7f)Nc              3   *   #    U  H	  oS :  v   M     g7f)r   N ).0counts     r   	<genexpr>1RedisExampleDatabase._pipeline.<locals>.<genexpr>W   s     2'19's   )	r   pipelineexpirer   r   executelenany_publish)r   r,   r-   r.   reset_expire_keyspipekeychangeds           r   	_pipelineRedisExampleDatabase._pipelineD   s      zz""$
$CKKs*D,>,>? %llnG 7%6!7 78G2'222!---!---z67 3 s   B-B/c                    ^  US   [        U 4S jUS    5       5      4nT R                  R                  T R                  [        R
                  " U5      5        g )Nr   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr(   )_encoder2   vr   s     r   r4   0RedisExampleDatabase._publish.<locals>.<genexpr>]   s      C(Qa(   !   )tupler   publishr   jsondumps)r   events   ` r   r;   RedisExampleDatabase._publish\   sC    q5 C%( CCD

400$**U2CDr   valuec                 L    [         R                  " U5      R                  S5      $ )Nascii)base64	b64encodedecoder   rP   s     r   rD   RedisExampleDatabase._encode`   s    &--g66r   c                 .    [         R                  " U5      $ r(   )rS   	b64decoderV   s     r   _decodeRedisExampleDatabase._decodec   s    &&r   r>   c              #      #    U R                  USS9 nUR                  U R                  U-   5        S S S 5        WR                  5       S    S h  vN   g ! , (       d  f       N*= f N7f)NFr,   r   )r@   smembersr   r8   )r   r>   r=   s      r   fetchRedisExampleDatabase.fetchf   sQ     ^^CU^;tMM$,,,- <<<>!$$$ <;$s'   A)AA)A'A)
A$ A)c                     U R                  USX4S9 nUR                  U R                  U-   U5        S S S 5        g ! , (       d  f       g = f)Nsaver-   r.   )r@   saddr   r   r>   rP   r=   s       r   rb   RedisExampleDatabase.savek   s=    ^^CF|^LPTIIdllS(%0 MLL	    <
A
c                     U R                  USX4S9 nUR                  U R                  U-   U5        S S S 5        g ! , (       d  f       g = f)Ndeleterc   )r@   sremr   re   s       r   ri   RedisExampleDatabase.deleteo   s=    ^^CH#^NRVIIdllS(%0 ONNrg   srcdestc                    X:X  a  U R                  X#5        g U R                  XSS9 nUR                  U R                  U-   U5        UR	                  U R                  U-   U5        S S S 5        WR                  5       nUS   S:  a  U R                  SX445        US   S:  a  U R                  SX#445        g g ! , (       d  f       NZ= f)NFr]   r   ri   rI   rb   )rb   r@   rj   r   rd   r8   r;   )r   rl   rm   rP   r=   r?   s         r   moveRedisExampleDatabase.moves   s    ;IId"^^C5^ATIIdllS(%0IIdllT)51 B ,,.1:>MM8c\231:>MM6D=12  BAs   ?B;;
C	messagec                    ^  US   S:X  d   e[         R                  " US   5      nUS   nT R                  U[        U 4S jUS    5       5      45        g )Ntyperq   datar   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr(   )rZ   rE   s     r   r4   7RedisExampleDatabase._handle_message.<locals>.<genexpr>   s     @1t||ArH   rI   )rL   loads_broadcast_changerJ   )r   rq   rt   r-   s   `   r   _handle_message$RedisExampleDatabase._handle_message   sW     v)+++zz'&/*!W
@Q@@A	
r   c                     U R                   R                  5       U l        U R                  R                  " S0 U R                  U R
                  0D6  g )Nr1   )r   pubsubr   	subscriber   ry   r#   s    r   _start_listening%RedisExampleDatabase._start_listening   s<    zz((*O$"7"79M9M!NOr   c                 z    U R                   R                  5         U R                   R                  5         S U l         g r(   )r   unsubscribecloser#   s    r   _stop_listening$RedisExampleDatabase._stop_listening   s)      "r   )r   r   r   r   r   )r    N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r$   objectboolr*   r   r@   r;   rD   rZ   r   r_   rb   ri   ro   dictry   r~   r   __static_attributes____classcell__)r   s   @r   r   r      sA   	 #,"32 4!!  	!
 ! ! !&
# 


F 
t 
  !8 8.E7U 7s 7'S 'U '% %8E? %
1 1e 1 11% 1 1$ 13 3U 35 3T 3"
t 
 
P r   r   )rS   rL   collections.abcr   
contextlibr   datetimer   typingr   r   r   hypothesis.databaser   hypothesis.internal.validationr	   r   r1   r   r   <module>r      s0      $ %    / 5}? }r   