
    01i                   L   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	r
SSK
JrJr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!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  SSK6J7r7J8r8  SSK	J9r9  \Rt                  \;\<\Rz                  \;   \R|                  \R~                  \<   \Rt                  \;\<\Rz                  \;   4   4   \R|                  \R~                  \<   \Rt                  \;\<\Rz                  \;   4   \R~                  \<   4   4   r@\Rt                  \R                  \<\@4   \R                  \R|                  \<\@4      4   rC1 S	krD " S
 S5      rE " S S5      rF " S S\
R                  R                  R                  R                  5      rJ " S S\
R                  R                  R                  R                  5      rK " S S5      rL " S S5      rM " S S5      rN " S S5      rO " S S5      rP " S S\95      rQg)zGraphDB client module.    )annotationsN)GraphLiteralURIRef)BadRequestErrorConflictErrorForbiddenErrorInternalServerErrorNotFoundErrorPreconditionFailedErrorRepositoryNotFoundErrorRepositoryNotHealthyErrorResponseFormatErrorServiceUnavailableErrorUnauthorisedError)AccessControlEntryAuthenticatedUserBackupOperationBeanClearGraphAccessControlEntryClusterRequestFreeAccessSettingsGraphDBRepositoryImportSettingsInfrastructureStatistics
NodeStatusParserSettingsPluginAccessControlEntryRepositoryConfigBeanRepositoryConfigBeanCreateRepositorySizeInfoRepositoryStatisticsServerImportBodyStatementAccessControlEntryStructuresStatisticsSystemAccessControlEntryUser
UserCreate
UserUpdate_parse_operation_parse_plugin_parse_policy_parse_role))extract_filename_from_content_dispositioninfer_filename_from_fileobj)RDF4JClient>   pluginsystem	statementclear_graphc                      \ rS rSrSrSS jr\S 5       r\S 5       r         S                   SS jjr	SS jr
 S   SS	 jjrSS
 jrSrg)AccessControlListManagementN   zBManage fine-grained access control lists for GraphDB repositories.c                    Xl         X l        g N)_identifier_http_client)self
identifierhttp_clients      W/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/contrib/graphdb/client.py__init__$AccessControlListManagement.__init__Q   s    %'    c                    U R                   $ r8   r:   r;   s    r>   r=   'AccessControlListManagement.http_clientU          rA   c                    U R                   $ )zRepository identifier.)r9   rD   s    r>   r<   &AccessControlListManagement.identifierY   s     rA   Nc
                   0 n
