
    01i                       S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	J
r
Jr  SSKrSSKJr  SSKJrJrJrJrJrJrJrJrJrJrJr  SSKJrJrJrJrJ r J!r!J"r"  SS	K#J$r$J%r%J&r&  SS
K'J(r(  SSK)J*r*J+r+J,r,  \RZ                  \,S4   r.\RZ                  \,S4   r/\RZ                  \,\+S4   r0\" SS9 " S S5      5       r1 " S S5      r2 " S S5      r3\" SS9 " S S5      5       r4 " S S5      r5 " S S5      r6 " S S5      r7 " S S5      r8g)zRDF4J client module.    )annotationsN)	dataclass)AnyBinaryIOIterable)BNode)RDF4JUnsupportedProtocolErrorRDFLibParserErrorRepositoryAlreadyExistsErrorRepositoryErrorRepositoryNotFoundErrorRepositoryNotHealthyErrorRepositoryResponseFormatErrorTransactionClosedErrorTransactionCommitErrorTransactionPingErrorTransactionRollbackError)build_context_parambuild_infer_param build_sparql_query_accept_headerbuild_spo_paramrdf_payload_to_streamvalidate_graph_namevalidate_no_bnodes)DATASET_DEFAULT_GRAPH_IDDatasetGraph)Result)IdentifiedNodeLiteralURIRefT)frozenc                  .    \ rS rSr% SrS\S'   S\S'   Srg)NamespaceListingResult-   z'RDF4J namespace and prefix name result.strprefix	namespace N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r)       U/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/contrib/rdf4j/client.pyr$   r$   -   s    1KNr1   r$   c                  p    \ rS rSrSrSS jr\S 5       r\S 5       rSS jr	S r
SS jrSS	 jrSS
 jrSrg)RDF4JNamespaceManager5   zA namespace manager for RDF4J repositories.

Parameters:
    identifier: The identifier of the repository.
    http_client: The httpx.Client instance.
c                    Xl         X l        g N)_identifier_http_clientself
identifierhttp_clients      r2   __init__RDF4JNamespaceManager.__init__=   s    %'r1   c                    U R                   $ r7   r9   r;   s    r2   r=   !RDF4JNamespaceManager.http_clientA          r1   c                    U R                   $ zRepository identifier.r8   rB   s    r2   r<    RDF4JNamespaceManager.identifierE        r1   c                P   SS0nU R                   R                  SU R                   S3US9nUR                  5          UR	                  5       nUS   S   nU Vs/ s H  n[        US   S	   US
   S	   S9PM     sn$ s  snf ! [        [        4 a  n[        SU 35      eSnAff = f)zList all namespace declarations in the repository.

Returns:
    list[NamespaceListingResult]: List of namespace and prefix name results.

Raises:
    RepositoryResponseFormatError: If the response format is unrecognized.
Acceptapplication/sparql-results+json/repositories//namespacesheadersresultsbindingsr'   valuer(   )r'   r(   Unrecognised response format: N)	r=   getr<   raise_for_statusjsonr$   KeyError
ValueErrorr   )r;   rP   responsedatarQ   rowerrs          r2   listRDF4JNamespaceManager.listJ   s     7
 ##''T__-[97 ( 
 	!!#	X==?D9oj1G #
 #C	 'x=1!+.w7 #   *% 	X/2PQTPU0VWW	Xs)   B  A=:B =B B%B  B%c                |    SS0nU R                   R                  SU R                   S3US9nUR                  5         g)z3Clear all namespace declarations in the repository.rK   rL   rM   rN   rO   N)r=   deleter<   rV   )r;   rP   rZ   s      r2   clearRDF4JNamespaceManager.clearh   sO     7
 ##**T__-[97 + 
 	!!#r1   c                4   U(       d  [        S5      eSS0n U R                  R                  SU R                   SU 3US9nUR	                  5         UR
                  $ ! [        R                   a%  nUR                  R                  S:X  a   SnAge SnAff = f)	zGet the namespace URI for a given prefix.

Parameters:
    prefix: The prefix to lookup.

Returns:
    The namespace URI or `None` if not found.
Prefix cannot be empty.rK   
text/plainrM   /namespaces/rO     N)
rY   r=   rU   r<   rV   texthttpxHTTPStatusErrorrZ   status_code)r;   r'   rP   rZ   r]   s        r2   rU   RDF4JNamespaceManager.getr   s     677l
		''++  1fXFPW , H %%'== $$ 	||''3.	s   AA B2BBBc                    U(       d  [        S5      eU(       d  [        S5      eSS0nU R                  R                  SU R                   SU 3UUS9nUR	                  5         g)	zSet the namespace URI for a given prefix.

!!! note
    If the prefix was previously mapped to a different namespace, this will be
    overwritten.

Parameters:
    prefix: The prefix to set.
    namespace: The namespace URI to set.
re   zNamespace cannot be empty.Content-Typerf   rM   rg   rP   contentN)rY   r=   putr<   rV   )r;   r'   r(   rP   rZ   s        r2   setRDF4JNamespaceManager.set   st     6779::L
 ##''T__-\&B ( 

 	!!#r1   c                    U(       d  [        S5      eU R                  R                  SU R                   SU 35      nUR	                  5         g)zdRemove the namespace declaration for a given prefix.

