
    01i+                    ,   S r SSKJr  SSKrSSKrSSKJrJrJ	r	  SSK
Jr  SSKJrJrJr  \R                   (       a
  SSKJrJrJr   S     SS jjr   S         SS	 jjr S     SS
 jjr    SS jrSS jrSS jr          SS jrg)zRDF4J utility functions.    )annotationsN)DATASET_DEFAULT_GRAPH_IDDatasetGraph)prepareQuery)BNodeIdentifiedNodeURIRef)
ObjectTypePredicateTypeSubjectTypec                   Ub9  [        U[        5      (       a$  U[        :X  a  SU S'   gUR                  5       U S'   gUb2  [        U[        5      (       a  [        U5      R                  5       U S'   gUbT  [        U[        R                  5      (       a4  SR                  U Vs/ s H  o"R                  5       PM     sn5      nX0S'   gggs  snf )a.  Build the RDF4J http context query parameters dictionary.

!!! Note
    This mutates the params dictionary key `context`.

Parameters:
    params: The `httpx.Request` parameter dictionary.
    graph_name: The graph name or iterable of graph names.

        This is the `context` query parameter value.
Nnullcontext,)	
isinstancer	   r   n3strr
   tIterablejoin)params
graph_namexgraph_namess       S/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/contrib/rdf4j/util.pybuild_context_paramr      s     *Z"H"H11 &F9 *F9		Jz3$?$?":.113y		Jz1::$F$Fhh
;
1
;<'y %G	;s   #C
c                    Ub  UR                  5       U S'   Ub  UR                  5       U S'   Ub  UR                  5       U S'   gg)ac  Build the RDF4J http subj, predicate, and object query parameters dictionary.

!!! Note
    This mutates the params dictionary key `subj`, `pred`, and `obj`.

Parameters:
    params: The `httpx.Request` parameter dictionary.
    subj: The `subj` query parameter value.
    pred: The `pred` query parameter value.
    obj: The `obj` query parameter value.
Nsubjpredobj)r   )r   r   r    r!   s       r   build_spo_paramr"   -   sG    " vv
u     c                    U(       d  SU S'   gg)zBuild the RDF4J http infer query parameters dictionary.

!!! Note
    This mutates the params dictionary key `infer`.

Parameters:
    params: The `httpx.Request` parameter dictionary.
    infer: The `infer` query parameter value.
falseinferN )r   r&   s     r   build_infer_paramr(   F   s     !w r#   c                   [        U [        5      (       aO  SU ;  a  [        U 5      S:  a   [        U S5      nSnO'[        R                  " U R                  S5      5      nSnX4$ [        U [        5      (       a  [        R                  " U 5      nSnX4$ [        U [        [        45      (       a_  U R                  (       a%  [        R                  " U R                  SSS95      nO$[        R                  " U R                  S	SS95      nSnX4$ U nSnX4$ ! [        [
        4 a*    [        R                  " U R                  S5      5      nSn Nf = f)
al  Convert an RDF payload into a file-like object.

Parameters:
    data: The RDF payload.

        This can be a python `str`, `bytes`, `BinaryIO`, or a
        [`Graph`][rdflib.graph.Graph] or [`Dataset`][rdflib.graph.Dataset].

Returns:
    A tuple containing the file-like object and a boolean indicating whether the
    immediate caller should close the stream.

i  rbTzutf-8Fzapplication/n-quads)formatencodingapplication/n-triples)r   r   lenopenFileNotFoundErrorOSErrorioBytesIOencodebytesr   r   context_aware	serialize)datastreamshould_closes      r   rdf_payload_to_streamr<   W   sE     $tD	C%dD)# ZZG 45F L& % 
D%	 	 D!   
D5'*	+	+ZZ&;gNF ZZ&=PF   5 &w/ %DKK$89$%s   D 7EEc                    [        U 5      nUR                  R                  S;   a  SUS'   gUR                  R                  S;   a  SUS'   g[        SUR                  R                   35      e)zBuild the SPARQL query accept header.

!!! Note
    This mutates the headers dictionary key `Accept`.

Parameters:
    query: The SPARQL query.
)SelectQueryAskQueryzapplication/sparql-results+jsonAccept)ConstructQueryDescribeQueryr.   zUnsupported query type: N)r   algebraname
ValueError)queryheadersprepared_querys      r    build_sparql_query_accept_headerrI      sl     "%(N""&AA=				$	$(K	K33N4J4J4O4O3PQRRr#   c                    [        U [        5      (       d6  [        U [        R                  5      (       a#  [	        S U  5       5      (       a  [        S5      eg g )Nc              3  B   #    U  H  n[        U[        5      v   M     g 7fN)r   r   ).0r   s     r   	<genexpr>&validate_graph_name.<locals>.<genexpr>   s     9j
1e$$js   zGraph name must not be a BNode.)r   r   r   r   anyrE   )r   s    r   validate_graph_namerQ      sG    :u%%j!**--9j999:;; : .r#   c                    [        U [        5      (       d?  [        U[        5      (       d*  [        U[        5      (       d  [        U[        5      (       a  [        SU  SU SU 35      e[        U5        g)z@Validate that the subject, predicate, and object are not BNodes.z4Subject, predicate, and object must not be a BNode: z, N)r   r   rE   rQ   )r   r    r!   r   s       r   validate_no_bnodesrS      sh     	4dE""c5!!j%((BfBtfBse%
 	
 
#r#   rL   )r   dict[str, str]r   z8IdentifiedNode | t.Iterable[IdentifiedNode] | str | NonereturnNone)NNN)
r   rT   r   r   r    r   r!   r   rU   rV   )T)r   rT   r&   boolrU   rV   )r9   z*str | bytes | t.BinaryIO | Graph | DatasetrU   ztuple[t.BinaryIO, bool])rF   r   rG   rT   )r   (URIRef | t.Iterable[URIRef] | str | None)
r   r   r    r   r!   r   r   rX   rU   rV   )__doc__
__future__r   r3   typingr   rdflib.graphr   r   r   rdflib.plugins.sparql.processorr   rdflib.termr   r	   r
   TYPE_CHECKINGrdflib.contrib.rdf4j.clientr   r   r   r   r"   r(   r<   rI   rQ   rS   r'   r#   r   <module>ra      s	    " 	  A A 8 5 5??RR
 LP((H( 
(> 	!!
! ! 
	!
 
!6 """ 
""0 
40 0 fS$<$
$
$ 
$ 9	$
 
$r#   