
    4Ysh                     b    d Z ddlmZ ddlmZ ddlZdZdZ G d de      Z	d Z
 G d	 d
e      Zy)ab  
This wrapper intercepts calls through the store interface which make use of
the REGEXTerm class to represent matches by REGEX instead of literal
comparison.

Implemented for stores that don't support this and essentially
provides the support by replacing the REGEXTerms by wildcards (None) and
matching against the results from the store it's wrapping.
    )Store)GraphN   c                       e Zd ZdZd Zd Zy)	REGEXTermz
    REGEXTerm can be used in any term slot and is interpreted as a request to
    perform a REGEX match (not a string comparison) using the value
    (pre-compiled) for checking rdf:type matches
    c                 8    t        j                  |      | _        y N)recompilecompiledExpr)selfexprs     /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/stores/regexmatching.py__init__zREGEXTerm.__init__   s    JJt,    c                 &    t         t        d      ffS )N )r   strr   s    r   
__reduce__zREGEXTerm.__reduce__!   s    CG:&&r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s    -'r   r   c                     t        d      D ]9  }t        ||   t              s||   j                  j	                  | |         r9 y y)N   FT)range
isinstancer   r   match)quad	regexQuadindexs      r   regexCompareQuadr$   %   sO    q i&	29<

,uuT%[)<* 	
 r   c                   z    e Zd Zd ZddZd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d Zy)REGEXMatchingc                 x    || _         |j                  | _        |j                  | _        |j                  | _        y r	   )storagecontext_awareformula_awaretransaction_aware)r   r(   s     r   r   zREGEXMatching.__init__/   s5    $22 %22!(!:!:r   c                 :    | j                   j                  ||      S r	   )r(   open)r   configurationcreates      r   r-   zREGEXMatching.open7   s    ||  77r   c                 8    | j                   j                          y r	   )r(   close)r   commit_pending_transactions     r   r1   zREGEXMatching.close:   s    r   c                 :    | j                   j                  |       y r	   )r(   destroy)r   r.   s     r   r4   zREGEXMatching.destroy=   s    ]+r   c                 P    |\  }}}| j                   j                  |||f||       y r	   )r(   add)r   triplecontextquotedsubject	predicateobject_s          r   r6   zREGEXMatching.add@   s+    (.%)W'9g6Hr   Nc           
      J   |\  }}}t        |t              s>t        |t              s.t        |t              s|Kt        |j                  t              r0t        |t               xr |xs d }t        |t               xr |xs d }t        |t               xr |xs d }|d uxr t        |j                  t               xr |xs d }	g }
| j                  j	                  |||f|	      D ]Z  \  \  }}}}|D ]L  }|j                  }t        ||||f||||d uxr |j                  xs |f      s8|
j                  ||||f       N \ |
D ]8  \  }}}}	| j                  j                  |||f|	xr t        | |	      xs |	       : y | j                  j                  |||f|       y r	   )	r   r   
identifierr(   triplesr$   appendremover   )r   r7   r8   r:   r;   r<   spocremoveQuadLists1p1o1cgctxs                   r   rA   zREGEXMatching.removeD   s   (.%)Ww	*)Y/'9-#
73E3Ey(Q w	22>wF$Ay)44BJdAw	22>wF$A$VZ8J8JI-V)V    N$(LL$8$8!QA$F A Rb AC..C'RS)#%##4/FG4F4FQ'	 '--r2r3.?@AA - J
1a##Q1Iq/CU4^/HqIJ LL)W =wGr   c              #   l  K   |\  }}}t        |t              s>t        |t              s.t        |t              s|Ct        |j                  t              r(t        |t               xr |xs d }t        |t               xr |xs d }t        |t               xr |xs d }|d uxr t        |j                  t               xr |xs d }	| j                  j	                  |||f|	      D ]  \  \  }
}}}g }|D ]Y  }|	D|0|j                  j
                  j                  |j                        s7|j                  |       I|j                  |       [ |smt        |
||d f|||d f      s|
||fd |D        f  y | j                  j	                  |||f|      D ]  \  \  }
}}}|
||f|f  y w)Nc              3       K   | ]  }|  y wr	   r   ).0rE   s     r   	<genexpr>z(REGEXMatching.triples.<locals>.<genexpr>   s     (Aq(As   )	r   r   r>   r(   r?   r   r    r@   r$   )r   r7   r8   r:   r;   r<   rB   rC   rD   rE   rG   rH   rI   rJ   matchingCtxsrK   s                   r   r?   zREGEXMatching.triplesj   s    (.%)Ww	*)Y/'9-#
73E3Ey(Q w	22>wF$Ay)44BJdAw	22>wF$A$VZ8J8JI-V)V  
 %)LL$8$8!QA$F B Rb! 1Cy"?g.@.@.M.M.S.SNN/ )//4$++C01  $4R&)Wd(K% r2,(AL(AAAB %)LL$8$8)W-w% ' Rb 2rlB&&'s   D,F4/'F4F4,AF4c                 8    | j                   j                  |      S r	   )r(   __len__)r   r8   s     r   rR   zREGEXMatching.__len__   s     ||##G,,r   c              #   T   K   | j                   j                  |      D ]  }|  y wr	   )r(   contexts)r   r7   rK   s      r   rT   zREGEXMatching.contexts   s+      <<((0 	CI	s   &(c                 <    | j                   j                  d|       y )N)NNN)r(   rA   )r   r>   s     r   remove_contextzREGEXMatching.remove_context   s    .
;r   c                 <    | j                   j                  ||       y r	   )r(   bind)r   prefix	namespaces      r   rX   zREGEXMatching.bind   s    &),r   c                 8    | j                   j                  |      S r	   )r(   rY   )r   rZ   s     r   rY   zREGEXMatching.prefix   s    ||""9--r   c                 8    | j                   j                  |      S r	   )r(   rZ   )r   rY   s     r   rZ   zREGEXMatching.namespace   s    ||%%f--r   c                 6    | j                   j                         S r	   )r(   
namespacesr   s    r   r^   zREGEXMatching.namespaces   s    ||&&((r   c                 8    | j                   j                          y r	   )r(   commitr   s    r   r`   zREGEXMatching.commit   s    r   c                 8    | j                   j                          y r	   )r(   rollbackr   s    r   rb   zREGEXMatching.rollback   s    r   )T)Fr	   )r   r   r   r   r-   r1   r4   r6   rA   r?   rR   rT   rV   rX   rY   rZ   r^   r`   rb   r   r   r   r&   r&   .   sV    ;8,I$HL$'L-
<-..) r   r&   )r   rdflib.storer   rdflib.graphr   r
   NATIVE_REGEXPYTHON_REGEXr   r   r$   r&   r   r   r   <module>rg      sB      
 ' 'A E A r   