o
    i
                     @   s,   d dl mZ G dd dZG dd dZdS )    )Lockc                   @   s8   e Zd ZdZddgZdd Zdd Zdd	 Zd
d ZdS )ResponsibleGeneratorz?A generator that will help clean up when it is done being used.cleanupgenc                 C   s   || _ || _d S N)r   r   )selfr   r    r   [/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/plugins/stores/concurrent.py__init__	   s   
zResponsibleGenerator.__init__c                 C   s   |    d S r   )r   r   r   r   r	   __del__   s   zResponsibleGenerator.__del__c                 C   s   | S r   r   r   r   r   r	   __iter__   s   zResponsibleGenerator.__iter__c                 C   s
   t | jS r   )nextr   r   r   r   r	   __next__      
zResponsibleGenerator.__next__N)	__name__
__module____qualname____doc__	__slots__r
   r   r   r   r   r   r   r	   r      s    r   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )ConcurrentStorec                 C   s$   || _ d| _t | _g | _g | _d S Nr   )store_ConcurrentStore__visit_countr   _ConcurrentStore__lock!_ConcurrentStore__pending_removes_ConcurrentStore__pending_adds)r   r   r   r   r	   r
      s
   
zConcurrentStore.__init__c                 C   @   |\}}}| j dkr| j|||f d S | j|||f d S r   )r   r   addr   appendr   triplespor   r   r	   r   &      

zConcurrentStore.addc                 C   r   r   )r   r   remover   r   r    r   r   r	   r&   -   r%   zConcurrentStore.removec           
      c   s    |\}}}| j |||f}| j}|   t|| jD ]\}}}	|||	f|vr.|||	fV  q| jD ]#\}}}	|d u s?||krU|d u sG||krU|d u sO||	krU|||	fV  q2d S r   )r   triplesr   _ConcurrentStore__begin_readr   _ConcurrentStore__end_readr   )
r   r!   suprobgpending_removesr"   r#   r$   r   r   r	   r'   4   s    
zConcurrentStore.triplesc                 C   s
   | j  S r   )r   __len__r   r   r   r	   r/   E   r   zConcurrentStore.__len__c                 C   s&   | j }|  | jd | _|  d S )N   )r   acquirer   release)r   lockr   r   r	   __begin_readH   s   zConcurrentStore.__begin_readc                 C   s   | j }|  | jd | _| jdkrN| j}|r7| \}}}z| j|||f W n   t|||d Y |s| j}|rN| \}}}| j	|||f |s<|
  d S )Nr0   r   zNot in store to remove)r   r1   r   r   popr   r&   printr   r   r2   )r   r3   r.   r"   r#   r$   pending_addsr   r   r	   
__end_readN   s$   
zConcurrentStore.__end_readN)
r   r   r   r
   r   r&   r'   r/   r(   r)   r   r   r   r	   r      s    r   N)	threadingr   r   r   r   r   r   r	   <module>   s    