
    4Yshy                     L    d Z ddlmZ ddlmZmZ ddlZdddZ G d de      Zy)a  

This wrapper intercepts calls through the store interface and implements
thread-safe logging of destructive operations (adds / removes) in reverse.
This is persisted on the store instance and the reverse operations are
executed In order to return the store to the state it was when the transaction
began Since the reverse operations are persisted on the store, the store
itself acts as a transaction.

Calls to commit or rollback, flush the list of reverse operations This
provides thread-safe atomicity and isolation (assuming concurrent operations
occur with different store instances), but no durability (transactions are
persisted in memory and wont  be available to reverse operations after the
system fails): A and I out of ACID.

    )Store)GraphConjunctiveGraphN)addremovec                   z    e Zd Zd ZddZddZd Zd ZddZddZ	dd	Z
dd
ZddZd Zd Zd Zd Zd Zd Zy)AuditableStorec                     || _         |j                  | _        d| _        d| _        g | _        t        j                         | _        y )NFT)storecontext_awareformula_awaretransaction_aware
reverseOps	threadingRLockrollbackLock)selfr   s     /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/stores/auditable.py__init__zAuditableStore.__init__   s?    
"00 #!%%OO-    c                 :    | j                   j                  ||      S N)r   open)r   configurationcreates      r   r   zAuditableStore.open'   s    zz}f55r   c                 8    | j                   j                          y r   )r   close)r   commit_pending_transactions     r   r   zAuditableStore.close*   s    

r   c                 :    | j                   j                  |       y r   )r   destroy)r   r   s     r   r    zAuditableStore.destroy-   s    

=)r   c                 :     | j                   j                  |i |S r   )r   query)r   argskws      r   r"   zAuditableStore.query0   s    tzz,,,r   c                 2   |\  }}}t         d   }|r|nt        j                         }|5  |&|j                  | j                  |j
                        nd }||j
                  nd }t        | j                  j                  ||            r
	 d d d        y | j                  j                  ||||df       	 | j                  j                  ||||df       | j                  j                  |||f||       d d d        y # t        $ r Y 4w xY w# 1 sw Y   y xY w)Nr   r   )destructiveOpLocksr   r   	__class__r   
identifierlisttriplesr   appendr   
ValueErrorr   )	r   triplecontextquotedspolockctxIds	            r   r   zAuditableStore.add3   s   	Aq!%(t!2 	7 & !!$**g.@.@A 
 +2*=G&&4EDJJ&&vw78	7 	7 OO""Aq!UH#=>&&1a'>? JJNNAq!9gv6	7 	7  	7 	7s6   A!D D5 C> D>	D
D	D

DDNc           
      B   |\  }}}t         d   }|r|nt        j                         }|5  |&|j                  | j                  |j
                        nd }||j
                  nd }d ||||fv r|r?|j                  |||f      D ]'  \  }}	}
	 | j                  j                  ||	|
|df       ) nt        | j                        j                  |||f      D ]2  \  }}	}
}	 | j                  j                  ||	|
|j
                  df       4 nIt        | j                  |||f|            s
	 d d d        y 	 | j                  j                  ||||df       | j                  j                  |||f|       d d d        y # t        $ r$ | j                  j                  ||	|
|df       Y %w xY w# t        $ r. | j                  j                  ||	|
|j
                  df       Y w xY w# t        $ r# | j                  j                  ||||df       Y w xY w# 1 sw Y   y xY w)Nr   r   )r&   r   r   r'   r   r(   r*   r   r   r,   r+   r   quadsr)   )r   spor.   subject	predicateobject_r3   r4   r0   r1   r2   ctxs               r   r   zAuditableStore.removeG   sJ   &)#G!(+t!2 !	F
 & !!$**g.@.@A 
 +2*=G&&4EGW==#*??GY3P#Q L1aL OO22Aq!UH3MNL )9(D(J(J )W5) U1aU OO22Aq!S^^X3VW	U DLL'9g)FPQ5!	F !	F6XOO** )WeXF
 JJw	7;WEC!	F !	F  * L OO22Aq!UE3JKL  * U OO22Aq!S^^U3STU " XOO**GYPU+VWX?!	F !	Fsx   A H E<+2H*F,"H4 G&H<)F)%H(F))H,3G#H"G##H&)HHHHHc              #      K   |\  }}}|&|j                  | j                  |j                        nd }| j                  j                  |||f|      D ]  \  \  }}}}	|||f|	f  y wr   )r'   r   r(   r*   )
r   r-   r.   suprobr0   r1   r2   cgs
             r   r*   zAuditableStore.triplesn   s     R " djj'*<*<= 	
 "ZZ//RgF 	 MIQ1ra)R-	 s   A&A(c                     |&|j                  | j                  |j                        nd }| j                  j                  |      S r   )r'   r   r(   __len__)r   r.   s     r   rB   zAuditableStore.__len__x   sE     " djj'*<*<= 	
 zz!!'**r   c              #   T   K   | j                   j                  |      D ]  }|  y wr   )r   contexts)r   r-   r;   s      r   rD   zAuditableStore.contexts   s)     ::&&v. 	CI	s   &(c                 <    | j                   j                  ||       y r   )r   bind)r   prefix	namespaces      r   rF   zAuditableStore.bind   s    

	*r   c                 8    | j                   j                  |      S r   )r   rG   )r   rH   s     r   rG   zAuditableStore.prefix   s    zz  ++r   c                 8    | j                   j                  |      S r   )r   rH   )r   rG   s     r   rH   zAuditableStore.namespace   s    zz##F++r   c                 6    | j                   j                         S r   )r   
namespacesr   s    r   rL   zAuditableStore.namespaces   s    zz$$&&r   c                     g | _         y r   )r   rM   s    r   commitzAuditableStore.commit   s	    r   c           	      Z   | j                   5  | j                  D ]t  \  }}}}}|dk(  r4| j                  j                  |||ft	        | j                  |             B| j                  j                  |||ft	        | j                  |             v g | _        d d d        y # 1 sw Y   y xY w)Nr   )r   r   r   r   r   r   )r   r8   r9   objr.   ops         r   rollbackzAuditableStore.rollback   s      	!8< 4C";JJNN )S15W3M JJ%% )S15W3M !DO	! 	! 	!s   BB!!B*)T)Fr   )__name__
__module____qualname__r   r   r   r    r"   r   r   r*   rB   rD   rF   rG   rH   rL   rO   rS    r   r   r	   r	      sT    .6*-7(%FN ++,,'!r   r	   )	__doc__rdflib.storer   rdflibr   r   r   r&   r	   rW   r   r   <module>r[      s3   "  *   E!U E!r   