o
     JAf,                     @   s   	 d dl Z d dlZd dlmZ d dlmZmZ d dlmZ zd dl	m
Z
 W n ey0   dZ
Y nw g dZzd dl	mZ W n eyN   G dd	 d	eZY nw G d
d deZG dd dZG dd deZG dd deZG dd dZe
du r}eZ
dS dS )    N)deque)heappushheappop)	monotonic)SimpleQueue)EmptyFullQueuePriorityQueue	LifoQueuer   )r   c                   @      e Zd Z	 dS )r   N__name__
__module____qualname__ r   r   /usr/lib/python3.10/queue.pyr          r   c                   @   r   )r   Nr   r   r   r   r   r      r   r   c                   @   s   e Zd Z	 d ddZdd Zdd Zdd	 Zd
d Zdd Zd!ddZ	d!ddZ
dd Zdd Zdd Zdd Zdd Zdd ZeejZdS )"r	   r   c                 C   sN   || _ | | t | _t| j| _t| j| _t| j| _d| _	d S Nr   )
maxsize_init	threadingLockmutex	Condition	not_emptynot_fullall_tasks_doneunfinished_tasksselfr   r   r   r   __init__"   s   


zQueue.__init__c                 C   s`   	 | j " | jd }|dkr|dk rtd| j   || _W d    d S 1 s)w   Y  d S )N   r   z!task_done() called too many times)r   r   
ValueError
notify_all)r    
unfinishedr   r   r   	task_done9   s   

"zQueue.task_donec                 C   sT   	 | j  | jr| j   | jsW d    d S W d    d S 1 s#w   Y  d S N)r   r   waitr    r   r   r   joinO   s   
"z
Queue.joinc                 C   s4   	 | j  |  W  d    S 1 sw   Y  d S r'   r   _qsizer)   r   r   r   qsize\   s   $zQueue.qsizec                 C   s6   	 | j  |   W  d    S 1 sw   Y  d S r'   r+   r)   r   r   r   emptya   s   
$zQueue.emptyc                 C   sJ   	 | j  d| j  k o|  kn  W  d    S 1 sw   Y  d S r   )r   r   r,   r)   r   r   r   fullo   s   $z
Queue.fullTNc                 C   s   	 | j o | jdkrZ|s|  | jkrtnD|d u r.|  | jkr-| j   |  | jks!n,|dk r6tdt | }|  | jkrZ|t  }|dkrMt| j | |  | jksB| | |  jd7  _| j	
  W d    d S 1 svw   Y  d S )Nr   ''timeout' must be a non-negative number        r"   )r   r   r,   r   r(   r#   time_putr   r   notify)r    itemblocktimeoutendtime	remainingr   r   r   putz   s2   





"z	Queue.putc                 C   s   	 | j T |s|  stn8|d u r |  s| j   |  rn&|dk r(tdt | }|  sF|t  }|dkr<t| j | |  r1|  }| j  |W  d    S 1 s[w   Y  d S )Nr   r0   r1   )	r   r,   r   r(   r#   r2   _getr   r4   )r    r6   r7   r8   r9   r5   r   r   r   get   s0   




$z	Queue.getc                 C      	 | j |ddS NF)r6   r:   r    r5   r   r   r   
put_nowait      zQueue.put_nowaitc                 C      	 | j ddS r>   r<   r)   r   r   r   
get_nowait      zQueue.get_nowaitc                 C   s   t  | _d S r'   )r   queuer   r   r   r   r      s   zQueue._initc                 C   
   t | jS r'   lenrG   r)   r   r   r   r,         
zQueue._qsizec                 C      | j | d S r'   rG   appendr@   r   r   r   r3         z
Queue._putc                 C   
   | j  S r'   )rG   popleftr)   r   r   r   r;      rK   z
Queue._get)r   TN)r   r   r   r!   r&   r*   r-   r.   r/   r:   r<   rA   rE   r   r,   r3   r;   classmethodtypesGenericAlias__class_getitem__r   r   r   r   r	      s"    


 r	   c                   @   .   e Zd Z	 dd Zdd Zdd Zdd Zd	S )
r
   c                 C   
   g | _ d S r'   rG   r   r   r   r   r      rK   zPriorityQueue._initc                 C   rH   r'   rI   r)   r   r   r   r,      rK   zPriorityQueue._qsizec                 C   s   t | j| d S r'   )r   rG   r@   r   r   r   r3      rO   zPriorityQueue._putc                 C   rH   r'   )r   rG   r)   r   r   r   r;      rK   zPriorityQueue._getNr   r   r   r   r,   r3   r;   r   r   r   r   r
      s    r
   c                   @   rW   )
r   c                 C   rX   r'   rY   r   r   r   r   r      rK   zLifoQueue._initc                 C   rH   r'   rI   r)   r   r   r   r,      rK   zLifoQueue._qsizec                 C   rL   r'   rM   r@   r   r   r   r3      rO   zLifoQueue._putc                 C   rP   r'   )rG   popr)   r   r   r   r;      rK   zLifoQueue._getNrZ   r   r   r   r   r      s    r   c                   @   sT   e Zd Z	 dd ZdddZdddZd	d
 Zdd Zdd Zdd Z	e
ejZdS )_PySimpleQueuec                 C   s   t  | _td| _d S r   )r   _queuer   	Semaphore_countr)   r   r   r   r!     s   z_PySimpleQueue.__init__TNc                 C   s   	 | j | | j  d S r'   )r]   rN   r_   release)r    r5   r6   r7   r   r   r   r:     s   z_PySimpleQueue.putc                 C   s6   	 |d ur|dk rt d| j||st| j S )Nr   r0   )r#   r_   acquirer   r]   rQ   )r    r6   r7   r   r   r   r<     s   

z_PySimpleQueue.getc                 C   r=   r>   r?   r@   r   r   r   rA   *  rB   z_PySimpleQueue.put_nowaitc                 C   rC   r>   rD   r)   r   r   r   rE   2  rF   z_PySimpleQueue.get_nowaitc                 C   s   	 t | jdkS r   rJ   r]   r)   r   r   r   r.   :  s   z_PySimpleQueue.emptyc                 C   s   	 t | jS r'   rb   r)   r   r   r   r-   >  s   
z_PySimpleQueue.qsizerR   )r   r   r   r!   r:   r<   rA   rE   r.   r-   rS   rT   rU   rV   r   r   r   r   r\     s    	

	r\   )r   rT   collectionsr   heapqr   r   r2   r   r]   r   ImportError__all__r   	Exceptionr   r	   r
   r   r\   r   r   r   r   <module>   s4     DC