
    iH                    @   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZmZ ddlmZ 	 	 d	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ G d de      Z  G d de      Z! G d de      Z"y)za
Code for tying SPARQL Engine into RDFLib

These should be automatically registered with RDFLib

    )annotations)AnyMappingOptionalUnion)Graph)translateQuerytranslateUpdate)	evalQuery)
parseQueryparseUpdate)QueryUpdate)
evalUpdate)	ProcessorResultUpdateProcessor)
IdentifierNc                N    |i }t        t        |       ||      }| ||f|_        |S )z,
    Parse and translate a SPARQL Query
    )r	   r   _original_args)queryStringinitNsbaserets       NC:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/plugins/sparql/processor.pyprepareQueryr      s5     ~
K0$
?C%vt4CJ    c                N    |i }t        t        |       ||      }| ||f|_        |S )z-
    Parse and translate a SPARQL Update
    )r
   r   r   )updateStringr   r   r   s       r   prepareUpdater    %   s5     ~
+l3T6
BC&5CJr   c                F    t        | t        t        |      ||      |       y)zf
    Process a SPARQL Update Request
    returns Nothing on success or raises Exceptions on error
    N)r   r
   r   )graphr   initBindingsr   r   s        r   processUpdater$   4   s!     {<8$Gr   c                      e Zd ZddZy)SPARQLResultc                    t        j                  | |d          |j                  d      | _        |j                  d      | _        |j                  d      | _        |j                  d      | _        y )Ntype_vars_bindings	askAnswerr"   )r   __init__getvarsr*   r+   r"   )selfress     r   r,   zSPARQLResult.__init__E   sT    c'l+GGG$	
+-WWW%
r   N)r0   Mapping[str, Any])__name__
__module____qualname__r,    r   r   r&   r&   D   s    &r   r&   c                  .    e Zd Zd Z	 	 d	 	 	 	 	 	 	 ddZy)SPARQLUpdateProcessorc                    || _         y Nr"   r/   r"   s     r   r,   zSPARQLUpdateProcessor.__init__O   	    
r   Nc                |    t        |t              rt        t        |      |      }t	        | j
                  ||      S )a&  
        .. caution::

           This method can access indirectly requested network endpoints, for
           example, query processing will attempt to access network endpoints
           specified in ``SERVICE`` directives.

           When processing untrusted or potentially malicious queries, measures
           should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.
        )r   )
isinstancestrr
   r   r   r"   )r/   
strOrQueryr#   r   s       r   updatezSPARQLUpdateProcessor.updateR   s2    * j#&(Z)@PJ$**j,??r   NN)r@   zUnion[str, Update]r#   "Optional[Mapping[str, Identifier]]r   Optional[Mapping[str, Any]]returnNone)r2   r3   r4   r,   rA   r5   r   r   r7   r7   N   s@     <@.2	@&@ 9@ ,	@
 
@r   r7   c                  :    e Zd Zd Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZy)SPARQLProcessorc                    || _         y r9   r:   r;   s     r   r,   zSPARQLProcessor.__init__n   r<   r   Nc                ~    t        |t              rt        t        |      ||      }t	        | j
                  |||      S )a  
        Evaluate a query with the given initial bindings, and initial
        namespaces. The given base is used to resolve relative URIs in
        the query and will be overridden by any BASE given in the query.

        .. caution::

           This method can access indirectly requested network endpoints, for
           example, query processing will attempt to access network endpoints
           specified in ``SERVICE`` directives.

           When processing untrusted or potentially malicious queries, measures
           should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.
        )r>   r?   r	   r   r   r"   )r/   r@   r#   r   r   DEBUGs         r   queryzSPARQLProcessor.queryu   s6    6 j#&'
:(>fMJZtDDr   )NNNF)r@   zUnion[str, Query]r#   rC   r   rD   r   Optional[str]rK   boolrE   r1   )r2   r3   r4   r,   rL   r5   r   r   rH   rH   m   s\     <@.2"E%E 9E ,	E
 E E 
Er   rH   rB   )r   r?   r   rD   r   rM   rE   r   )r   r?   r   rD   r   rM   rE   r   )NNN)r"   r   r   r?   r#   rC   r   rD   r   rM   rE   rF   )#__doc__
__future__r   typingr   r   r   r   rdflib.graphr   rdflib.plugins.sparql.algebrar	   r
   rdflib.plugins.sparql.evaluater   rdflib.plugins.sparql.parserr   r   rdflib.plugins.sparql.sparqlr   r   rdflib.plugins.sparql.updater   rdflib.queryr   r   r   rdflib.termr   r   r    r$   r&   r7   rH   r5   r   r   <module>rZ      s   # 0 0  I 4 @ 6 3 ; ; "
 +/'  	" +/'  	$ 8<*. 5 (	
  
 &6 &@O @>&Ei &Er   