Ub  U[         ;  a  [        SU< 35      eXS'   Ub  [        U5      U
S'   UbR  [        U[        5      (       a  UR                  5       U
S'   O)[        U[        5      (       a  X:S'   O[        SU< 35      eUbR  [        U[        5      (       a  UR                  5       U
S'   O)[        U[        5      (       a  XJS'   O[        SU< 35      eUbX  [        U[        [        45      (       a  UR                  5       U
S	'   O)[        U[        5      (       a  XZS	'   O[        S
U< 35      eUb  [        U[        5      (       a  UR                  5       U
S'   O\[        U[        5      (       a  UR                  R                  5       U
S'   O)[        U[        5      (       a  XjS'   O[        SU< 35      eUb  [        U5      U
S'   Ub  [        U5      U
S'   U	b  [        U	5      U
S'    U R                  R                  SU R                   S3U
S9nUR                  5          UR!                  5       n[        U[&        5      (       d  [%        S5      e U Vs/ s H  n[(        R*                  " U5      PM     sn$ ! [        ["        4 a  n[%        SU 35      UeSnAff = fs  snf ! [        ["        4 a  n[%        SU 35      UeSnAff = f! [,        R.                   a  nUR0                  R2                  nUS:X  a#  [5        SUR0                  R6                   35      UeUS:X  a#  [9        SUR0                  R6                   35      UeUS:X  a#  [;        SUR0                  R6                   35      Uee SnAff = f)a  
List ACL rules for the repository.

Parameters:
    scope: The scope of the FGAC rule (`statement`, `clear_graph`, `plugin`, `system`).
    operation: The operation of the FGAC rule (`read`, `write`, `*`).
    subject: The subject of the FGAC rule in Turtle format (for example, `<http://example.com/Mary>`).
    predicate: The predicate of the FGAC rule in Turtle format (for example, `<http://www.w3.org/2000/01/rdf-schema#label>`).
    obj: The object of the FGAC rule in Turtle format (for example, `"Mary"@en`).
    graph: The graph of the FGAC rule in Turtle format (for example, `<http://example.org/graphs/graph1>`).
    plugin: The plugin name for the FGAC rule with plugin scope (for example, `elasticsearch-connector`).
    role: The role associated with the FGAC rule.
    policy: The policy for the FGAC rule (`allow`, `deny`, `abstain`).

Returns:
    A list of FGAC rules.

Raises:
    ValueError: If the parameters are invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ResponseFormatError: If the response cannot be parsed.
NzInvalid FGAC scope filter: scope	operationsubjectzInvalid FGAC subject filter: 	predicatezInvalid FGAC predicate filter: objectzInvalid FGAC object filter: contextzInvalid FGAC graph filter: r0   rolepolicy/rest/repositories//aclparams"Failed to parse GraphDB response: zAFailed to parse GraphDB response: expected a list of ACL entries.  Request is unauthorised:   Request is forbidden:   Internal server error: )_ALLOWED_FGAC_SCOPES
ValueErrorr)   
isinstancer   n3strr   r   r<   r*   r,   r+   r:   getraise_for_statusjson	TypeErrorr   listr   	from_dicthttpxHTTPStatusErrorresponsestatus_coder   textr	   r
   )r;   rJ   rK   rL   rM   objgraphr0   rP   rQ   rU   rj   payloaderraclstatuss                   r>   rf    AccessControlListManagement.list^   s   R "$00 #>ui!HII#7O "29"=F;'6**$+JJLy!GS))$+y! #@!LMM )V,,&/lln{#Is++&/{# #B9-!PQQ?#011#&668x C%%#&x  #?w!GHH%(($)HHJy!E5))$)$4$4$7$7$9y!E3''$)y! #>ui!HII,V4F8(.F6N,V4F8%	((,,%doo%6d;F - H %%'"--/ gt,,)W ELMWc*44S9WMM 	* )8> N	* )8> $$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A 	sm   58K .J > K J2 # J-J2 J*J%%J**K -J2 2KKKK N-BM??Nc                   [        U5      n[        S U 5       5      (       a  [        S5      eU Vs/ s H  o3R                  5       PM     nnSS0n U R                  R                  SU R                   S3UUS9nUR                  5         gs  snf ! [        R                   a  nUR                  R                  nUS:X  a#  [        S	UR                  R                   35      UeUS
:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [!        SUR                  R                   35      Uee SnAff = f)a  
Set ACL rules for the repository.

!!! Note
    This method overwrites existing ACL rules in the repository.
    If you want to add new rules without overwriting existing ones,
    use the [`add`][rdflib.contrib.graphdb.client.AccessControlListManagement.add] method.

Parameters:
    acl_rules: The list of ACL rules to set.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ValueError: If the ACL rules are not provided as a sequence or are not AccessControlEntry instances.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   r_   r   .0rules     r>   	<genexpr>2AccessControlListManagement.set.<locals>.<genexpr>        SND:d$6777N   "$3All ACL rules must be AccessControlEntry instances.Content-Typeapplication/jsonrR   rS   headersrd     Invalid request: rW   rX   rY   rZ   r[   r\   N)rf   anyr^   as_dictr:   putr<   rc   rh   ri   rj   rk   r   rl   r   r	   r
   	r;   	acl_rulesacl_rules_listry   ro   r   rj   rp   rr   s	            r>   setAccessControlListManagement.set   ss   & iSNSSSRSS.<=nd<<>n=!#56	((,,%doo%6d; - H
 %%' > $$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A !	s   B9B E%%B;E  E%c                Z   [        U5      n[        S U 5       5      (       a  [        S5      eU Vs/ s H  oDR                  5       PM     nnSS0n0 nUb?  [	        U[
        5      (       d  [        S5      eUS:  a  [        S5      e[        U5      US	'    U R                  R                  S
U R                   S3UUUS9nUR                  5         gs  snf ! [        R                   a  n	U	R                  R                  n
U
S:X  a#  [        SU	R                  R                    35      U	eU
S:X  a#  [#        SU	R                  R                    35      U	eU
S:X  a#  [%        SU	R                  R                    35      U	eU
S:X  a#  ['        SU	R                  R                    35      U	ee Sn	A	ff = f)a3  
Add ACL rules to the repository.

You can also provide an optional URL request parameter position that specifies the position of the rules to be added.
The position is zero-based (0 is the first position). If the position parameter is not provided, the rules are added at
the end of the list.

Parameters:
    acl_rules: The list of ACL rules to add.
    position: The zero-based position to add the rules at.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ValueError: If the position is not an integer or is a negative integer.
    ValueError: If the ACL rules are not provided as a sequence or are not AccessControlEntry instances.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   rv   rw   s     r>   rz   2AccessControlListManagement.add.<locals>.<genexpr>#  r|   r}   r~   r   r   NzPosition must be an integer.r   z$Position must be a positive integer.positionrR   rS   r   rd   rU   r   r   rW   rX   rY   rZ   r[   r\   )rf   r   r^   r   r_   intra   r:   postr<   rc   rh   ri   rj   rk   r   rl   r   r	   r
   )r;   r   r   r   ry   ro   r   rU   rj   rp   rr   s              r>   addAccessControlListManagement.add  s   , iSNSSSRSS.<=nd<<>n=!#56h,, !?@@!| !GHH!$XF:	((--%doo%6d;	 . H %%'! >" $$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A !	s   C:C F**B;F%%F*c                   [        U5      n[        S U 5       5      (       a  [        S5      eU Vs/ s H  o3R                  5       PM     nnSS0n U R                  R                  SSU R                   S3UUS9nUR                  5         gs  snf ! [        R                   a  nUR                  R                  nUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [!        SUR                  R                   35      Uee SnAff = f)a  
Delete ACL rules from the repository.

The provided FGAC rules are removed from the list regardless of their position.

Parameters:
    acl_rules: The list of ACL rules to delete.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ValueError: If the ACL rules are not provided as a sequence or are not AccessControlEntry instances.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   rv   rw   s     r>   rz   5AccessControlListManagement.delete.<locals>.<genexpr>Z  r|   r}   r~   r   r   DELETErR   rS   methodurlr   rd   r   r   rW   rX   rY   rZ   r[   r\   N)rf   r   r^   r   r:   requestr<   rc   rh   ri   rj   rk   r   rl   r   r	   r
   r   s	            r>   delete"AccessControlListManagement.deleteI  sv     iSNSSSRSS.<=nd<<>n=!#56	((00)$//):$?	 1 H %%' > $$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A !	s   B:B E&&B;E!!E&)r:   r9   r<   ra   r=   httpx.Client)	NNNNNNNNN)rJ   z@t.Literal['statement', 'clear_graph', 'plugin', 'system'] | NonerK   z&t.Literal['read', 'write', '*'] | NonerL   str | URIRef | NonerM   r   rm   zstr | URIRef | Literal | Nonern   z:t.Literal['*', 'named', 'default'] | URIRef | Graph | Noner0   
str | NonerP   r   rQ   z,t.Literal['allow', 'deny', 'abstain'] | Nonereturnzxt.List[SystemAccessControlEntry | StatementAccessControlEntry | PluginAccessControlEntry | ClearGraphAccessControlEntry])r   t.Sequence[AccessControlEntry]r8   )r   r   r   
int | None)__name__
__module____qualname____firstlineno____doc__r?   propertyr=   r<   rf   r   r   r   __static_attributes__ rA   r>   r5   r5   N   s    L( ! !     SW<@'+)--1LP!?CzOz :z %	z
 'z +z Jz z z =z
zx0f QU;7;CM;z.rA   r5   c                  &   \ 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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SS jrSS jrS S jrS!S jrS"S jrSrg)#ClusterGroupManagementiz  z2Manage and monitor GraphDB cluster configurations.c                    Xl         g r8   rC   r;   r=   s     r>   r?   ClusterGroupManagement.__init__}      'rA   c                    U R                   $ r8   rC   rD   s    r>   r=   "ClusterGroupManagement.http_client  rF   rA   c                    U R                   R                  S5      nUR                  5         g! [        R                   a  nUR
                  R                  nUS:X  a#  [        SUR
                  R                   35      UeUS:X  a#  [        SUR
                  R                   35      UeUS:X  a#  [        SUR
                  R                   35      Uee SnAff = f)	a  Truncate the GraphDB cluster log.

The truncate log operation is used to free up storage space on all cluster nodes by clearing the
current transaction log and removing cached recovery snapshots.

Raises:
    ResponseFormatError: If the response is not in the expected format.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
z/rest/cluster/truncate-logr   r   rW   rX   rY   rZ   Nr=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r;   rj   rp   rr   s       r>   truncate_log#ClusterGroupManagement.truncate_log  s    	'',,-IJH%%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 	s   +. CBCCc                ^    SS0nU R                   R                  SUS9nUR                  5          [        R                  " UR                  5       5      $ ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [!        S
UR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      Uee SnAff = f)aT  Get the GraphDB cluster configuration.

Returns:
    Cluster configuration.

Raises:
    ResponseFormatError: If the response is not in the expected format.
    UnauthorisedError: If the request is unauthorised.
    NotFoundError: If the cluster configuration is not found.
    InternalServerError: If the server returns an internal error.
Acceptr   /rest/cluster/configr   z'Failed to parse cluster configuration: NrW   rX     z!Cluster configuration not found: r[   r\   )r=   rb   rc   r   rg   rd   KeyErrorre   r^   r   rh   ri   rj   rk   r   rl   r   r
   r;   r   rj   rp   rr   s        r>   
get_config!ClusterGroupManagement.get_config  s:   	!34G''++,BG+TH%%'%//@@i4 )=cUC $$ 	\\--F}'/0A0A/BC 3#78I8I7JK 3)-cll.?.?-@A 	5   .B #A A>*A99A>>B D,BD''D,Nc	                    [        U[        5      (       a  [        S U 5       5      (       a  [        S5      eSU4SU4SU4SU4SU4SU4S	U4/n	U	 H*  u  pUc  M
  [	        U5      [
        Ld  M  [        U
 S35      e   SU0nUb  X,S'   Ub  X<S'   Ub  XLS'   Ub  X\S'   Ub  XlS'   Ub  X|S'   Ub  XS'   SS0nU R                  R                  SXS9nUR                  5         g
! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [!        SUR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      UeUS :X  a#  [%        S!UR                  R                   35      Uee S
nAff = f)"a  Create a GraphDB cluster.

Parameters:
    nodes: List of node addresses.
    election_min_timeout: The minimum wait time in milliseconds for a heartbeat from a leader.
    election_range_timeout: The variable portion of each waiting period in milliseconds for a heartbeat.
    heartbeat_interval: The interval in milliseconds between each heartbeat that is sent to follower nodes by the leader.
    message_size_kb: The size of the data blocks, in kilobytes, transferred during data replication streaming through the RPC protocol.
    verification_timeout: The amount of time in milliseconds that a follower node would wait before attempting to verify the last committed
        entry when the first verification is unsuccessful.
    transaction_log_maximum_size_gb: Maximum size of the transaction log in GBs. The transaction log will be automatically truncated if it
        becomes bigger than this value. The minimum transaction log size is 1 GB. Setting it to a negative value will disable automatic transaction
        log truncation.
    batch_update_interval: The interval in milliseconds between requesting updates from the primary cluster. Used only when the cluster is in
        secondary mode.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    ConflictError: If the cluster configuration already exists.
    PreconditionFailedError: If the cluster is not in a state to create a configuration.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   r_   ra   rx   nodes     r>   rz   7ClusterGroupManagement.create_config.<locals>.<genexpr>  s       26;dJtS)))er}   nodes must be a list[str].election_min_timeoutelection_range_timeoutheartbeat_intervalmessage_size_kbverification_timeouttransaction_log_maximum_size_gbbatch_update_intervalN must be an int if provided.nodeselectionMinTimeoutelectionRangeTimeoutheartbeatIntervalmessageSizeKBverificationTimeouttransactionLogMaximumSizeGBbatchUpdateIntervalr   r   r   r   r   r   rW   rX   rY   rZ   i  z&Cluster configuration already exists:   Precondition failed: )r_   rf   r   re   typer   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   r   )r;   r   r   r   r   r   r   r   r   _int_fields
field_namevaluero   r   rj   rp   rr   s                    r>   create_config$ClusterGroupManagement.create_config  sk   D<	eT**c 26;2 / /   <== ()=>)+AB%'9:"O4')=>24ST(*?@9K &1!
$eC)?#zl2N$OPP &1 *1%(8G#/0D,-%12H./!-/A+,*+:(#/1E-..:9X56$01F-.%'9:G'',,& - H %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3#<S\\=N=N<OP 3-+CLL,=,=+>? )	s&   AC$ C$ 0A3C$ $G!8C$GG!c                   SnUb  S[        U5      R                  5       0n SS0nUc  U R                  R                  SUS9nOU R                  R                  SX2S9nUR	                  5          UR                  5       n[        U[        5      (       d  [        S	5      e[        S
 UR                  5        5       5      (       d  [        S5      e[        R                  " [        [         [         4   U5      $ ! [        [        4 a  n[        SU 35      UeSnAff = f! [        R                    a  nUR"                  R$                  nUS:X  a#  ['        SUR"                  R(                   35      UeUS:X  a#  [+        SUR"                  R(                   35      UeUS:X  a#  [-        SUR"                  R(                   35      Uee SnAff = f)a  Delete the GraphDB cluster.

By default, the cluster group cannot be deleted if one or more nodes are unreachable.
Reachable here means that the nodes are not in status `NO_CONNECTION`, therefore there is an
RPC connection to them.

Parameter:
    force: When set to `True`, the cluster configuration will be deleted only on the reachable nodes and
        the response will always succeed.

Returns:
    A dictionary where the node address is the key and the deletion status message is the value.

Raises:
    ResponseFormatError: If the response is not in the expected format.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If one or more nodes in the group are not reachable and force is not set to `True`.
Nforcer   r   r   r   r   rU   z+Failed to parse cluster deletion response: zBFailed to parse cluster deletion response: expected a JSON object.c              3  t   #    U  H.  u  p[        U[        5      =(       a    [        U[        5      v   M0     g 7fr8   r   )rx   keyr   s      r>   rz   7ClusterGroupManagement.delete_config.<locals>.<genexpr>S  s/      "1JC 3$?E3)??"1s   68zKFailed to parse cluster deletion response: expected string keys and values.rW   rX   rY   rZ   r   r   )ra   lowerr=   r   rc   rd   r^   re   r   r_   dictallitemstcastrh   ri   rj   rk   r   rl   r	   r   )r;   r   rU   r   rj   ro   rp   rr   s           r>   delete_config$ClusterGroupManagement.delete_config'  s   ( )-s5z//12F+	!34G~++22*G 3   ++22*G 3  %%'"--/
 gt,,)X   ")--/   *a  66$sCx.'22 	* )A#G  $$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? 	s>   AD /C7 ?A7D 7DDDD G	2BGG	c                   SU4SU4SU4SU4SU4SU4SU4/nU H*  u  pU
c  M
  [        U
5      [        Ld  M  [        U	 S	35      e   0 nUb  XS
'   Ub  X+S'   Ub  X;S'   Ub  XKS'   Ub  X[S'   Ub  XkS'   Ub  X{S'   SS0n U R                  R	                  SXS9nUR                  5          [        R                  " UR                  5       5      $ ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [!        SUR                  R"                   35      UeUS:X  a#  [%        SUR                  R"                   35      UeUS:X  a#  ['        SUR                  R"                   35      UeUS:X  a#  [)        SUR                  R"                   35      Uee SnAff = f)a  Update the GraphDB cluster configuration.

If one of the cluster nodes is down or was not able to accept the new configuration,
the operation will not be successful. A total consensus between the nodes is required.
In case one or more of them cannot append the new configuration, it will be rejected
by all of the nodes.

Parameters:
    election_min_timeout: The minimum wait time in milliseconds for a heartbeat from a leader.
    election_range_timeout: The variable portion of each waiting period in milliseconds for a heartbeat.
    heartbeat_interval: The interval in milliseconds between each heartbeat that is sent to follower nodes by the leader.
    message_size_kb: The size of the data blocks, in kilobytes, transferred during data replication streaming through the RPC protocol.
    verification_timeout: The amount of time in milliseconds that a follower node would wait before attempting to verify the last committed
        entry when the first verification is unsuccessful.
    transaction_log_maximum_size_gb: Maximum size of the transaction log in GBs. The transaction log will be automatically truncated if it
        becomes bigger than this value. The minimum transaction log size is 1 GB. Setting it to a negative value will disable automatic transaction
        log truncation.
    batch_update_interval: The interval in milliseconds between requesting updates from the primary cluster. Used only when the cluster is in
        secondary mode.

Returns:
    The updated cluster configuration.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If one or more nodes in the group are not reachable.
r   r   r   r   r   r   r   Nr   r   r   r   r   r   r   r   r   r   r   r   z/Failed to parse updated cluster configuration: r   r   rW   rX   rY   rZ   r   r   )r   r   re   r=   patchrc   r   rg   rd   r   r^   r   rh   ri   rj   rk   r   rl   r   r	   r   )r;   r   r   r   r   r   r   r   r   r   r   ro   r   rj   rp   rr   s                   r>   update_config$ClusterGroupManagement.update_configk  sR   P $%9:%'=>!#560#%9:.0OP$&;<5
 "-J T%[%;:,.J KLL "- %'+,@()!-.D*+)+='(&'6O$+-A)**65T12 ,-B)*/0	''--& . H %%'%//@@i4 )EcUK $$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s7    *C; +#C C8$C33C88C; ;GB;G

Gc                p   [        U[        5      (       d  [        S5      eU(       d  [        S5      e U R                  R                  SSU0S9nUR                  5         g! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        S	UR                  R                   35      UeUS
:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  Add primary cluster tag.

Parameters:
    tag: The identifier tag to add to the primary cluster.

Raises:
    TypeError: If tag is not a string.
    ValueError: If tag is an empty string.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the cluster is not in a state to add a tag.
tag must be a stringtag must be a non-empty string/rest/cluster/config/tagtagrd   r   r   rW   rX   rY   rZ   r   r   Nr_   ra   re   r^   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   )r;   r   rj   rp   rr   s        r>   add_tagClusterGroupManagement.add_tag  s=    #s##233=>>	'',,*% - H %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   ,A! !D55B;D00D5c                |   [        U[        5      (       d  [        S5      eU(       d  [        S5      eSS0n U R                  R                  SSUSU0S9nUR                  5         g! [        R                   a  nUR                  R                  nUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  Remove primary cluster tag.

Parameters:
    tag: The identifier tag to remove from the primary cluster.

Raises:
    TypeError: If tag is not a string.
    ValueError: If tag is an empty string.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the cluster is not in a state to delete a tag.
r   r   r   r   r   r   r   r   r   r   rW   rX   rY   rZ   r   r   N)r_   ra   re   r^   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   )r;   r   r   rj   rp   rr   s         r>   
delete_tag!ClusterGroupManagement.delete_tag  sO    #s##233=>>!#56	''//.S\	 0 H %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   .A' 'D;;B;D66D;c                   [        U[        5      (       d  [        S5      eU(       d  [        S5      e[        U[        5      (       d  [        S5      eU(       d  [        S5      eXS.n U R                  R                  SUS9nUR                  5         g! [        R                   a  nUR                  R                  nUS:X  a#  [        S	UR                  R                   35      UeUS
:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  Enable cluster secondary mode.

You can switch any healthy primary cluster to secondary mode by providing the RPC address
of the primary cluster node that it will replicate and then declaring the tag used to identify
it. Once you have switched a cluster to secondary mode, all of its current repositories and
data will be removed and replaced with the data and state of the primary cluster.

!!! Note
    You can enable the secondary cluster mode from any of the nodes of a cluster, not just the
    leader node. You can also use any of the healthy nodes of the primary cluster to connect to
    that cluster.

!!! Warning
    Enabling the secondary mode will delete all data on the secondary cluster and replicate
    the state of the primary cluster.

Parameters:
    primary_node: The RPC address of one of the healthy nodes of the primary cluster.
    tag: The identifier tag of the primary cluster.

Raises:
    TypeError: If primary_node or tag is not a string.
    ValueError: If primary_node or tag is an empty string.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the cluster is not in a state to enable secondary mode.
zprimary_node must be a stringz'primary_node must be a non-empty stringr   r   )primaryNoder   #/rest/cluster/config/secondary-moder   r   r   rW   rX   rY   rZ   r   r   Nr   )r;   primary_noder   ro   rj   rp   rr   s          r>   enable_secondary_mode,ClusterGroupManagement.enable_secondary_mode%  si   : ,,,;<<FGG#s##233=>>".;	'',,5G - H %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   **B E))B;E$$E)c                
    U R                   R                  S5      nUR                  5         g
! [        R                   a  nUR
                  R                  nUS:X  a#  [        SUR
                  R                   35      UeUS:X  a#  [        SUR
                  R                   35      UeUS:X  a#  [        SUR
                  R                   35      UeUS:X  a#  [        S	UR
                  R                   35      Uee S
nAff = f)a  Disable cluster secondary mode.

Once in secondary mode, you can disable secondary mode and then you will no longer be in
that mode. Doing this will stop the pulling of updates from the primary cluster.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the cluster is not in a state to disable secondary mode.
r  r   r   rW   rX   rY   rZ   r   r   N)r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   r   s       r>   disable_secondary_mode-ClusterGroupManagement.disable_secondary_modec  s   	''../TUH%%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   +. DB;C==Dc                   [        U[        5      (       a  [        S U 5       5      (       a  [        S5      eSU0nSS0n U R                  R                  SX2S9nUR                  5         g! [        R                   a  nUR                  R                  nUS:X  a#  [        S	UR                  R                   35      UeUS
:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  Add nodes to the GraphDB cluster.

Parameters:
    nodes: List of node addresses to add to the cluster.

Raises:
    TypeError: If nodes is not a list of strings.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If one or more nodes in the group are not reachable.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   r   r   s     r>   rz   3ClusterGroupManagement.add_nodes.<locals>.<genexpr>         .
27$
4%%%%r}   r   r   r   r   /rest/cluster/config/noder   r   r   rW   rX   rY   rZ   r   r   N)r_   rf   r   re   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   )r;   r   ro   r   rj   rp   rr   s          r>   	add_nodes ClusterGroupManagement.add_nodes  sZ    %&&# .
27.
 +
 +
 899E"!#56	'',,+W - H %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   *A, ,E  B;D;;E c                   [        U[        5      (       a  [        S U 5       5      (       a  [        S5      eSU0n U R                  R                  SSUS9nUR                  5         g! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  Remove nodes from the GraphDB cluster.

Parameters:
    nodes: List of node addresses to remove from the cluster.

Raises:
    TypeError: If nodes is not a list of strings.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If one or more nodes in the group are not reachable.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   r   r   s     r>   rz   6ClusterGroupManagement.remove_nodes.<locals>.<genexpr>  r  r}   r   r   r   r  )r   r   rd   r   r   rW   rX   rY   rZ   r   r   N)r_   rf   r   re   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   )r;   r   ro   rj   rp   rr   s         r>   remove_nodes#ClusterGroupManagement.remove_nodes  sS    %&&# .
27.
 +
 +
 899E"	''/// 0 H
 %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   +A) )D==B;D88D=c                   [        U[        5      (       a  [        S U 5       5      (       a  [        S5      e[        U[        5      (       a  [        S U 5       5      (       a  [        S5      eX!S.n U R                  R                  SUS9nUR                  5         g! [        R                   a  nUR                  R                  nUS:X  a#  [        S	UR                  R                   35      UeUS
:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  Replace nodes in the GraphDB cluster.

Parameters:
    add_nodes: List of node addresses to add to the cluster.
    remove_nodes: List of node addresses to remove from the cluster.

Raises:
    TypeError: If add_nodes or remove_nodes is not a list of strings.
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If one or more nodes in the group are not reachable.
c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   r   r   s     r>   rz   7ClusterGroupManagement.replace_nodes.<locals>.<genexpr>  s       2
2;$
4%%%)r}   zadd_nodes must be a list[str].c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7fr8   r   r   s     r>   rz   r    s       5
2>$
4%%%,r}   z!remove_nodes must be a list[str].)removeNodesaddNodesr  r   r   r   rW   rX   rY   rZ   r   r   N)r_   rf   r   re   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   )r;   r  r  ro   rj   rp   rr   s          r>   replace_nodes$ClusterGroupManagement.replace_nodes  s|    )T**c 2
2;2
 /
 /
 <==,-- 5
2>5
 2
 2
 ?@@".F	''--.IPW-XH%%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3-+CLL,=,=+>? !	s   4*B E33B;E..E3c                ^    SS0nU R                   R                  SUS9nUR                  5          [        R                  " UR                  5       5      $ ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [!        S
UR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      Uee SnAff = f)aO  Get the status of this GraphDB cluster node.

Returns:
    NodeStatus: The status of this GraphDB cluster node.

Raises:
    ResponseFormatError: If the response cannot be parsed.
    BadRequestError: If the request is invalid.
    NotFoundError: If the node status is not found.
    InternalServerError: If the internal server error.
r   r   z/rest/cluster/node/statusr   zFailed to parse node status: Nr   r   r   zNode status not found: r[   r\   )r=   rb   rc   r   rg   rd   r   re   r^   r   rh   ri   rj   rk   r   rl   r   r
   r   s        r>   node_status"ClusterGroupManagement.node_status  s:   	!34G''+++W , H %%'!++HMMO<<i4 )3C59 $$ 	\\--F}%(9#,,:K:K9L&MNTWW3#-cll.?.?-@A 3)-cll.?.?-@A 	r   c                    SS0nU R                   R                  SUS9nUR                  5          UR                  5       nU Vs/ s H  n[        R
                  " U5      PM     sn$ s  snf ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [!        S
UR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      Uee SnAff = f)aD  Get the status of the GraphDB cluster.

Returns:
    A list of node statuses for the cluster group.

Raises:
    ResponseFormatError: If the response cannot be parsed.
    BadRequestError: If the request is invalid.
    NotFoundError: If the group status is not found.
    InternalServerError: If the internal server error.
r   r   z/rest/cluster/group/statusr   zFailed to parse group status: Nr   r   r   zGroup status not found: r[   r\   )r=   rb   rc   rd   r   rg   r   re   r^   r   rh   ri   rj   rk   r   rl   r   r
   )r;   r   rj   dataitemrp   rr   s          r>   group_status#ClusterGroupManagement.group_status.  sQ   	!34G''++,g , H %%'}}?CDtt
,,T2tDDDi4 )4SE: $$ 	\\--F}%(9#,,:K:K9L&MNTWW3#.s||/@/@.AB 3)-cll.?.?-@A 	sG   .B A-  A(%A- (A- -BBBB E-BD??ErC   r=   r   )r   None)r   r   )NNNNNNN)r   	list[str]r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r)  r8   )r   bool | Noner   zdict[str, str])r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   ra   r   r)  )r  ra   r   ra   r   r)  )r   r*  r   r)  )r  r*  r  r*  r   r)  )r   r   )r   zlist[NodeStatus])r   r   r   r   r   r?   r   r=   r   r   r   r   r   r   r  r  r
  r  r  r  r!  r&  r   r   rA   r>   r   r   z  sX   <( ! !:$R ,0-1)-&*+/6:,0^^ )^ !+	^
 '^ $^ )^ *4^  *^ 
^@BL ,0-1)-&*+/6:,0`(` !+` '	`
 $` )` *4`  *` 
`D(T,\<|B)V*X+Z$L%rA   r   c                  p   ^  \ rS rSrSrS
U 4S jjr\SS j5       rSSS jjrSS jr	SS jr
SS jrS	rU =r$ )
RepositoryiV  a8  GraphDB Repository client.

Overrides specific methods of the RDF4J Repository class and also provides GraphDB-only functionality
(such as FGAC ACL management) made available through the GraphDB REST API.

Parameters:
    identifier: The identifier of the repository.
    http_client: The httpx.Client instance.
c                n   > [         TU ]  X5        [        U R                  U R                  5      U l        g r8   )superr?   r5   r<   r=   _access_control_list_management)r;   r<   r=   	__class__s      r>   r?   Repository.__init__a  s,    1/JOOT--0
,rA   c                    U R                   $ r8   r0  rD   s    r>   rq   Repository.aclg  s    333rA   c           	         S[        U5      0nU R                  R                  SU R                   S3U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)a  Repository health check.

Parameters:
    timeout: A timeout parameter in seconds. If provided, the endpoint attempts
        to retrieve the repository within this timeout. If not, the passive
        check is performed.

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.
passivez/repositories/z/healthrT   Tr   Repository  not found.z is not healthy. z - N)ra   r=   rb   r<   rc   rh   ri   rj   rk   r   r9   r   rl   )r;   timeoutrU   rj   rp   s        r>   healthRepository.healthk  s    	W.F''++  19& , H %%'$$ 	||''3.-!$"2"2!3;?  ,d..//@AYAY@ZZ]^a^j^j^o^o]pq 	s   AA CA9CCc                <    SS0nU R                   R                  SU R                   S3US9nUR                  5          / nUR	                  5        HL  nSU;   a)  [        US   [        5      (       a  [        S0 US   D6US'   UR                  [        S0 UD65        MN     U$ ! [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                   S	:X  a#  [#        S
UR                  R$                   35      UeUR                  R                   S:X  a#  ['        SUR                  R$                   35      UeUR                  R                   S:X  a#  [)        SUR                  R$                   35      Uee SnAff = f)aJ  Get server files available for import.

Returns:
    A list of files available for import.

Raises:
    ResponseFormatError: If the response format is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
r   r   rR   /import/serverr   parserSettingsFailed to parse response: NrW   rX   rY   rZ   r[   r\   r   )r=   rb   r<   rc   rd   r_   r   r   appendr   r^   re   r   rh   ri   rj   rk   r   rl   r	   r
   )r;   r   rj   resultr%  rp   s         r>   get_server_import_files"Repository.get_server_import_files  s   "	!34G''++%doo%6nE , H %%'W$MMOD'4/J-.5 5 2@ 2"#342-. MM."84"89 , 	* W),Fse*LMSVVW$$ 	||''3.'/0A0A/BC ))S0$,S\\->->,?@ ))S0)-cll.?.?-@A 	s6   <C
 A#B# #C3CCC
 
FB8FFc                J    SS0nU R                   R                  SU R                   S3UUR                  5       S9nUR	                  5         g! [
        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        S	UR                  R                   35      UeUS
:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)a4  Import a server file into the repository.

Parameters:
    server_import_body: The server import body.

Raises:
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    NotFoundError: If the request is not found.
r   r   rR   r>  r   r   Bad request: rW   rX   rY   rZ   r   zRequest is not found: N)r=   r   r<   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   )r;   server_import_bodyr   rj   rp   rr   s         r>   import_server_import_file$Repository.import_server_import_file  s4   	%'9:G'',,%doo%6nE'//1 - H
 %%'$$ 	\\--F}%cll6G6G5H&IJPSS3'/0A0A/BC 3$,S\\->->,?@ 3#,S\\->->,?@ !	s   AA D""B;DD"c                    SU0nU R                   R                  SU R                   S3US9nUR                  5         g! [        R
                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [        S
UR                  R                   35      Uee SnAff = f)a  Cancel server file import operation.

Parameters:
    name: The name of the file import to interrupt.

Raises:
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
namerR   r>  rT   r   rF  rW   rX   rY   rZ   N)r=   r   r<   rc   rh   ri   rj   rk   r   rl   r   r	   )r;   rK  rU   rj   rp   rr   s         r>   cancel_server_import_file$Repository.cancel_server_import_file  s    	d^F''..%doo%6nE / H %%'$$ 	\\--F}%cll6G6G5H&IJPSS3'/0A0A/BC 3$,S\\->->,?@ 	s   <? C*BC%%C*r4  r   )r   r5   )   )r:  r   r   bool)r   zlist[ImportSettings])rG  r"   r   r)  )rK  ra   r   r)  )r   r   r   r   r   r?   r   rq   r;  rC  rH  rL  r   __classcell__r1  s   @r>   r-  r-  V  s<    
 4 4>.`$L rA   r-  c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )RepositoryManageri  zGraphDB Repository Manager.

This manager client overrides specific RDF4J RepositoryManager class methods to provide GraphDB-specific implementations.
c                b   > [         TU ]  U5      n[        UR                  UR                  5      $ )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/  rb   r-  r<   r=   )r;   repository_id_repor1  s      r>   rb   RepositoryManager.get  s,      M*%**E,=,=>>rA   r   )rU  ra   r   r-  )r   r   r   r   r   rb   r   rP  rQ  s   @r>   rS  rS    s    
? ?rA   rS  c                  x    \ rS rSrSrSS jr\S 5       r\SS j5       rSS jr	\SS j5       r
SS jrSS	 jrS
rg)MonitoringManagementi  z&
Monitor different GraphDB processes.
c                    Xl         g r8   rC   r   s     r>   r?   MonitoringManagement.__init__   r   rA   c                    U R                   $ r8   rC   rD   s    r>   r=    MonitoringManagement.http_client#  rF   rA   c                    SS0nU R                   R                  SUS9nUR                  5          [        S0 UR	                  5       D6$ ! [
        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [!        SUR                  R                   35      Uee SnAff = f)an  Get structures statistics.

Returns:
    The structures statistics.

Raises:
    ResponseFormatError: If the response format is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ServiceUnavailableError: If the server is unavailable.
r   r   z/rest/monitor/structuresr   r@  NrW   rX   rY   rZ   r[   r\     Service is unavailable: r   )r=   rb   rc   r$   rd   r^   re   r   rh   ri   rj   rk   r   rl   r	   r
   r   r   s        r>   
structuresMonitoringManagement.structures'  sa   	!34G''++,FPW+XH%%'W+>hmmo>>	* W),Fse*LMSVVW$$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A 3-.s||/@/@.AB %	s5   .A1 A
 
A.A))A..A1 1EB;E  Ec                d    SS0nU R                   R                  SU 3US9nUR                  5          [        R                  " UR                  5       5      $ ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [!        S
UR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      Uee SnAff = f)a  Get repository statistics.

Parameters:
    repository_id: The identifier of the repository.

Returns:
    RepositoryStatistics: The repository statistics.

Raises:
    ResponseFormatError: If the response cannot be parsed.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
r   r   z/rest/monitor/repository/r   r@  NrW   rX   rY   rZ   r[   r\   )r=   rb   rc   r!   rg   rd   r^   re   r   r   rh   ri   rj   rk   r   rl   r	   r
   )r;   rU  r   rj   rp   rr   s         r>   get_repo_stats#MonitoringManagement.get_repo_statsQ  sD   	!34G''+++M?;W , H %%'W+55hmmoFF	84 W),Fse*LMSVVW$$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A 	s5   1B #A B-A<<BB D/BD**D/c                ^    SS0nU R                   R                  SUS9nUR                  5          [        R                  " UR                  5       5      $ ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [!        S
UR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      Uee SnAff = f)aX  Get all infrastructure statistics.

Returns:
    InfrastructureStatistics: The infrastructure statistics.

Raises:
    ResponseFormatError: If the response cannot be parsed.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
r   r   z/rest/monitor/infrastructurer   r@  NrW   rX   rY   rZ   r[   r\   )r=   rb   rc   r   rg   rd   r^   re   r   r   rh   ri   rj   rk   r   rl   r	   r
   r   s        r>   infrastructure#MonitoringManagement.infrastructurez  s=   	!34G''++. , H %%'W/99(--/JJ	84 W),Fse*LMSVVW$$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A 	r   c                &    SS0nU R                   R                  SUS9nUR                  5         UR                  $ ! [        R
                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      Uee SnAff = f)ak  Get cluster statistics.

!!! Note
    This endpoint is only available in GraphDB EE.

Returns:
    Prometheus-style metrics.

Raises:
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ServiceUnavailableError: If the server is unavailable.
r   z
text/plainz/rest/monitor/clusterr   rW   rX   rY   rZ   r[   r\   r_  r`  N)r=   rb   rc   rl   rh   ri   rj   rk   r   r	   r
   r   r   s        r>   clusterMonitoringManagement.cluster  s#   	.G''++,CW+UH%%'== $$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A 3-.s||/@/@.AB %	s   9< DB;DDc                    SS0nU R                   R                  SUS9nUR                  5          UR                  5       nU(       d  g[        R
                  " U5      $ ! [        [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [!        S
UR                  R                   35      UeUS:X  a#  [#        SUR                  R                   35      UeUS:X  a#  [%        SUR                  R                   35      Uee SnAff = f)a  Track backup operations.

Returns:
    On-going backup operations or `None` if no backup is in progress.

Raises:
    ResponseFormatError: If the response cannot be parsed.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
    ServiceUnavailableError: If the server is unavailable.
r   r   z/rest/monitor/backupr   Nr@  rW   rX   rY   rZ   r[   r\   r_  r`  )r=   rb   rc   rd   r   rg   r^   re   r   r   rh   ri   rj   rk   r   rl   r	   r
   r   )r;   r   rj   r$  rp   rr   s         r>   backupMonitoringManagement.backup  sp   	!34G''++,BG+TH%%'W}}*44T::	84 W),Fse*LMSVVW$$ 	\\--F}'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A 3-.s||/@/@.AB %	s;   .B A 	A B4BBB EB;EErC   Nr(  )r   r$   )rU  ra   )r   r   )r   ra   )r   zBackupOperationBean | None)r   r   r   r   r   r?   r   r=   ra  rd  rg  rj  rm  r   r   rA   r>   rY  rY    s[    ( ! ! ' 'R'R $ $L&P*rA   rY  c                  V   \ rS rSrSrSS jr\S 5       r   S         SS jjr    S           SS jjr	\
R                    SSS.       SS	 jjj5       r\
R                    S       SS
 jj5       r  SSS.       SS jjjr   S         SS jjrSrg)RecoveryManagementi  z%
GraphDB Recovery Management client.
c                    Xl         g r8   rC   r   s     r>   r?   RecoveryManagement.__init__  r   rA   c                    U R                   $ r8   rC   rD   s    r>   r=   RecoveryManagement.http_client  rF   rA   Nc                6  ^ ^ UbB  [        U[        5      (       d  [        S5      e[        S U 5       5      (       d  [        S5      e[        U[        5      (       d  Ub  [        S5      e[        U[        5      (       d  Ub  [        S5      e0 nUb  X%S'   Ub  X5S'   Ub  XES	'   S[
        R                  " U5      S
4mSUU 4S jjn[        U[        [        [        45      (       a  [        U5      nU" SUS45        g[        US5      (       ah  [        U[        [        R                  45      (       dC  [        R                  " [        R                   [           U5      n[#        US5      n	U" XS45        g[        U[        [        R                  45      (       ac  [$        R&                  " U5      R)                  5       n
[+        U
S5       nU
R,                  =(       d    [#        US5      n	U" XS45        SSS5        g[        S5      e! , (       d  f       g= f)a  Restore GraphDB instance from a backup archive.

Parameters:
    backup: Backup archive content as bytes/bytes-like, a binary file-like
        object, or a filesystem path to a `.tar` produced by
        [`backup`][rdflib.contrib.graphdb.client.RecoveryManagement.backup].
    repositories: List of repositories to restore. If `None` (default), the
        parameter is omitted and all repositories found in the backup are
        restored. If an empty list (`[]`) is provided, no repositories from
        the backup are restored.
    restore_system_data: Whether to restore system data (users, saved queries,
        visual graphs, etc.). If omitted, GraphDB defaults to `false`. If
        `true` and no system data exists in the backup, GraphDB returns an
        error.
    remove_stale_repositories: Whether to remove repositories on the target
        instance that are not restored from the backup. If omitted, GraphDB
        defaults to `false`.

Raises:
    ValueError: If parameters are invalid, or if backup is not a supported type.
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
N#repositories must be a list or Nonec              3  B   #    U  H  n[        U[        5      v   M     g 7fr8   r   rx   rs     r>   rz   -RecoveryManagement.restore.<locals>.<genexpr>$       @<az!S))<   &repositories must be a list of strings*restore_system_data must be a bool or None0remove_stale_repositories must be a bool or NonerepositoriesrestoreSystemDataremoveStaleRepositoriesr   c                  >  TR                   R                  SST4SU 4/S9nUR                  5         g ! [        R                   a  nUR
                  R                  nUS:X  a#  [        SUR
                  R                   35      UeUS:X  a#  [        SUR
                  R                   35      UeUS	:X  a#  [        S
UR
                  R                   35      UeUeS nAff = f)Nz/rest/recovery/restorerU   file)filesr   rF  rW   rX   rY   rZ   r   )	file_partrj   rp   rr   params_partr;   s       r>   _post)RecoveryManagement.restore.<locals>._post;  s    ++00,$k2VY4GH 1  ))+(( 11S=)M#,,:K:K9L*MNTWWs]+3CLL4E4E3FG s](01B1B0CD 	s   04 C BCC graphdb-backup.tarzapplication/x-tarreadrbzPbackup must be bytes/bytes-like, a binary file-like object, or a filesystem path)r  FileContentr   r)  )r_   rf   r^   r   rO  rd   dumpsbytes	bytearray
memoryviewhasattrra   osPathLiker   r   IOr.   pathlibPath
expanduseropenrK  )r;   rm  r  restore_system_dataremove_stale_repositoriesro   r  contentfile_objfilenamebackup_pathfr  s   `           @r>   restoreRecoveryManagement.restore  s   > #lD11 !FGG@<@@@ !IJJ.55#/IJJ4d;;)5OPP$&#&2N#*+>'($01J-.$($**W*=?Q#R	 	* fui<==FmG'2EFG66"":fsBKK>P+Q+Qvvadd5k62H28=QRH8':;<fsBKK011!,,v.99;Kk4(A&++ /J+0 x$789	 )
 ^
 	
 )(
 s   *H


Hc                  ^ ^ [        U[        5      (       a  U(       d  [        S5      eUbB  [        U[        5      (       d  [        S5      e[	        S U 5       5      (       d  [        S5      e[        U[
        5      (       d  Ub  [        S5      e[        U[
        5      (       d  Ub  [        S5      e0 nUb  X&S'   Ub  X6S	'   Ub  XFS
'   XS'   S[        R                  " U5      S4mSUU 4S jjnUc	  U" S5        g[        U[        [        [        45      (       a  [        U5      nU" SUS45        g[        US5      (       ah  [        U[        [        R                  45      (       dC  [        R                  " [        R                   [           U5      n	[#        U	S5      n
U" XS45        g[        U[        [        R                  45      (       ac  [$        R&                  " U5      R)                  5       n[+        US5       nUR,                  =(       d    [#        US5      n
U" XS45        SSS5        g[        S5      e! , (       d  f       g= f)a  Restore GraphDB instance from a cloud backup archive.

Parameters:
    bucket_uri: Cloud bucket URI including provider-specific parameters (required).
    repositories: List of repositories to restore. If `None` (default), the
        parameter is omitted and all repositories found in the backup are
        restored. If an empty list (`[]`) is provided, no repositories from
        the backup are restored.
    restore_system_data: Whether to restore system data (users, saved queries,
        visual graphs, etc.). If omitted, GraphDB defaults to `false`. If
        `true` and no system data exists in the backup, GraphDB returns an
        error.
    remove_stale_repositories: Whether to remove repositories on the target
        instance that are not restored from the backup. If omitted, GraphDB
        defaults to `false`.
    authentication_file: Optional credential file content as bytes/bytes-like, a
        binary file-like object, or a filesystem path.

Raises:
    ValueError: If parameters are invalid, or authentication_file is not a supported type.
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
%bucket_uri must be a non-empty stringNrv  c              3  B   #    U  H  n[        U[        5      v   M     g 7fr8   r   rx  s     r>   rz   3RecoveryManagement.cloud_restore.<locals>.<genexpr>  r{  r|  r}  r~  r  r  r  r  	bucketUrir   c                  > ST4/nU b  UR                  SU 45         TR                  R                  SSS0US9nUR                  5         g ! [        R
                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUeS nAff = f)NrU   authenticationFilez/rest/recovery/cloud-restorer   r   r   r  r   rF  rW   rX   rY   rZ   rA  r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   authentication_partr  rj   rp   rr   r  r;   s        r>   r  /RecoveryManagement.cloud_restore.<locals>._post  s   5={4K3LE".24GHI++002%'9: 1 
 ))+(( 11S=)M#,,:K:K9L*MNTWWs]+3CLL4E4E3FG s](01B1B0CD 	   -A C8 BC33C8authentication-fileapplication/octet-streamr  r  ]authentication_file must be bytes/bytes-like, a binary file-like object, or a filesystem pathr  zFileContent | Noner   r)  r_   ra   r^   rf   r   rO  rd   r  r  r  r  r  r  r  r   r   r  r.   r  r  r  r  rK  )r;   
bucket_urir  r  r  authentication_filero   r  r  r  r  	auth_pathr  r  s   `            @r>   cloud_restore RecoveryManagement.cloud_restoreh  s,   D *c***DEE#lD11 !FGG@<@@@ !IJJ.55#/IJJ4d;;)5OPP$&#&2N#*+>'($01J-.)$($**W*=?Q#R	 	2 &$K)E9j+IJJ/0G('3MNO&//
#r{{!39
 9
 vvadd5k+>?H28=RSH8'ABC)C+=>>%89DDFIi&!$>> -H,. x$>?@	 '
 k
 	
 '&
 s   *I
I)destc                   g r8   r   r;   r  backup_system_datar  s       r>   rm  RecoveryManagement.backup  s     rA   c                   g r8   r   r  s       r>   rm  r    s     rA   c                  UbB  [        U[        5      (       d  [        S5      e[        S U 5       5      (       d  [        S5      e[        U[        5      (       d  Ub  [        S5      e0 nUb  XS'   Ub  X$S'   SS jnUc7   U R
                  R                  S	US
9nUR                  5         UR                  $ [        R                  " U5      R                  5       R                  5       n U R
                  R                  SS	US
9 nUR                  5         UR!                  5       (       a8  UR"                  R%                  SS5      n	['        U	5      n
U
(       a  X-  nOUS-  nUR)                  UR*                  S-   5      n[-        US5       nUR/                  5        H  nUR1                  U5        M     SSS5        UR3                  U5        SSS5        U$ ! [        R                   a  nU" U5         SnAgSnAff = f! , (       d  f       NR= f! , (       d  f       U$ = f! [        R                   a  nU" U5         SnAgSnAff = f)a  Create a new backup of GraphDB instance.

The backup is returned as a tar archive containing repository data and
optionally system data (user accounts, saved queries, visual graphs, etc.).

Parameters:
    repositories: List of repositories to be backed up, specified by their repository identifiers.
        If `None`, all repositories will be included in the backup.
    backup_system_data: Determines whether user account data such as user accounts, saved queries,
        or visual graphs, among others, should be included in the backup.
    dest: Destination path to save the backup archive. If `None`, the backup
        content is returned as bytes (suitable for small backups). If a directory
        path is provided, the filename from the response Content-Disposition header
        is used (e.g., backup-2026-01-16-10-30-00.tar). If a file path is provided,
        that exact path is used. The response is streamed directly to disk
        (recommended for large backups).

Returns:
    bytes: If `dest` is `None`, returns the backup archive as bytes.
    Path: If `dest` is provided, returns the resolved `pathlib.Path` where the backup was saved.

Raises:
    ValueError: If repositories is not a list or None, or if backup_system_data is not a bool or None.
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    OSError: If the destination path cannot be written to.
Nrv  c              3  B   #    U  H  n[        U[        5      v   M     g 7fr8   r   rx  s     r>   rz   ,RecoveryManagement.backup.<locals>.<genexpr>  r{  r|  r}  !backup_system_data must be a boolr  backupSystemDatac                (   U R                   R                  nUS:X  a#  [        SU R                   R                   35      U eUS:X  a#  [	        SU R                   R                   35      U eUS:X  a#  [        SU R                   R                   35      U eU e)Nr   rF  rW   rX   rY   rZ   )rj   rk   r   rl   r   r	   )rp   rr   s     r>   _handle_http_error5RecoveryManagement.backup.<locals>._handle_http_error"  s    \\--F}%cll6G6G5H&IJPSS3'/0A0A/BC 3$,S\\->->,?@ IrA   z/rest/recovery/backupr   POSTzContent-Disposition r  z.partialwb)rp   zhttpx.HTTPStatusErrorr   z
t.NoReturn)r_   rf   r^   r   rO  r=   r   rc   r  rh   ri   r  r  r  resolvestreamis_dirr   rb   r-   with_suffixsuffixr  
iter_byteswritereplace)r;   r  r  r  ro   r  rj   rp   	dest_pathcontent_dispositionr  tmp_pathr  chunks                 r>   rm  r    s?   F #lD11 !FGG@<@@@ !IJJ,d338J8V@AA$&#&2N#)*<&'	 <(++001Hw0W))+'''
  T*557??AI(%%,,3' - --/ !'')).6.>.>.B.B12/+ $M/$ $(1(<I )24H(HI  )44Y5E5E
5RSHh-%-%8%8%:EGGEN &; . $$Y/34 ! C (( ("3''(: .-- 4 ! (( ("3''(sg   5G +H& BH)H7H	H& H .G;;H 
H	H
H#H& #H& &I:IIc                P  ^ ^ [        U[        5      (       a  U(       d  [        S5      eUbB  [        U[        5      (       d  [        S5      e[	        S U 5       5      (       d  [        S5      e[        U[
        5      (       d  Ub  [        S5      e0 nUb  X%S'   Ub  X5S'   XS	'   S[        R                  " U5      S
4mSUU 4S jjnUc	  U" S5        g[        U[        [        [        45      (       a  [        U5      nU" SUS45        g[        US5      (       ah  [        U[        [        R                  45      (       dC  [        R                  " [        R                   [           U5      n[#        US5      n	U" XS45        g[        U[        [        R                  45      (       ac  [$        R&                  " U5      R)                  5       n
[+        U
S5       nU
R,                  =(       d    [#        US5      n	U" XS45        SSS5        g[        S5      e! , (       d  f       g= f)aV  Create a new backup of GraphDB instance uploaded to a cloud bucket.

GraphDB uploads the resulting `.tar` archive directly to the configured
cloud bucket. This uses the GraphDB endpoint `/rest/recovery/cloud-backup`.

Parameters:
    bucket_uri: Cloud bucket URI including provider-specific parameters (required).
    repositories: Optional list of repositories to be backed up.
    backup_system_data: Optional flag to include system data (users, saved queries, etc.).
    authentication_file: Optional credential file content as bytes/bytes-like, a
        binary file-like object, or a filesystem path.

Raises:
    ValueError: If parameters are invalid, or authentication_file is not a supported type.
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
r  Nrv  c              3  B   #    U  H  n[        U[        5      v   M     g 7fr8   r   rx  s     r>   rz   2RecoveryManagement.cloud_backup.<locals>.<genexpr>|  r{  r|  r}  r  r  r  r  r   c                  > ST4/nU b  UR                  SU 45         TR                  R                  SSS0US9nUR                  5         g ! [        R
                   a  nUR                  R                  nUS:X  a#  [        SUR                  R                   35      UeUS	:X  a#  [        S
UR                  R                   35      UeUS:X  a#  [        SUR                  R                   35      UeUeS nAff = f)NrU   r  z/rest/recovery/cloud-backupr   r   r  r   rF  rW   rX   rY   rZ   r  r  s        r>   r  .RecoveryManagement.cloud_backup.<locals>._post  s   5={4K3LE".24GHI++001%'9: 1 
 ))+(( 11S=)M#,,:K:K9L*MNTWWs]+3CLL4E4E3FG s](01B1B0CD 	r  r  r  r  r  r  r  r  )r;   r  r  r  r  ro   r  r  r  r  r  r  r  s   `           @r>   cloud_backupRecoveryManagement.cloud_backup[  s   6 *c***DEE#lD11 !FGG@<@@@ !IJJ,d338J8V@AA$&#&2N#)*<&')$($**W*=?Q#R	 	2 &$K)E9j+IJJ/0G('3MNO&//
#r{{!39
 9
 vvadd5k+>?H28=RSH8'ABC)C+=>>%89DDFIi&!$>> -H,. x$>?@	 '
 k
 	
 '&
 s   *H
H%rC   r(  )NNN)
rm  zEbytes | bytearray | memoryview | t.IO[bytes] | str | os.PathLike[str]r  list[str] | Noner  r+  r  r+  r   r)  )NNNN)r  ra   r  r  r  r+  r  r+  r  Lbytes | bytearray | memoryview | t.IO[bytes] | str | os.PathLike[str] | Noner   r)  NN)r  r  r  r+  r  r)  r   r  )r  r  r  r+  r  zstr | os.PathLike[str]r   zpathlib.Path)r  r  r  r+  r  zstr | os.PathLike[str] | Noner   zbytes | pathlib.Path)
r  ra   r  r  r  r+  r  r  r   r)  )r   r   r   r   r   r?   r   r=   r  r  r   overloadrm  r  r   r   rA   r>   rp  rp    s   ( ! ! *.+/15d
Ud
 'd
 )	d

 $/d
 
d
R *.+/15 u
u
 'u
 )	u

 $/u
 Yu
 
u
n ZZ *.*.
 & (
  
  ZZ *.*.& (
 % 
  *.*.h(
 /3h(&h( (h(
 ,h( 
h(Z *.*. e
e
 'e
 (	e
 Ye
 
e
 e
rA   rp  c                     \ rS rSrSrSS jrSSS jjr  S     SS jjr\S 5       r	\
R                   S       SS jj5       r\
R                    S       S S	 jj5       r\
R                   S       S!S
 jj5       r\
R                   S       S"S jj5       r  S       S#S jjrS$S jrSS%S jjr S       S&S jjr S     S'S jjr\
R                  SSS.           S(S jj5       r\
R                  SSSS.           S)S jj5       r\
R                  SS.       S*S jj5       rSSSSS.           S+S jjrSrg),RepositoryManagementi  zGraphDB Repository Management client.

The functionality provided by this management client accepts an optional location parameter to operate on external
GraphDB locations.
c                    Xl         g r8   rC   r   s     r>   r?   RepositoryManagement.__init__  r   rA   Nc                   0 nUb  XS'    U R                   R                  SUS9nUR                  5          UR                  5        Vs/ s H  n[        R
                  " U5      PM     sn$ s  snf ! [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   aC  nUR                  R                  S:X  a#  [        SUR                  R                   35      Uee SnAff = f)a  List all repositories.

Parameters:
    location: The location of the repositories.

Returns:
    list[GraphDBRepository]: List of GraphDB repositories.

Raises:
    InternalServerError: If the server returns an internal error.
    ResponseFormatError: If the response cannot be parsed.
Nlocation/rest/repositoriesrT   rV   r[   r\   )r=   rb   rc   rd   r   rg   r^   re   r   rh   ri   rj   rk   r
   rl   )r;   r  rU   rj   reporp   s         r>   rf   RepositoryManagement.list  s     !):	''++,@+PH%%'FNmmoVod)33D9oVVV	* )8> $$ 	||''3.)-cll.?.?-@A 	sF   *B A0  A+(A0 +A0 0B BBB C.+>C))C.c                   0 nUb  X$S'   SS jn [        U[        5      (       a  / nUbf  [        U[        R                  5      (       a  [	        UR                  5       5      nO[	        U5      n[        S U 5       5      (       a  [        S5      eSSUS44/nU H  u  pUR                  X" X5      45        M     U R                  R                  S	UUS
9n
O:Ub  [        S5      eU R                  R                  S	SS0UR                  5       US9n
U
R                  5         g! [        R                   a  nUR                  R                   nUS:X  a#  [#        SUR                  R$                   35      UeUS:X  a#  ['        SUR                  R$                   35      UeUS:X  a#  [)        SUR                  R$                   35      UeUS:X  a#  [+        SUR                  R$                   35      Uee SnAff = f)a  Create a new repository.

Parameters:
    config: Repository configuration. When a `RepositoryConfigBeanCreate` is
        provided, the request is sent as JSON. When a string is provided, it
        is treated as Turtle content and sent as multipart/form-data part
        `config` (required by GraphDB) with the content type `text/turtle`.
    location: Optional repository location (query param `location`).
    files: Optional extra multipart parts for GraphDB-specific files (e.g.
        `obdaFile`, `owlFile`, `propertiesFile`, `constraintFile`,
        `dbMetadataFile`, `lensesFile`). Keys must be the form part names;
        values may be file content or httpx-style file tuples. Ignored when
        `config` is a dataclass (JSON payload).

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
Nr  c                    [        U[        5      (       a2  [        U5      S:X  a  Uu  p#U=(       d    U U4$ Uu  p#nU=(       d    U X44$ X4$ )N   )r_   tuplelen)fieldr   r  r  content_types        r>   _normalize_file_content<RepositoryManagement.create.<locals>._normalize_file_content  sT    %''u:?(-%H$-w7727/< )E7AA>!rA   c              3  0   #    U  H  u  pUS :H  v   M     g7f)configNr   )rx   r  _s      r>   rz   .RepositoryManagement.create.<locals>.<genexpr>  s     I[5H,[s   zQDo not pass a 'config' multipart part via files; use the config argument instead.r  z
config.ttltext/turtler  )rU   r  zEAdditional files can only be provided when config is a Turtle string.r   r   r   r   r   rW   rX   rY   rZ   r[   r\   )r  ra   r   r  r   r  )r_   ra   r   Mappingrf   r   r   r^   rA  r=   r   r   rc   rh   ri   rj   rk   r   rl   r   r	   r
   )r;   r  r  r  rU   r  extra_partsmultipart_filesr  r  rj   rp   rr   s                r>   createRepositoryManagement.create  s#   4 !):	"7	&#&&=?$!%33&*5;;=&9&*5kI[III(o 
 fmDEB '2NE#** 7 GH '2
  ++00(!) 1  $$_   ++00(+-?@)!	 1  %%'$$ 	\\--F}%(9#,,:K:K9L&MNTWW3'/0A0A/BC 3$,S\\->->,?@ 3)-cll.?.?-@A !	s   DD" "G66B;G11G6c                    U R                   $ r8   rC   rD   s    r>   r=    RepositoryManagement.http_clientN  rF   rA   c                    g r8   r   r;   rU  r  r  s       r>   rb   RepositoryManagement.getR        #rA   c                    g r8   r   r  s       r>   rb   r  Z  r  rA   c                    g r8   r   r  s       r>   rb   r  b  s     rA   c                    g r8   r   r  s       r>   rb   r  j  s     (+rA   c                   Uc  SnUS;  a  [        SU S35      eSU0n0 nUb  X5S'    U R                  R                  SU 3XES	9nUR                  5         US:X  a   [	        S0 UR                  5       D6$ US:X  a#   [        5       R                  UR                  SS9$ [        SU S35      e! [         [        4 a  n[        S
5      UeSnAff = f! [         a  n[        SU 35      UeSnAff = f! [        R                   aV  nUR                  R                  S:X  a  [!        SU S35      UeUR                  R                  S:X  a  [#        S5      Uee SnAff = f)a  Get a repository's configuration.

Parameters:
    repository_id: The identifier of the repository.
    content_type: The content type of the response. Can be `application/json` or
        `text/turtle`. Defaults to `application/json`.
    location: The location of the repository.

Returns:
    RepositoryConfigBean: The repository configuration.
    Graph: The repository configuration in RDF.

Raises:
    BadRequestError: If the content type is not supported.
    ResponseFormatError: If the response cannot be parsed.
    RepositoryNotFoundError: If the repository is not found.
    InternalServerError: If the server returns an internal error.
Nr   )r   r  zUnsupported content type: .r   r  rR   r   !Failed to parse GraphDB response.r  turtle)r$  formatzError parsing RDF: zUnhandled content type: r   r8  r9  r[   Internal server error.r   )r^   r=   rb   rc   r   rd   re   r   r   parserl   	Exceptionrh   ri   rj   rk   r   r
   )r;   rU  r  r  r   rU   rj   rp   s           r>   rb   r  r  s   0 -LBB9,qIJJ\*!):	''++%m_5w , H %%'11/B(--/BB
 .T 7==hmmH=MM !#;L>!KLL #I. -; ! T-0CC5.IJPSST $$ 	||''3.-!-< ))S0)*BCL	s`   3C3 B. 6C3 =!C C3 .C>C

CC3 
C0C++C00C3 3EAEEc                   SS0n U R                   R                  SU 3UUR                  5       S9nUR                  5         g! [        R
                   a  nUR                  R                  S:X  a#  [        SUR                  R                   35      UeUR                  R                  S:X  a#  [        SUR                  R                   35      UeUR                  R                  S	:X  a#  [        S
UR                  R                   35      UeUR                  R                  S:X  a#  [        SUR                  R                   35      Uee SnAff = f)ar  Edit a repository's configuration.

Parameters:
    repository_id: The identifier of the repository.
    config: The repository configuration.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
r   r   rR   r   r   r   rW   rX   rY   rZ   r[   r\   N)r=   r   r   rc   rh   ri   rj   rk   r   rl   r   r	   r
   )r;   rU  r  r   rj   rp   s         r>   editRepositoryManagement.edit  sM    .
	''++%m_5^^% , H
 %%'$$ 	||''3.%(9#,,:K:K9L&MNTWW))S0'/0A0A/BC ))S0$,S\\->->,?@ ))S0)-cll.?.?-@A 	s   <A EC5EEc                   0 nUb  X#S'    U R                   R                  SU 3US9nUR                  5         g! [        R                   a  nUR
                  R                  S:X  a#  [        SUR
                  R                   35      UeUR
                  R                  S:X  a#  [        SUR
                  R                   35      UeUR
                  R                  S	:X  a#  [        S
UR
                  R                   35      UeUR
                  R                  S:X  a#  [        SUR
                  R                   35      Uee SnAff = f)ah  Delete a repository.

Parameters:
    repository_id: The identifier of the repository.
    location: The location of the repository.

Raises:
    BadRequestError: If the request is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
Nr  rR   rT   r   r   rW   rX   rY   rZ   r[   r\   )r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r
   r;   rU  r  rU   rj   rp   s         r>   r   RepositoryManagement.delete  sH    !):	''..%m_5f / H %%'$$ 	||''3.%(9#,,:K:K9L&MNTWW))S0'/0A0A/BC ))S0$,S\\->->,?@ ))S0)-cll.?.?-@A 	s   -9 EC5EEc                   0 nUb  [        U5      R                  5       US'   Ub  X4S'    U R                  R                  SU S3US9nUR	                  5         UR
                  $ ! [        R                   a|  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      UeUR                  R                  S:X  a  [        SU S35      Uee SnAff = f)a  Restart a repository.

Parameters:
    repository_id: The identifier of the repository.
    sync: Whether to sync the repository.
    location: The location of the repository.

Returns:
    str: The response text.

Raises:
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    RepositoryNotFoundError: If the repository is not found.
Nsyncr  rR   z/restartrT   rW   Request is unauthorised.rY   Request is forbidden.r   r8  r9  )ra   r   r=   r   rc   rl   rh   ri   rj   rk   r   r	   r   )r;   rU  r  r  rU   rj   rp   s          r>   restartRepositoryManagement.restart  s    $  Y__.F6N!):	'',,%m_H=f - H %%'== $$ 		||''3.'(BCL))S0$%<=3F))S0-!-< 		s   9A$ $C48A7C//C4c                   0 nU(       a  X#S'    U R                   R                  SU S3US9nUR                  5          [        S	0 UR	                  5       D6$ ! [
        [        4 a  n[        S5      UeSnAff = f! [        R                   aC  nUR                  R                  S:X  a#  [        SUR                  R                   35      Uee SnAff = f)
a  Get repository size.

Parameters:
    repository_id: The identifier of the repository.
    location: The location of the repository.

Raises:
    ResponseFormatError: If the response cannot be parsed.
    InternalServerError: If the server returns an internal error.
r  rR   z/sizerT   r	  Nr[   r\   r   )r=   rb   rc   r    rd   r^   re   r   rh   ri   rj   rk   r
   rl   r  s         r>   sizeRepositoryManagement.size%	  s     !):	''++%m_E:6 , H %%'X)<HMMO<<	* X)*MNTWWX$$ 	||''3.)-cll.?.?-@A 	s4   .A; A A8'A33A88A; ;C>CC)r  shapes_repository_idc                   g r8   r   )r;   rU  r  r  r  r  s         r>   validateRepositoryManagement.validateE	       rA   )r  r  r  c                   g r8   r   )r;   rU  r  r  r  r  s         r>   r   r!  P	  r"  rA   )r  c                   g r8   r   )r;   rU  r  r  s       r>   r   r!  [	  s     rA   )r  r  r  r  c                  0 nUb  XFS'   Ub^  Ub  [        S5      eUb  [        S5      eSS0n U R                  R                  SU SU 3UUS	9nUR                  5         UR                  $ Uc  [        S5      e[        US5      =(       a    [        U[        5      (       + nU(       a}  SS0nS[        R                   " [        R"                  [$           U5      U=(       d    S4nSU0n U R                  R                  SU S3UUUS9nUR                  5         UR                  $ U(       d  [        S5      eUSS.n U R                  R                  SU S3UUUS9nUR                  5         UR                  $ ! [
        R                   ai  n	U	R                  R                  n
U
S
:X  a  [        S5      U	eU
S:X  a  [        S5      U	eU
S:X  a#  [        SU	R                  R                   35      U	ee Sn	A	ff = f! [
        R                   ai  n	U	R                  R                  n
U
S
:X  a  [        S5      U	eU
S:X  a  [        S5      U	eU
S:X  a#  [        SU	R                  R                   35      U	ee Sn	A	ff = f! [
        R                   ai  n	U	R                  R                  n
U
S
:X  a  [        S5      U	eU
S:X  a  [        S5      U	eU
S:X  a#  [        SU	R                  R                   35      U	ee Sn	A	ff = f)a  Validate repository data using SHACL shapes.

Parameters:
    repository_id: The identifier of the repository.
    content_type: Content type of the request body (required for text payloads).
    content: SHACL shapes payload; string for text-based validation or file-like
        (binary) object for multipart validation.
    location: Optional repository location.
    shapes_repository_id: ID of repository containing SHACL shapes; when
        provided, no content is sent and shapes are fetched from that
        repository.

Returns:
    str: Validation report as RDF Turtle.

Raises:
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    InternalServerError: If the server returns an internal error.
Nr  z>content must not be provided when shapes_repository_id is set.zCcontent_type must not be provided when shapes_repository_id is set.r   r  rR   z/validate/repository/)r   rU   r   rW   r  rY   r  r[   r\   zcontent must be provided.r  z
shapes.ttlr  z/validate/file)r   rU   r   r  z2content_type must be provided for text validation.r   r   z/validate/text)r   rU   r   r  )r^   r=   r   rc   rl   rh   ri   rj   rk   r   r	   r
   r  r_   ra   r   r   r  r  )r;   rU  r  r  r  r  rU   r   rj   rp   rr   is_file_liker  r  s                 r>   r   r!  d	  sR   : !):+" T  ' Y   /G++00-m_<QRfQgh!# 1 
 ))+}}$ ?899w/P
7C8P4P/GqttE{G,-I
 !'	2E++00-m_NK!#	 1  ))+}}$   !UVV'3}MG++00-m_NK!##	 1  ))+}}$u (( 
11S=+,FGSPs]()@AsJs]-1#,,2C2C1DE 
D (( 
11S=+,FGSPs]()@AsJs]-1#,,2C2C1DE 
2 (( 
11S=+,FGSPs]()@AsJs]-1#,,2C2C1DE 
sJ   <E9 );G9 =;I9 9G6A$G11G69I6A$I11I69K6A$K11K6rC   r(  r8   )r  r   r   zlist[GraphDBRepository]r  )r  z RepositoryConfigBeanCreate | strr  r   r  zFilesType | None)rU  ra   r  zt.Literal['application/json']r  r   r   r   )rU  ra   r  r)  r  r   r   r   )rU  ra   r  zt.Literal['text/turtle']r  r   r   r   )rU  ra   r  ra   r  r   r   RepositoryConfigBean | Graph)rU  ra   r  r   r  r   r   r(  )rU  ra   r  r   r   r)  )rU  ra   r  r   r   r)  )rU  ra   r  r+  r  r   r   ra   )rU  ra   r  r   r   r    )rU  ra   r  ra   r  ra   r  r   r  r)  r   ra   )rU  ra   r  zt.IO[bytes]r  r   r  r   r  r)  r   ra   )rU  ra   r  ra   r  r   r   ra   )rU  ra   r  r   r  zstr | t.IO[bytes] | Noner  r   r  r   r   ra   )r   r   r   r   r   r?   rf   r  r   r=   r   r  rb   r  r   r  r  r   r   r   rA   r>   r  r    sG   (F  $"&	_0_ _  	_B ! ! ZZ
  $	## 4# 	#
 
# # ZZ "#	## # 	#
 
# # ZZ
  $	 / 	
 
  ZZ
  $	++ + 	+
 
&+ + $(#	;; !; 	;
 
&;z&P$N TX& &(3&FP&	&R :> ,6	@ ZZ  $%) 	
   # 
  ZZ $(#%) 	
 !  # 
  ZZ  $ "	
  
  $(,0#+/xx !	x
 *x x )x 
x xrA   r  c                  ~    \ rS rSrSrSS jr\S 5       r\SS j5       r\R                  SS j5       rS r
SS jrS	rg
)SecurityManagementi	  z#GraphDB Security Management client.c                    Xl         g r8   rC   r   s     r>   r?   SecurityManagement.__init__	  r   rA   c                    U R                   $ r8   rC   rD   s    r>   r=   SecurityManagement.http_client	  rF   rA   c                    SS0nU R                   R                  SUS9nUR                  5          UR                  5       n[	        U[
        5      (       d  [        S5      eU$ ! [        [        4 a  n[        SU 35      UeSnAff = f! [        R                   aC  nUR                  R                  S:X  a#  [        S	UR                  R                   35      Uee SnAff = f)
zCheck if security is enabled.

Returns:
    bool: True if security is enabled, False otherwise.

Raises:
    ResponseFormatError: If the response format is invalid.
    InternalServerError: If the server returns an internal error.
r   r   /rest/securityr   zResponse is not a boolean.rV   Nr[   r\   )r=   rb   rc   rd   r_   rO  r   r^   re   rh   ri   rj   rk   r
   rl   )r;   r   rj   r   rp   s        r>   enabledSecurityManagement.enabled	  s    	!34G''++,<g+NH%%' !%..-.JKK	* )8> $$ 	||''3.)-cll.?.?-@A 	s4   .B
 1A# #B3BBB
 
C!>CC!c                   [        U[        5      (       d  [        S5      e SSS.nU R                  R	                  SX!S9nUR                  5         g! [        R                   ax  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S:X  a  [        S	5      UeUR                  R                  S
:X  a  [        S5      Uee SnAff = f)a!  Enable or disable security.

Parameters:
    value: The value to set.

Raises:
    TypeError: If the value is not a boolean.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the precondition is failed.
zValue must be a boolean.r   r&  r0  r   rW   r  rY   r  r   Precondition failed.N)r_   rO  re   r=   r   rc   rh   ri   rj   rk   r   r	   r   )r;   r   r   rj   rp   s        r>   r1  r2  
  s     %&&677	'9EWXG'',, ' - H %%'$$ 	||''3.'(BCL))S0$%<=3F))S0-.DE3N	s   /A C&A3CCc                    SS0nU R                   R                  SUS9nUR                  5          [        S	0 UR	                  5       D6$ ! [
        [        4 a  n[        SU 35      UeSnAff = f! [        R                   aC  nUR                  R                  S:X  a#  [        SUR                  R                   35      Uee SnAff = f)
z
Check if free access is enabled.

Returns:
    FreeAccessSettings: The free access settings.

Raises:
    ResponseFormatError: If the response format is invalid.
    InternalServerError: If the server returns an internal error.
r   r   /rest/security/free-accessr   rV   Nr[   r\   r   )r=   rb   rc   r   rd   r^   re   r   rh   ri   rj   rk   r
   rl   )r;   r   rj   rp   s       r>   get_free_access_details*SecurityManagement.get_free_access_details&
  s    	!34G''++,g , H %%')<HMMO<<	* )8> $$ 	||''3.)-cll.?.?-@A 	s4   .A1 A
 
A.A))A..A1 1C>CCc                    SSS.nU R                   R                  SUUR                  5       S9nUR                  5         g! [        R
                   ax  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      Uee SnAff = f)a  
Enable or disable free access.

Parameters:
    free_access_settings: The free access settings.

Raises:
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the precondition is failed.
r   r&  r6  r   rW   r  rY   r  r   r4  N)r=   r   r   rc   rh   ri   rj   rk   r   r	   r   )r;   free_access_settingsr   rj   rp   s        r>   set_free_access_details*SecurityManagement.set_free_access_detailsD
  s    	'9EWXG'',,,)113 - H
 %%'$$ 	||''3.'(BCL))S0$%<=3F))S0-.DE3N	s   >A CA3CCrC   Nr(  )r   rO  )r   rO  )r:  r   )r   r   r   r   r   r?   r   r=   r1  setterr7  r;  r   r   rA   r>   r*  r*  	  sT    -( ! !  < ^^ :<rA   r*  c                  x    \ rS rSrSrSS jr\S 5       rSS jrSS jr	SS jr
SS jrSS	 jrSS
 jrSS jrSrg)UserManagementib
  zGraphDB User Management client.c                    Xl         g r8   rC   r   s     r>   r?   UserManagement.__init__e
  r   rA   c                    U R                   $ r8   rC   rD   s    r>   r=   UserManagement.http_clienth
  rF   rA   c                   SS0n U R                   R                  SUS9nUR                  5          UR                  5        Vs/ s H  n[	        S0 UD6PM     sn$ s  snf ! [
        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      UeUR                  R                  S:X  a  [        S5      UeUR                  R                  S:X  a#  [        SUR                  R                    35      Uee SnAff = f)aZ  
Get all users.

Returns:
    A list of users.

Raises:
    ResponseFormatError: If the response format is invalid.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the precondition is failed.
    InternalServerError: If the server returns an internal error.
r   r   z/rest/security/usersr   rV   NrW   r  rY   r  r   r4  r[   r\   r   )r=   rb   rc   rd   r&   r^   re   r   rh   ri   rj   rk   r   r	   r   r
   rl   )r;   r   rj   userrp   s        r>   rf   UserManagement.listl
  sG    /0	''++,BG+TH%%'19AtAAA	* )8> $$ 	||''3.'(BCL))S0$%<=3F))S0-.DE3N))S0)-cll.?.?-@A 	sG   *B A  AA  A   B0A??BB EB0EEc                4    SS0nU R                   R                  SU 3US9nUR                  5          [        S0 UR	                  5       D6$ ! [
        [        4 a  n[        SU 35      UeSnAff = f! [        R                   a  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      UeUR                  R                  S:X  a#  [        SUR                  R                   35      Uee SnAff = f)aE  
Get a user.

Parameters:
    username: The username of the user.

Returns:
    User: The user.

Raises:
    ResponseFormatError: If the response format is invalid.
    ForbiddenError: If the request is forbidden.
    NotFoundError: If the user is not found.
    InternalServerError: If the server returns an internal error.
r   r   /rest/security/users/r   rV   NrY   r  r   User not found.r[   r\   r   )r=   rb   rc   r&   rd   r^   re   r   rh   ri   rj   rk   r	   r   r
   rl   )r;   usernamer   rj   rp   s        r>   rb   UserManagement.get
  s"    	!34G''++'z2G , H %%'.hmmo..	* )8> $$ 		||''3.$%<=3F))S0#$56C?))S0)-cll.?.?-@A 		s5   1A4 A A1A,,A11A4 4DB
DDc                "   [        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      e SS0nU R                  R                  SU 3X2R                  5       S9nUR                  5         g! [        R                   ax  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      UeUR                  R                  S:X  a  [        S5      Uee SnAff = f)aV  
Overwrite a user.

Parameters:
    username: The username of the user.
    user: The user to overwrite.

Raises:
    TypeError: if username is not a string or user is not an instance of User.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    NotFoundError: If the user is not found.
Username must be a string.z!User must be an instance of User.r   r   rH  r   rW   r  rY   r  r   rI  N)r_   ra   re   r&   r=   r   r   rc   rh   ri   rj   rk   r   r	   r   r;   rJ  rE  r   rj   rp   s         r>   	overwriteUserManagement.overwrite
  s     (C((899$%%?@@	%'9:G''++'z2G,,. , H %%'$$ 	||''3.'(BCL))S0$%<=3F))S0#$56C?	s   ?B DA3D		Dc                P   [        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      e SS0nU R                  R                  SU 3X2R                  5       S9nUR                  5         g! [        R                   a  nUR                  R                  S:X  a#  [        SUR                  R                   35      UeUR                  R                  S	:X  a  [        S
5      UeUR                  R                  S:X  a  [        S5      Uee SnAff = f)aU  
Create a user.

Parameters:
    username: The username of the user.
    user: The user to create.

Raises:
    TypeError: if username is not a string or user is not an instance of UserCreate.
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
rM  z'User must be an instance of UserCreate.r   r   rH  r   r   Bad request. rW   r  rY   r  N)r_   ra   re   r'   r=   r   r   rc   rh   ri   rj   rk   r   rl   r   r	   rN  s         r>   r  UserManagement.create
  s    (C((899$
++EFF	%'9:G'',,'z2G,,. - H %%'$$ 	||''3.%cll6G6G5H&IJPSS))S0'(BCL))S0$%<=3F	s   ?B D%B
D  D%c                :   [        U[        5      (       d  [        S5      e U R                  R	                  SU 35      nUR                  5         g! [        R                   a  nUR                  R                  S:X  a#  [        SUR                  R                   35      UeUR                  R                  S:X  a  [        S5      UeUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      Uee SnAff = f)a;  
Delete a user.

Parameters:
    username: The username of the user.

Raises:
    TypeError: if username is not a string.
    BadRequestError: If the request is bad.
    UnauthorisedError: If the request is unauthorised.
    ForbiddenError: If the request is forbidden.
    NotFoundError: If the user is not found.
rM  rH  r   rR  rW   r  rY   r  r   rI  N)r_   ra   re   r=   r   rc   rh   ri   rj   rk   r   rl   r   r	   r   r;   rJ  rj   rp   s       r>   r   UserManagement.delete
  s     (C((899	''..1Fxj/QRH%%'$$ 		||''3.%cll6G6G5H&IJPSS))S0'(BCL))S0$%<=3F))S0#$56C?		s   .A D%B0DDc                   [        U[        5      (       d  [        S5      e[        U[        [        45      (       d  [        S5      e[        U[        5      (       a  UR                  5       nOUn SS0nU R                  R                  SU 3XCS9nUR                  5         g! [        R                   aR  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S	:X  a  [        S
5      Uee SnAff = f)a  
Update a user.

!!! Note
    Certain user fields are not updatable using PATCH. For example, at the
    time of writing, `grantedAuthorities` are not updatable, but `appSettings` are.

Parameters:
    username: The username of the user.
    user: The user data to update, either as a UserUpdate instance or a dict.

Raises:
    TypeError: if username is not a string or user is not an instance of UserUpdate or dict.
    ForbiddenError: If the request is forbidden.
    PreconditionFailedError: If the precondition is failed.
rM  z/User must be an instance of UserUpdate or dict.r   r   rH  r   rY   r  r   r4  N)r_   ra   re   r(   r   r   r=   r   rc   rh   ri   rj   rk   r	   r   )r;   rJ  rE  	user_datar   rj   rp   s          r>   updateUserManagement.update  s    " (C((899$T 233MNNdJ''II	%'9:G''--'z2G . H %%'$$ 	||''3.$%<=3F))S0-.DE3N	s   01B" "D6ADDc                   [        U[        5      (       d  [        S5      e U R                  R	                  SU S35      nUR                  5         UR                  5       $ ! [        R                   ax  nUR                  R                  S:X  a  [        S5      UeUR                  R                  S:X  a  [        S5      UeUR                  R                  S:X  a  [        S	5      Uee S
nAff = f)a`  
Retrieve custom roles associated with the user.

Parameters:
    username: The username of the user.

Returns:
    list[str]: The custom roles for the user.

Raises:
    TypeError: if username is not a string.
    ForbiddenError: If the request is forbidden.
    NotFoundError: If the user is not found.
    InternalServerError: If the request fails.
rM  rH  z/custom-rolesrY   r  r   rI  r[   r  N)r_   ra   re   r=   rb   rc   rd   rh   ri   rj   rk   r	   r   r
   rU  s       r>   custom_rolesUserManagement.custom_rolesC  s      (C((899	''++'z?H %%'==?"$$ 	||''3.$%<=3F))S0#$56C?))S0)*BCL	s   >A! !C-5A3C((C-rC   Nr(  )r   z
list[User])rJ  ra   r   r&   )rJ  ra   rE  r&   r   r)  )rJ  ra   rE  r'   r   r)  )rJ  ra   r   r)  )rJ  ra   rE  zUserUpdate | dict[str, t.Any]r   r)  )rJ  ra   r   zt.List[str])r   r   r   r   r   r?   r   r=   rf   rb   rO  r  r   rY  r\  r   r   rA   r>   r?  r?  b
  sF    )( ! !#J%N D D>&P rA   r?  c                     ^  \ rS rSrSr  S       SU 4S jjjr\SS j5       r\SS j5       r\SS j5       r	\SS j5       r
\SS j5       r\SS	 j5       r\SS
 j5       rSS jrSrU =r$ )GraphDBClientif  af  GraphDB Client

This client and its inner management objects perform HTTP requests via
httpx and may raise httpx-specific exceptions. Errors documented by GraphDB
in its OpenAPI 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 GraphDB 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.
c                  > [         TU ]  " XU40 UD6  [        U R                  5      U l        [        U R                  5      U l        [        U R                  5      U l        [        U R                  5      U l
        [        U R                  5      U l        [        U R                  5      U l        [        U R                  5      U l        g r8   )r/  r?   r   r=   _cluster_grouprY  _monitoringrp  	_recoveryrS  _graphdb_repository_managerr  _graphdb_repositoriesr*  	_securityr?  _users)r;   base_urlauthr:  kwargsr1  s        r>   r?   GraphDBClient.__init__y  s     	;F;4T5E5EF/0@0@A+D,<,<=+<T=M=M+N(%9$:J:J%K"+D,<,<=$T%5%56rA   c                    U R                   $ r8   )ra  rD   s    r>   rj  GraphDBClient.cluster  s    """rA   c                    U R                   $ r8   )rb  rD   s    r>   
monitoringGraphDBClient.monitoring  s    rA   c                    U R                   $ r8   )rc  rD   s    r>   recoveryGraphDBClient.recovery      ~~rA   c                    U R                   $ )zAServer-level repository management operations (GraphDB-specific).)rd  rD   s    r>   r  GraphDBClient.repositories  s     ///rA   c                    U R                   $ r8   )re  rD   s    r>   graphdb_repositories"GraphDBClient.graphdb_repositories  s    )))rA   c                    U R                   $ r8   )rf  rD   s    r>   securityGraphDBClient.security  rt  rA   c                    U R                   $ r8   )rg  rD   s    r>   usersGraphDBClient.users  s    {{rA   c                    U R                   R                  SXS.S9nUR                  5         UR                  R	                  SS5      nUR                  S5      (       d  [        S5      e UR                  5       n [        R                  " XT5      $ ! [        [        4 a  n[        SU 35      UeS	nAff = f! [        [        4 a  n[        S
U 35      UeS	nAff = f! [        R                   an  nUR                  R                  nUS:X  a#  [!        SUR                  R"                   35      UeUS:X  a#  [%        SUR                  R"                   35      Uee S	nAff = f)a  Authenticate with GraphDB and obtain a GDB token.

Parameters:
    username: The username to authenticate with.
    password: The password to authenticate with.

Returns:
    An AuthenticatedUser instance containing user details and the GDB token.

Raises:
    UnauthorisedError: If the credentials are invalid.
    BadRequestError: If the request body is invalid.
    ResponseFormatError: If the response cannot be parsed.
z/rest/login)rJ  passwordr   Authorizationr  zGDB z.Authorization header missing or invalid formatz Failed to parse login response: Nz$Failed to parse authenticated user: r   r   rW   zInvalid credentials: )r=   r   rc   r   rb   
startswithr   rd   r^   re   r   from_responserh   ri   rj   rk   r   rl   r   )r;   rJ  r  rj   auth_headerr$  rp   rr   s           r>   loginGraphDBClient.login  sx   #	'',,"*A - H %%'"**..CK))&11)D }}(66tII 	* )6se< 	* ):3%@
 $$ 	\\--F}%(9#,,:K:K9L&MNTWW3'+CLL,=,=+>? 	sU   A)C! ,B =B: B7#B22B77C! :C
CCC! !E#5A)EE#)ra  re  rd  rb  rc  rf  rg  )Ng      >@)rh  ra   ri  ztuple[str, str] | str | Noner:  zfloat | httpx.Timeoutrj  zt.Any)r   r   )r   rY  )r   rp  )r   rS  )r   r  )r   r*  )r   r?  )rJ  ra   r  ra   r   r   )r   r   r   r   r   r?   r   rj  ro  rr  r  rx  r{  r~  r  r   rP  rQ  s   @r>   r_  r_  f  s    * .2)-	77 +7 '	7
 7 7  # #       0 0 * *    2 2rA   r_  )Rr   
__future__r   rd   r  r  typingr   rh   rdflib.contrib.rdf4jrdflibr   r   r   !rdflib.contrib.graphdb.exceptionsr   r   r	   r
   r   r   r   r   r   r   r   rdflib.contrib.graphdb.modelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   rdflib.contrib.graphdb.utilr-   r.   r/   Unionr  ra   r  TupleOptionalr  r  Iterable	FilesTyper]   r5   r   contribrdf4jclientr-  rS  rY  rp  r  r*  r?  r_  r   rA   r>   <module>r     s    "  	     ) )          : -gg	DDKGGAJJsOQWWUCe%<==>GGAJJsOQWWUCe%<=qzz#NO	Q GGIIc;JJqwwsK'()+	
 H i iX	Y Yxh%%,,77 hV?,,33EE ?4X XvJ
 J
ZY Yx@ @FA AHrK rrA   