
    h
                    n    S SK Jr  S SKJr  S SKJrJrJr  \(       a  S SKJ	r	J
r
  S SKJr   " S S5      rg)	    )annotations)deque)TYPE_CHECKINGAnyCallable)HashableIterable)	BaseQueuec                  d    \ rS rSrSr S     SS jjrSS jrSS jrSS jrSS jr	SS jr
S	rg
)RoundRobinQueue   a  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                    0 U l         Xl        U H!  nU R                  U5      U R                   U'   M#     [        U5      U l        g N)queuesqfactoryr   	key_queue)selfr   start_domainskeys       W/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/queuelib/rrqueue.py__init__RoundRobinQueue.__init__   s=    
   C#}}S1DKK !}-    c                    X R                   ;  a9  U R                  U5      U R                  U'   U R                   R                  U5        U R                  U   nUR	                  U5        g r   )r   r   r   
appendleftpush)r   objr   qs       r   r   RoundRobinQueue.push*   sN    nn$#}}S1DKKNN%%c*KK	sr   c                |     U R                   S   nU R                  U   R                  5       $ ! [         a     g f = f)N)r   
IndexErrorr   peek)r   r   s     r   r#   RoundRobinQueue.peek1   sC    	..$C {{3$$&&  		s   . 
;;c                >     U R                   R                  5       nU R                  U   nUR                  5       n[	        U5      S:X  a  U R                  U	 UR                  5         OU R                   R                  U5        U(       a  U$ M  ! [         a     g f = f)Nr   )r   popr"   r   lencloser   )r   r   r   ms       r   r&   RoundRobinQueue.pop8   s    nn((* C AA1v{KK$	))#.!   s   B 
BBc                    / nU R                   R                  5        H6  u  p#[        U5      (       a  UR                  U5        UR	                  5         M8     U$ r   )r   itemsr'   appendr(   )r   activekr   s       r   r(   RoundRobinQueue.closeL   sE    KK%%'DA1vva GGI ( r   c                |    U R                   (       a*  [        S U R                   R                  5        5       5      $ S$ )Nc              3  8   #    U  H  n[        U5      v   M     g 7fr   )r'   ).0xs     r   	<genexpr>*RoundRobinQueue.__len__.<locals>.<genexpr>U   s     8#7a3q66#7s   r   )r   sumvalues)r   s    r   __len__RoundRobinQueue.__len__T   s+    <@KKs84;;#5#5#788NQNr   )r   r   r   N) )r   zCallable[[Hashable], BaseQueue]r   zIterable[Hashable]returnNone)r   r   r   r   r<   r=   )r<   z
Any | None)r<   zlist[Hashable])r<   int)__name__
__module____qualname____firstlineno____doc__r   r   r#   r&   r(   r9   __static_attributes__r;   r   r   r   r      sG    * -/	.1	. *	. 
		.'(Or   r   N)
__future__r   collectionsr   typingr   r   r   collections.abcr   r	   queuelib.queuer
   r   r;   r   r   <module>rJ      s(    "  / /2(IO IOr   