
    iZ                     b    d Z ddlZddlmZ ddlm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.
    N)Graph)Store   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     RC:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/plugins/stores/regexmatching.py__init__zREGEXTerm.__init__   s    JJt,    c                     t         dfS )N) )r   r   s    r   
__reduce__zREGEXTerm.__reduce__    s    5!!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#   $   sJ    qi&	29<

,uuT%[)<* 	 
 r   c                   |    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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.open6   s    ||  77r   c                 8    | j                   j                          y r	   )r'   close)r   commit_pending_transactions     r   r0   zREGEXMatching.close9   s    r   c                 :    | j                   j                  |       y r	   )r'   destroy)r   r-   s     r   r3   zREGEXMatching.destroy<   s    ]+r   c                 P    |\  }}}| j                   j                  |||f||       y r	   )r'   add)r   triplecontextquotedsubject	predicateobject_s          r   r5   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   r6   r7   r9   r:   r;   spocremoveQuadLists1p1o1cgctxs                   r   r@   zREGEXMatching.removeC   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 RbC..C'RS)#%##4/FG4F4FQ'	 '--r2r3.?@  %G -
1a##Q1Iq/CU4^/HqI - 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   ).0rD   s     r   	<genexpr>z(REGEXMatching.triples.<locals>.<genexpr>   s     (ALqLs   )	r   r   r=   r'   r>   r   r   r?   r#   )r   r6   r7   r9   r:   r;   rA   rB   rC   rD   rF   rG   rH   rI   matchingCtxsrJ   s                   r   r>   zREGEXMatching.triplesi   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 Rb!Cy"?g.@.@.M.M.S.SNN/ )//4$++C0   $4R&)Wd(K% r2,(AL(AAA %G %)LL$8$8)W-w% Rb 2rlB&&%s   D,F4/'F4F4,AF4c                 8    | j                   j                  |      S r	   )r'   __len__)r   r7   s     r   rQ   zREGEXMatching.__len__   s     ||##G,,r   c              #   T   K   | j                   j                  |      D ]  }|  y wr	   )r'   contexts)r   r6   rJ   s      r   rS   zREGEXMatching.contexts   s&      <<((0CI 1s   &(c                 <    | j                   j                  d|       y )N)NNN)r'   r@   )r   r=   s     r   remove_contextzREGEXMatching.remove_context   s    .
;r   c                 @    | j                   j                  |||       y )N)override)r'   bind)r   prefix	namespacerW   s       r   rX   zREGEXMatching.bind   s    &)h?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,   r0   r3   r5   r@   r>   rQ   rS   rU   rX   rY   rZ   r^   r`   rb   r   r   r   r%   r%   -   sW    ;8,I$HL$'L-
<@..) r   r%   )r   r
   rdflib.graphr   rdflib.storer   NATIVE_REGEXPYTHON_REGEXstrr   r#   r%   r   r   r   <module>rh      s@    
   " "A E A r   