
    Dh
                    d    d dl mZ d dlmZ d dlmZmZmZ erd dlm	Z	m
Z
 d dlmZ  G d d      Zy)	    )annotations)deque)TYPE_CHECKINGAnyCallable)HashableIterable)	BaseQueuec                  N    e Zd ZdZ	 d		 	 	 	 	 d
dZddZddZddZddZddZ	y)RoundRobinQueuea1  A round robin queue implemented using multiple internal queues (typically,
    FIFO queues). The internal queue must implement the following methods:
        * push(obj)
        * pop()
        * peek()
        * close()
        * __len__()
    The constructor receives a qfactory argument, which is a callable used to
    instantiate a new (internal) queue when a new key is allocated. The
    qfactory function is called with the key number as first and only argument.
    start_domains is a sequence of domains to initialize the queue with. If the
    queue was previously closed leaving some domain buckets non-empty, those
    domains should be passed in start_domains.

    The queue maintains a fifo queue of keys. The key that went last is popped
    first and the next queue for that key is then popped.
    c                    i | _         || _        |D ]   }| j                  |      | j                   |<   " t        |      | _        y N)queuesqfactoryr   	key_queue)selfr   start_domainskeys       r/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/queuelib/rrqueue.py__init__zRoundRobinQueue.__init__   sD    
    	2C#}}S1DKK	2}-    c                    || j                   vr9| j                  |      | j                  |<   | j                   j                  |       | j                  |   }|j	                  |       y r   )r   r   r   
appendleftpush)r   objr   qs       r   r   zRoundRobinQueue.push*   sP    dnn$#}}S1DKKNN%%c*KK	sr   c                z    	 | j                   d   }| j                  |   j                         S # t        $ r Y y w xY w)N)r   
IndexErrorr   peek)r   r   s     r   r    zRoundRobinQueue.peek1   sC    	..$C {{3$$&&  		s   . 	::c                .   	 	 | j                   j                         }| j                  |   }|j                         }t	        |      dk(  r| j                  |= |j                          n| j                   j                  |       |r|S # t        $ r Y y w xY w)Nr   )r   popr   r   lencloser   )r   r   r   ms       r   r"   zRoundRobinQueue.pop8   s    nn((* C AA1v{KK$	))#.!   s   B 	BBc                    g }| j                   j                         D ]1  \  }}t        |      r|j                  |       |j	                          3 |S r   )r   itemsr#   appendr$   )r   activekr   s       r   r$   zRoundRobinQueue.closeL   sJ    KK%%' 	DAq1va GGI	 r   c                r    | j                   r*t        d | j                   j                         D              S dS )Nc              3  2   K   | ]  }t        |        y wr   )r#   ).0xs     r   	<genexpr>z*RoundRobinQueue.__len__.<locals>.<genexpr>U   s     8a3q68s   r   )r   sumvalues)r   s    r   __len__zRoundRobinQueue.__len__T   s+    <@KKs84;;#5#5#788NQNr   N) )r   zCallable[[Hashable], BaseQueue]r   zIterable[Hashable]returnNone)r   r   r   r   r4   r5   )r4   z
Any | None)r4   zlist[Hashable])r4   int)
__name__
__module____qualname____doc__r   r   r    r"   r$   r2   r3   r   r   r   r      sG    * -/	.1	. *	. 
		.'(Or   r   N)
__future__r   collectionsr   typingr   r   r   collections.abcr   r	   queuelib.queuer
   r   r3   r   r   <module>r@      s(    "  / /2(IO IOr   