o
    —¨Êhp  ã                   @  s€   d Z ddlmZ ddlmZ ddlmZ dZddd	d
œZG dd„ dƒZ	G dd„ dƒZ
G dd„ de
ƒZG dd„ deƒZdd„ ZdS )zScheduling Utilities.é    )Úannotations)Úcounté   )Úsymbol_by_name)Ú	FairCycleÚpriority_cycleÚround_robin_cycleÚsorted_cyclez%kombu.utils.scheduling:priority_cyclez(kombu.utils.scheduling:round_robin_cyclez#kombu.utils.scheduling:sorted_cycle)ÚpriorityÚround_robinÚsortedc                   @  s<   e Zd ZdZefdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dS )r   a2  Cycle between resources.

    Consume from a set of resources, where each resource gets
    an equal chance to be consumed from.

    Arguments:
    ---------
        fun (Callable): Callback to call.
        resources (Sequence[Any]): List of resources.
        predicate (type): Exception predicate.
    c                 C  s   || _ || _|| _d| _d S )Nr   )ÚfunÚ	resourcesÚ	predicateÚpos)Úselfr   r   r   © r   úH/var/www/html/env/lib/python3.10/site-packages/kombu/utils/scheduling.pyÚ__init__!   s   
zFairCycle.__init__c                 C  sL   	 z| j | j }|  jd7  _|W S  ty$   d| _| j s"|  ¡ ‚Y nw q)Nr   r   )r   r   Ú
IndexErrorr   )r   Úresourcer   r   r   Ú_next'   s   ÿþûzFairCycle._nextc              	   K  s\   t dƒD ]'}|  ¡ }z| j||fi |¤ŽW   S  | jy+   |t| jƒd kr)‚ Y qw dS )zGet from next resource.r   r   N)r   r   r   r   Úlenr   )r   ÚcallbackÚkwargsÚtriedr   r   r   r   Úget2   s   ÿþüzFairCycle.getc                 C  ó   dS )zClose cycle.Nr   ©r   r   r   r   Úclose=   ó    zFairCycle.closec                 C  s   dj | t| jƒd�S )z``repr(cycle)``.z/<FairCycle: {self.pos}/{size} {self.resources}>)r   Úsize)Úformatr   r   r   r   r   r   Ú__repr__@   s   
ÿzFairCycle.__repr__N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	Exceptionr   r   r   r   r#   r   r   r   r   r      s    r   c                   @  s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )r   z2Iterator that cycles between items in round-robin.Nc                 C  s   |d ur	|| _ d S g | _ d S ©N©Úitems©r   Úitr   r   r   r   I   s   zround_robin_cycle.__init__c                 C  s   || j dd…< dS )zUpdate items from iterable.Nr*   r,   r   r   r   ÚupdateL   ó   zround_robin_cycle.updatec                 C  s   | j d|… S ©zConsume n items.Nr*   ©r   Únr   r   r   ÚconsumeP   s   zround_robin_cycle.consumec                 C  s8   | j }z| | | |¡¡¡ W |S  ty   Y |S w )z,Move most recently used item to end of list.)r+   ÚappendÚpopÚindexÚ
ValueError)r   Ú	last_usedr+   r   r   r   ÚrotateT   s   þþzround_robin_cycle.rotater)   )r$   r%   r&   r'   r   r.   r3   r9   r   r   r   r   r   F   s    
r   c                   @  ó   e Zd ZdZdd„ ZdS )r   z"Cycle that repeats items in order.c                 C  r   )zUnused in this implementation.Nr   )r   r8   r   r   r   r9   a   r    zpriority_cycle.rotateN)r$   r%   r&   r'   r9   r   r   r   r   r   ^   ó    r   c                   @  r:   )r	   zCycle in sorted order.c                 C  s   t | jd|… ƒS r0   )r   r+   r1   r   r   r   r3   h   r/   zsorted_cycle.consumeN)r$   r%   r&   r'   r3   r   r   r   r   r	   e   r;   r	   c                 C  s
   t | tƒS )zGet cycle class by name.)r   ÚCYCLE_ALIASES)Únamer   r   r   Úcycle_by_namem   s   
r>   N)r'   Ú
__future__r   Ú	itertoolsr   Úimportsr   Ú__all__r<   r   r   r   r	   r>   r   r   r   r   Ú<module>   s    ý2