Parameters:
    prefix: The prefix to remove.
re   rM   rg   N)rY   r=   ra   r<   rV   )r;   r'   rZ   s      r2   removeRDF4JNamespaceManager.remove   sL     677##**T__-\&B
 	!!#r1   )r9   r8   Nr<   r&   r=   httpx.Client)returnzlist[NamespaceListingResult])r'   r&   rz   
str | None)r'   r&   r(   r&   )r'   r&   )r*   r+   r,   r-   r.   r>   propertyr=   r<   r^   rb   rU   rs   rv   r0   r)   r1   r2   r4   r4   5   sN    ( ! !    X<$2$2$r1   r4   c                      \ rS rSrSrSS jr\S 5       r\S 5       r\	SS j5       r
SS jrSS jrSS	 jrSS
 jrSS jrSrg)GraphStoreManager   zAn RDF4J Graph Store Protocol Client.

Parameters:
    identifier: The identifier of the repository.
    http_client: The httpx.Client instance.
c                *    Xl         X l        SU l        g )Napplication/n-triples)r8   r9   _content_typer:   s      r2   r>   GraphStoreManager.__init__   s    %'4r1   c                    U R                   $ r7   rA   rB   s    r2   r=   GraphStoreManager.http_client   rD   r1   c                    U R                   $ rF   rG   rB   s    r2   r<   GraphStoreManager.identifier   rI   r1   c                    0 n[        U [        5      (       a
  U [        :X  d(  [        U [        5      (       a  U [        [        5      :X  a   U$ [        U 5      US'   U$ )Ngraph)
isinstancer!   r   r&   )
graph_nameparamss     r2   _build_graph_name_params*GraphStoreManager._build_graph_name_params   sX    z6**66*c**c":;;   "*oF7Or1   c                n    SU R                    S3n[        U[        5      (       a  U[        :X  a  US-  nU$ )NrM   z/rdf-graphs/servicez?default)r<   r   r!   r   )r;   r   urls      r2   
_build_urlGraphStoreManager._build_url   s:    t//BCj&))j<T.T:C
r1   c                V   U(       d  [        S5      e[        U5        SU R                  0nU R                  U5      =(       d    SnU R                  R                  U R                  U5      UUS9nUR                  5         [        US9R                  UR                  U R                  S9$ )a=  Fetch all statements in the specified graph.

Parameters:
    graph_name: The graph name of the graph.

        For the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].

Returns:
    A [`Graph`][rdflib.graph.Graph] object containing all statements in the
        graph.
Graph name must be provided.rK   NrP   r   )r<   r[   format)rY   r   r   r   r=   rU   r   rV   r   parseri   )r;   r   rP   r   rZ   s        r2   rU   GraphStoreManager.get   s     ;<<J'd((
 ..z:Bd##''OOJ' ( 

 	!!#
+11t'9'9 2 
 	
r1   c                   U(       d  [        S5      e[        U5        [        U5      u  p4SU R                  0nU R	                  U5      =(       d    Sn U R
                  R                  U R                  U5      UUUS9nUR                  5         U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)zAdd statements to the specified graph.

Parameters:
    graph_name: The graph name of the graph.

        For the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].

    data: The RDF data to add.
r   ro   NrP   r   rq   )
rY   r   r   r   r   r=   postr   rV   closer;   r   r[   streamshould_closerP   r   rZ   s           r2   addGraphStoreManager.add  s     ;<<J'4T:D..
 ..z:Bd
	'',,
+	 - H %%' |    ;B( (Cc                   U(       d  [        S5      e[        U5        [        U5      u  p4SU R                  0nU R	                  U5      =(       d    Sn U R
                  R                  U R                  U5      UUUS9nUR                  5         U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)a  Overwrite statements in the specified graph.

Parameters:
    graph_name: The graph name of the graph.

        For the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].

    data: The RDF data to overwrite with.
r   ro   Nr   )
rY   r   r   r   r   r=   rr   r   rV   r   r   s           r2   	overwriteGraphStoreManager.overwrite"  s     ;<<J'4T:D..
 ..z:Bd
	''++
+	 , H %%' | r   c                    U(       d  [        S5      e[        U5        U R                  U5      =(       d    SnU R                  R	                  U R                  U5      US9nUR                  5         g)zClear all statements in the specified graph.

Parameters:
    graph_name: The graph name of the graph.

        For the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].
r   Nr   )rY   r   r   r=   ra   r   rV   r;   r   r   rZ   s       r2   rb   GraphStoreManager.clearA  s`     ;<<J'..z:Bd##**4??:+Fv*V!!#r1   )r   r9   r8   Nrx   )r   URIRef | str)r   r   rz   r   )r   r   r[   zstr | bytes | BinaryIO | Graph)r*   r+   r,   r-   r.   r>   r|   r=   r<   staticmethodr   r   rU   r   r   rb   r0   r)   r1   r2   r~   r~      sb    5
 ! !      (
@>>$r1   r~   c                  P    \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S	rS
\S'   Srg	)RepositoryListingResultiR  a  RDF4J repository listing result.

Parameters:
    identifier: Repository identifier.
    uri: Repository URI.
    readable: Whether the repository is readable by the client.
    writable: Whether the repository is writable by the client.
    title: Repository title.
r&   r<   uriboolreadablewritableNr{   titler)   )r*   r+   r,   r-   r.   r/   r   r0   r)   r1   r2   r   r   R  s'     O	HNNE:r1   r   c                  r   \ rS rSrSrSS jr\S 5       r\S 5       r\SS j5       r	\SS j5       r
SS jrSSS
 jjr\SS j5       rSS jrSS jrSS jr      S             SS jjr  S      S!S jjr   S"       S#S jjr    S$         S%S jjr\R.                  S 5       rSrg	)&
Repositoryie  zRDF4J repository client.

Parameters:
    identifier: The identifier of the repository.
    http_client: The httpx.Client instance.
c                8    Xl         X l        S U l        S U l        g r7   )r8   r9   _namespace_manager_graph_store_managerr:   s      r2   r>   Repository.__init__m  s    %'@D>B!r1   c                    U R                   $ r7   rA   rB   s    r2   r=   Repository.http_clients  rD   r1   c                    U R                   $ rF   rG   rB   s    r2   r<   Repository.identifierw  rI   r1   c                ~    U R                   c%  [        U R                  U R                  5      U l         U R                   $ )z%Namespace manager for the repository.)r   r4   r<   r=   rB   s    r2   
namespacesRepository.namespaces|  s:     ""*&;!1!1'D# &&&r1   c                ~    U R                   c%  [        U R                  U R                  5      U l         U R                   $ )z'Graph store manager for the repository.)r   r~   r<   r=   rB   s    r2   graphsRepository.graphs  s:     $$,(9!1!1)D% (((r1   c           	        SSS.n U R                   R                  SU R                   3USS9nUR                  5         g! [        R
                   a~  nUR                  R                  S:X  a  [        S	U R                   S
35      e[        S	U R                   SUR                  R                   SUR                  R                   35      eSnAff = f)zRepository health check.

Returns:
    bool: True if the repository is healthy, otherwise an error is raised.

Raises:
    RepositoryNotFoundError: If the repository is not found.
    RepositoryNotHealthyError: If the repository is not healthy.
application/sparql-queryrL   )ro   rK   rM   zASK {}rp   Trh   Repository  not found.z is not healthy.  - N)r=   r   r8   rV   rj   rk   rZ   rl   r   r   ri   )r;   rP   rZ   r]   s       r2   healthRepository.health  s     77
	'',, !1!1 23Wh - H %%'$$ 	||''3.-!$"2"2!3;?  ,d..//@AYAY@ZZ]^a^j^j^o^o]pq 	s   8A   CA9CCNc                    [        U5        0 n[        X!5        U R                  R                  SU R                   S3US9nUR                  5         U R                  UR                  5      $ )  The number of statements in the repository or in the specified graph name.

Parameters:
    graph_name: Graph name(s) to restrict to.

        The default value `None` queries all graphs.

        To query just the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].

Returns:
    The number of statements.

Raises:
    RepositoryResponseFormatError: Fails to parse the repository size.
rM   z/sizer   )r   r   r=   rU   r<   rV   _to_sizeri   r   s       r2   sizeRepository.size  sh    " 	J'!#F/##''T__-U3F ( 
 	!!#}}X]]++r1   c                     [        U 5      nUS:  a  U$ [        SU 35      e! [         a  n[        SU 35      UeS nAff = f)Nr   zInvalid repository size: z!Failed to parse repository size: )intrY   r   )r   rS   r]   s      r2   r   Repository._to_size  sY    	IEz8@AA 	/3C59	s   # # 
A<Ac                   SS0n[        X5        U(       d(  U R                  R                  SU R                   3X1S9nO,U R                  R	                  SU R                   3USU0UES9nUR                  5          [        R                  " [        R                  " UR                  5      UR                  S   R                  S5      S   S	9$ ! [         a0  n[        S
UR                  R	                  S5       SU 35      UeSnAff = f)aH  Execute a SPARQL query against the repository.

!!! note
    A POST request is used by default. If any keyword arguments are provided,
    a GET request is used instead, and the arguments are passed as query parameters.

Parameters:
    query: The SPARQL query to execute.
    **kwargs: Additional keyword arguments to include as query parameters
        in the request. See
        [RDF4J REST API - Execute SPARQL query](https://rdf4j.org/documentation/reference/rest-api/#tag/SPARQL/paths/~1repositories~1%7BrepositoryID%7D/get)
        for the list of supported query parameters.
ro   r   rM   rp   queryr   ;r   content_type$Failed to parse SPARQL query result : N)r   r=   r   r<   rU   rV   r   r   ioBytesIOrq   rP   splitrX   r
   )r;   r   kwargsrP   rZ   r]   s         r2   r   Repository.query  s    "#=>(8'',,  12G - H ''++  121&1 , H
 	!!#	<<

8++,%--n=CCCHK   	#6x7G7G7K7KN7[6\\^_b^cd	s   <AC 
D+DDc                ~    SS0nU R                   R                  SU R                   S3UUS9nUR                  5         g)zqExecute a SPARQL update operation on the repository.

Parameters:
    query: The SPARQL update query to execute.
ro   zapplication/sparql-updaterM   /statementsrp   N)r=   r   r<   rV   )r;   r   rP   rZ   s       r2   updateRepository.update  sO     "#>?##((T__-[9 ) 

 	!!#r1   c                   SS0nU R                   R                  SU R                   S3US9nUR                  5          / nUR	                  5       S   S    Hc  nUS   S	   nUS   S
   nUS:X  a  UR                  [        U5      5        M5  US:X  a  UR                  [        U5      5        MW  [        SU 35      e   U$ ! [         a  n[        SU 35      UeSnAff = f)zGet a list of all graph names in the repository.

Returns:
    A list of graph names.

Raises:
    RepositoryResponseFormatError: Fails to parse the repository graph names.
rK   rL   rM   z	/contextsrO   rQ   rR   	contextIDrS   typer   bnodezInvalid graph name type: z(Failed to parse repository graph names: N)r=   rU   r<   rV   rW   appendr!   r   rY   	Exceptionr   )r;   rP   rZ   valuesr\   rS   
value_typer]   s           r2   graph_namesRepository.graph_names  s    7
 ##''T__-Y7 ( 
 	!!#	+-F}}y1*=K(1 -f5
&MM&-07*MM%,/$'@%MNN > M 	/:3%@	s   B B? ?
C	CCc                R   [        XX45        Uc  SnSU0n0 n[        X5        [        XX#5        [        XS9  U R                  R                  SU R                   S3UUS9n	U	R                  5         / SQn
 Xj;   a#  [        5       R                  U	R                  US	9nO"[        5       R                  U	R                  US	9nU R                  R                  5        H(  nUR                  UR                  UR                   S
S9  M*     U$ ! ["         a  n[%        SU 35      UeSnAff = f):  Get RDF statements from the repository matching the filtering parameters.

!!! Note
    The terms for `subj`, `pred`, `obj` or `graph_name` cannot be
    [`BNodes`][rdflib.term.BNode].

Parameters:
    subj: Subject of the statement to filter by, or `None` to match all.
    pred: Predicate of the statement to filter by, or `None` to match all.
    obj: Object of the statement to filter by, or `None` to match all.
    graph_name: Graph name(s) to restrict to.

        The default value `None` queries all graphs.

        To query just the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].

    infer: Specifies whether inferred statements should be included in the
        result.
    content_type: The content type of the response.
        A triple-based format returns a [Graph][rdflib.graph.Graph], while a
        quad-based format returns a [`Dataset`][rdflib.graph.Dataset].

Returns:
    A [`Graph`][rdflib.graph.Graph] or [`Dataset`][rdflib.graph.Dataset] object
        with the repository namespace prefixes bound to it.
Napplication/n-quadsrK   inferrM   r   r   r   text/turtlezapplication/rdf+xmlr   TreplaceError parsing RDF: )r   r   r   r   r=   rU   r<   rV   r   r   ri   r   r   r^   bindr'   r(   r   r
   r;   subjpredobjr   r   r   rP   r   rZ   triple_formatsretvalresultr]   s                 r2   rU   Repository.get&  s%   H 	4s70L\*!#F/d0&.##''T__-[9 ( 

 	!!#

		J-HMM,O hmmLQ//..0FMM6+;+;TJ 1M 	J#&9#$?@cI	Js   6BD 
D&D!!D&c                *   [        U5      u  pE SU=(       d    S0n0 nUb  X'S'   U R                  R                  SU R                   S3UUUS9nUR	                  5         U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)$  Upload and append statements to the repository.

Parameters:
    data: The RDF data to upload.
    base_uri: The base URI to resolve against for any relative URIs in the data.
    content_type: The content type of the data. Defaults to
        `application/n-quads` when the value is `None`.
ro   r   NbaseURIrM   r   r   )r   r=   r   r<   rV   r   	r;   r[   base_urir   r   r   rP   r   rZ   s	            r2   uploadRepository.uploadi  s      5T:	%|'L7LMGF#$,y!'',,  1=	 - H %%' | s   AA8 8Bc                V   [        U5      u  pV[        U5         SU=(       d    S0n0 n[        X5        Ub  X8S'   U R                  R	                  SU R
                   S3UUUS9n	U	R                  5         U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)a  Upload and overwrite statements in the repository.

Parameters:
    data: The RDF data to upload.
    graph_name: Graph name(s) to restrict to.

        The default value `None` applies to all graphs.

        To apply to just the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].

    base_uri: The base URI to resolve against for any relative URIs in the data.
    content_type: The content type of the data. Defaults to
        `application/n-quads` when the value is `None`.
ro   r   Nr  rM   r   r   )r   r   r   r=   rr   r<   rV   r   )
r;   r[   r   r  r   r   r   rP   r   rZ   s
             r2   r   Repository.overwrite  s    ,  5T:J'	%|'L7LMG%'F3#$,y!''++  1=	 , H %%' | s   AB B(c                    [        XX45        0 n[        XT5        [        XQX#5        U R                  R	                  SU R
                   S3US9nUR                  5         g)a  Deletes statements from the repository matching the filtering parameters.

!!! Note
    The terms for `subj`, `pred`, `obj` or `graph_name` cannot be
    [`BNodes`][rdflib.term.BNode].

Parameters:
    subj: Subject of the statement to filter by, or `None` to match all.
    pred: Predicate of the statement to filter by, or `None` to match all.
    obj: Object of the statement to filter by, or `None` to match all.
    graph_name: Graph name(s) to restrict to.

        The default value `None` queries all graphs.

        To query just the default graph, use
        [`DATASET_DEFAULT_GRAPH_ID`][rdflib.graph.DATASET_DEFAULT_GRAPH_ID].
rM   r   r   N)r   r   r   r=   ra   r<   rV   )r;   r   r   r   r   r   rZ   s          r2   ra   Repository.delete  sb    0 	4s7!#F/d0##**T__-[9 + 
 	!!#r1   c              #  r   #    [         R                  U 5       nUv   SSS5        g! , (       d  f       g= f7f)a  Create a new transaction for the repository.

!!! warning

Transaction instances are not thread-safe. Do not share a single
Transaction instance across multiple threads. Each thread should create
its own transaction, or use appropriate synchronization if sharing is
required.
N)Transactioncreate)r;   txns     r2   transactionRepository.transaction  s'      %I &%%s   7&	7
47)r   r9   r8   r   rx   )rz   r4   )rz   r~   rz   r   r7   )r   &URIRef | Iterable[URIRef] | str | Nonerz   r   )r   r&   r   r&   )rz   zlist[IdentifiedNode]NNNNTNr   SubjectTyper   PredicateTyper   
ObjectTyper   r  r   r   r   r{   rz   zGraph | DatasetNNr[   (str | bytes | BinaryIO | Graph | Datasetr  r{   r   r{   )NNN)r[   r  r   r  r  r{   r   r{   )NNNN)
r   r  r   r  r   r  r   r  rz   None)r*   r+   r,   r-   r.   r>   r|   r=   r<   r   r   r   r   r   r   r   r   r   rU   r  r   ra   
contextlibcontextmanagerr  r0   r)   r1   r2   r   r   e  s   C ! !     ' ' ) ):,4 	 	$L$F !"=A#'AJAJ AJ 	AJ
 ;AJ AJ !AJ 
AJL  $#'	6  !	D >B##''6' ;' 	'
 !'V !"=A!$!$ !$ 	!$
 ;!$ 
!$F  r1   r   c                      \ rS rSrSrSS jrS rS r\S 5       r	\S 5       r
\SS j5       rS	 r\SS
 j5       rS rS rS rSSS jjrSS jrSS jr  S     SS jjr      S             SS jjr  S       S S jjrSrg)!r  i  a=  An RDF4J transaction.

!!! warning

    Transaction instances are not thread-safe. Do not share a single
    Transaction instance across multiple threads. Each thread should create
    its own transaction, or use appropriate synchronization if sharing is
    required.

Parameters:
    repo: The repository instance.
c                *    Xl         X l        SU l        g NF)_repo_url_closed)r;   repor   s      r2   r>   Transaction.__init__  s    
	"r1   c                    U $ r7   r)   rB   s    r2   	__enter__Transaction.__enter__      r1   c                    U R                   (       d&  Uc  U R                  5         g U R                  5         gg! [         a     gf = fr!  )	is_closedcommitrollbackr   r;   exc_typeexc_valexc_tbs       r2   __exit__Transaction.__exit__  sI    ~~ MMO
 	 !  	s   9 
AAc                    U R                   $ )zThe repository instance.)r"  rB   s    r2   r%  Transaction.repo  s     zzr1   c                    U R                   $ )zThe transaction URL.)r#  rB   s    r2   r   Transaction.url  s     yyr1   c                    U R                   $ )z"Whether the transaction is closed.)r$  rB   s    r2   r,  Transaction.is_closed  s     ||r1   c                <    U R                   (       a  [        S5      eg )Nz The transaction has been closed.)r,  r   rB   s    r2   _raise_for_closedTransaction._raise_for_closed  s    >>()KLL r1   c                    UR                   R                  SUR                   S35      nUR                  5         UR                  S   nU " X5      $ )zCreate a new transaction for the repository.

Parameters:
    repo: The repository instance.

Returns:
    A new Transaction instance.
rM   z/transactionsLocation)r=   r   r<   rV   rP   )clsr%  rZ   r   s       r2   r  Transaction.create  sS     ##((T__-];
 	!!#z*4~r1   c                    U R                  5         SS0nU R                  R                  R                  U R                  US9nUR
                  S:w  a%  [        SUR
                   SUR                   35      eSU l        g)	zCommit the transaction.

Raises:
    TransactionCommitError: If the transaction commit fails.
    TransactionClosedError: If the transaction is closed.
actionCOMMITr      zTransaction commit failed: r   TN)	r<  r%  r=   rr   r   rl   r   ri   r$  r;   r   rZ   s      r2   r-  Transaction.commit*  s|     	 H%99((,,TXXf,E3&(-h.B.B-C3x}}oV  r1   c                    U R                  5         U R                  R                  R                  U R                  5      nUR
                  S:w  a%  [        SUR
                   SUR                   35      eSU l        g)zRoll back the transaction.

Raises:
    TransactionRollbackError: If the transaction rollback fails.
    TransactionClosedError: If the transaction is closed.
   zTransaction rollback failed: r   TN)	r<  r%  r=   ra   r   rl   r   ri   r$  r;   rZ   s     r2   r.  Transaction.rollback:  sm     	 99((//93&*/0D0D/ESX  r1   c                    U R                  5         SS0nU R                  R                  R                  U R                  US9nUR
                  S:w  a%  [        SUR
                   SUR                   35      eg)zPing the transaction.

Raises:
    RepositoryTransactionPingError: If the transaction ping fails.
    TransactionClosedError: If the transaction is closed.
rC  PINGr   rE  zTransaction ping failed: r   N)r<  r%  r=   rr   r   rl   r   ri   rF  s      r2   pingTransaction.pingI  sx     	 F#99((,,TXXf,E3&&+H,@,@+AX]]OT  'r1   Nc                   U R                  5         [        U5        SS0n[        X!5        U R                  R                  R                  U R                  US9nUR                  5         U R                  R                  UR                  5      $ )r   rC  SIZEr   )
r<  r   r   r%  r=   rr   r   rV   r   ri   r   s       r2   r   Transaction.sizeX  sr    " 	 J'F#F/99((,,TXXf,E!!#yy!!(--00r1   c                   U R                  5         0 n[        X5        SUS.nU R                  R                  R	                  U R
                  U0 UEUES9nUR                  5          [        R                  " [        R                  " UR                  5      UR                  S   R                  S5      S   S9$ ! [         a0  n[        SUR                  R!                  S5       S	U 35      UeS
nAff = f)a  Execute a SPARQL query against the repository.

Parameters:
    query: The SPARQL query to execute.
    **kwargs: Additional keyword arguments to include as query parameters
        in the request. See
        [RDF4J REST API - Execute SPARQL query](https://rdf4j.org/documentation/reference/rest-api/#tag/SPARQL/paths/~1repositories~1%7BrepositoryID%7D/get)
        for the list of supported query parameters.
QUERY)rC  r   r   ro   r   r   r   r   r   N)r<  r   r%  r=   rr   r   rV   r   r   r   r   rq   rP   r   rX   r
   rU   )r;   r   r   rP   r   rZ   r]   s          r2   r   Transaction.queryq  s     	 "$(8#e499((,,HHg.B.B6.B - 
 	!!#	<<

8++,%--n=CCCHK   	#6x7G7G7K7KN7[6\\^_b^cd	s   'AB9 9
C3+C..C3c                    U R                  5         SUS.nU R                  R                  R                  U R                  0 UEUES9nUR                  5         g)a  Execute a SPARQL update operation on the repository.

Parameters:
    query: The SPARQL update query to execute.
    **kwargs: Additional keyword arguments to include as query parameters
        See [RDF4J REST API - Execute a transaction action](https://rdf4j.org/documentation/reference/rest-api/#tag/Transactions/paths/~1repositories~1%7BrepositoryID%7D~1transactions~1%7BtransactionID%7D/put)
        for the list of supported query parameters.
UPDATE)rC  r   r   N)r<  r%  r=   rr   r   rV   )r;   r   r   r   rZ   s        r2   r   Transaction.update  s[     	 $699((,,HH'f'' - 
 	!!#r1   c                Z   U R                  5         [        U5      u  pESU=(       d    S0nSS0nUb  X'S'    U R                  R                  R	                  U R
                  UUUS9nUR                  5         U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)r  ro   r   rC  ADDNr  r   r<  r   r%  r=   rr   r   rV   r   r  s	            r2   r  Transaction.upload  s     	 4T:!<#H3HIE" (9
	yy,,00	 1 H %%' |    A B B*c                   U R                  5         [        XX45        Uc  SnSU0nSS0n[        X5        [        XX#5        [	        XS9  U R
                  R                  R                  U R                  UUS9n	U	R                  5         / SQn
 Xj;   a#  [        5       R                  U	R                  US	9nO"[        5       R                  U	R                  US	9nU R
                  R                  R                  5        H(  nUR!                  UR"                  UR$                  S
S9  M*     U$ ! [&         a  n[)        SU 35      UeSnAff = f)r   Nr   rK   rC  GETr   r   r   r   Tr   r   )r<  r   r   r   r   r%  r=   rr   r   rV   r   r   ri   r   r   r^   r   r'   r(   r   r
   r   s                 r2   rU   Transaction.get  s6   H 	 4s70L\*"*E!2F/d0&.99((,,HH - 

 	!!#

		J-HMM,O hmmLQ))..335FMM6+;+;TJ 6M 	J#&9#$?@cI	Js   BD* *
E4EEc                Z   U R                  5         SS0n[        U5      u  pVSU=(       d    S0nUb  X$S'    U R                  R                  R	                  U R
                  UUUS9nUR                  5         U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)az  Delete statements from the repository.

!!! Note
    This function operates differently to
    [`Repository.delete`][rdflib.contrib.rdf4j.client.Repository.delete]
    as it does not use filter parameters. Instead, it expects a data payload.
    See the notes from
    [graphdb.js#Deleting](https://github.com/Ontotext-AD/graphdb.js?tab=readme-ov-file#deleting-1)
    for more information.

Parameters:
    data: The RDF data to upload.
    base_uri: The base URI to resolve against for any relative URIs in the data.
    content_type: The content type of the data. Defaults to
        `application/n-quads` when the value is `None`.
rC  DELETEro   r   Nr  r   r[  )	r;   r[   r  r   r   r   r   rP   rZ   s	            r2   ra   Transaction.delete  s    , 	 "*H!54T:!<#H3HI (9
	yy,,00	 1 H %%' | r]  )r$  r"  r#  )r%  r   r   r&   r  )r%  r   rz   r  r7   )r   r  r  r  r  r  r  )r[   r  r  r{   r   r{   rz   r  )r*   r+   r,   r-   r.   r>   r(  r3  r|   r%  r   r,  r<  classmethodr  r-  r.  rN  r   r   r   r  rU   ra   r0   r)   r1   r2   r  r    sZ   #
      M    128$(  $#'	6  !	D !"=A#'BJBJ BJ 	BJ
 ;BJ BJ !BJ 
BJN  $#'	&6& & !	&
 
& &r1   r  c                  n    \ rS rSrSrSS jr\S 5       rSS jrSS jr	 S       SS jjr
SS jrS	rg
)RepositoryManageri+  zpA client to manage server-level repository operations.

Parameters:
    http_client: The httpx.Client instance.
c                    Xl         g r7   rA   )r;   r=   s     r2   r>   RepositoryManager.__init__2  s    'r1   c                    U R                   $ r7   rA   rB   s    r2   r=   RepositoryManager.http_client5  rD   r1   c                   SS0nU R                   R                  SUS9nUR                  5          UR                  5       nUS   S   nU Vs/ s HG  n[	        US   S   US	   S   US
   S   US   S   UR                  S0 5      R                  S5      S9PMI     sn$ s  snf ! [
        [        4 a  n[        SU 35      eSnAff = f)zList all available repositories.

Returns:
    list[RepositoryListingResult]: List of repository results.

Raises:
    RepositoryResponseFormatError: If the response format is unrecognized.
rK   rL   z/repositoriesrO   rQ   rR   idrS   r   r   r   r   )r<   r   r   r   r   rT   N)r=   rU   rV   rW   r   rX   rY   r   )r;   rP   rZ   r[   rQ   r%  r]   s          r2   r^   RepositoryManager.list9  s    7
 ##'''I!!#	X==?D9oj1G $	 $D (#Dz'2UG,!*-g6!*-g6((7B/33G< $	 	 	 *% 	X/2PQTPU0VWW	Xs*   B" ABB" B" "C2C  Cc                P    [        XR                  5      nUR                  5         U$ )ag  Get a repository by ID.

!!! Note
    This performs a health check before returning the repository object.

Parameters:
    repository_id: The identifier of the repository.

Returns:
    Repository: The repository instance.

Raises:
    RepositoryNotFoundError: If the repository is not found.
    RepositoryNotHealthyError: If the repository is not healthy.
)r   r=   r   )r;   repository_idr%  s      r2   rU   RepositoryManager.getX  s"      -)9)9:r1   c                    SU0nU R                   R                  SU 3XBS9nUR                  5         U R                  U5      $ ! [        R
                   a/  nUR                  R                  S:X  a  [        SU S35      ee SnAff = f)aU  Create a new repository.

Parameters:
    repository_id: The identifier of the repository.
    data: The repository configuration in RDF.
    content_type: The repository configuration content type.

Raises:
    RepositoryAlreadyExistsError: If the repository already exists.
    RepositoryNotHealthyError: If the repository is not healthy.
ro   rM   rp   i  r   z already exists.N)	r=   rr   rV   rU   rj   rk   rZ   rl   r   )r;   ro  r[   r   rP   rZ   r]   s          r2   r  RepositoryManager.createl  s    	%|4G''++ 0' , H %%'88M**$$ 	||''3.2!-0@A  	s   AA B*BBc           	     z    U R                   R                  SU 35      nUR                  5         UR                  S:w  a6  [	        SU SUR                   SUR
                  R                  5        35      eg	! [        R                   a/  nUR                  R                  S:X  a  [        SU S35      ee S	nAff = f)
zDelete a repository.

Parameters:
    repository_id: The identifier of the repository.

Raises:
    RepositoryNotFoundError: If the repository is not found.
    RepositoryError: If the repository is not deleted successfully.
rM   rI  z9Unexpected response status code when deleting repository r   r   rh   r   r   N)r=   ra   rV   rl   r   ri   striprj   rk   rZ   r   )r;   ro  rZ   r]   s       r2   ra   RepositoryManager.delete  s    
	''../OPH%%'##s*%OP]^`aiauau`vvy  {C  {H  {H  {N  {N  {P  zQ  R  + $$ 	||''3.-M?+.VWW	s   A4A7 7B:*B55B:rA   N)r=   ry   )rz   zlist[RepositoryListingResult])ro  r&   rz   r   )r   )ro  r&   r[   r&   r   r&   rz   r   )ro  r&   rz   r  )r*   r+   r,   r-   r.   r>   r|   r=   r^   rU   r  ra   r0   r)   r1   r2   rf  rf  +  s\    ( ! !X>* BO (+;>	8r1   rf  c                      \ rS rSrSr  S       SS jjrS rS r\S 5       r	\SS j5       r
\SS	 j5       rS
 rSrg)RDF4JClienti  ab  RDF4J client.

This client and its inner management objects perform HTTP requests via
httpx and may raise httpx-specific exceptions. Errors documented by RDF4J
in its protocol specification are mapped to specific exceptions in this
library where applicable. Error mappings are documented on each management
method. The underlying httpx client is reused across requests, and
connection pooling is handled automatically by httpx.

Parameters:
    base_url: The base URL of the RDF4J server.
    auth: Authentication credentials. Can be a tuple (username, password) for
        basic auth, or a string for token-based auth (e.g., "GDB <token>")
        which is added as the Authorization header.
    timeout: Request timeout in seconds or an httpx.Timeout for fine-grained control (default: 30.0).
    kwargs: Additional keyword arguments to pass to the httpx.Client.
Nc                   UR                  S5      (       d  US-  nS n[        U[        5      (       a  UnO/[        U[        5      (       a  UR	                  S0 5      nX&S'   XdS'   [
        R                  " S	XUS.UD6U l        [        U R                  5      U l
         U R                  nUS:  a  U R                  5         [        SU S35      eg ! [
        R                   a$  nU R                  5         [        SU 35      UeS nAff = f)
N/rP   Authorization)base_urlauthtimeoutz"Failed to check protocol version:    zRDF4J server protocol version z2 is not supported. Minimum required version is 12.r)   )endswithr   tupler&   rU   rj   Clientr9   rf  r=   _repository_managerprotocolRequestErrorr   r	   )	r;   r{  r|  r}  r   
httpx_authrP   protocol_versionr]   s	            r2   r>   RDF4JClient.__init__  s      %%OH-1
dE""Jc""jjB/G'+O$ '9!LL 

CI
 $5T5E5E#F 	#}} b JJL/01A0BBtu  ! !! 	JJL/4SE:	s   C D$DDc                    U $ r7   r)   rB   s    r2   r(  RDF4JClient.__enter__  r*  r1   c                $    U R                  5         g r7   )r   r/  s       r2   r3  RDF4JClient.__exit__  s    

r1   c                    U R                   $ r7   rA   rB   s    r2   r=   RDF4JClient.http_client  rD   r1   c                    U R                   $ )z.Server-level repository management operations.)r  rB   s    r2   repositoriesRDF4JClient.repositories  s     '''r1   c                    U R                   R                  SSS0S9nUR                  5         [        UR                  R                  5       5      $ )zPThe RDF4J REST API protocol version.

Returns:
    The protocol version number.
z	/protocolrK   rf   rO   )r=   rU   rV   floatri   rt  rJ  s     r2   r  RDF4JClient.protocol  sH     ##''h=U'V!!#X]]((*++r1   c                8    U R                   R                  5         g)z"Close the underlying httpx.Client.N)r=   r   rB   s    r2   r   RDF4JClient.close  s     r1   )r9   r  )Ng      >@)r{  r&   r|  ztuple[str, str] | str | Noner}  zfloat | httpx.Timeoutr   r   )rz   rf  )rz   r  )r*   r+   r,   r-   r.   r>   r(  r3  r|   r=   r  r  r   r0   r)   r1   r2   rw  rw    s    * .2)-	!! +! '	!
 !F ! ! ( ( , ,!r1   rw  )9r.   
__future__r   r  r   typingtdataclassesr   r   r   r   rj   rdflibr   rdflib.contrib.rdf4j.exceptionsr	   r
   r   r   r   r   r   r   r   r   r   rdflib.contrib.rdf4j.utilr   r   r   r   r   r   r   rdflib.graphr   r   r   rdflib.queryr   rdflib.termr   r    r!   Unionr  r  r  r$   r4   r~   r   r   r  rf  rw  r)   r1   r2   <module>r     s    "  	  ! * *        B A  7 7ggfdl#%WWVWd*+
 $  z$ z$z]$ ]$@ $  ${ {|E EP
q qhR! R!r1   