
    01i                        S SK Jr  S SKrS SKJrJrJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S	S
S.r " S S\5      rg)    )annotationsN)IOAnyOptional)uuid4)Dataset)_nq_row)_nt_row)
SerializerAD)addremovec                  d   ^  \ rS rSrSr  SU 4S jjr  S	         S
S jjrS rS rSr	U =r
$ )PatchSerializer   z
Creates an RDF patch file to add and remove triples/quads.
Can either:
- Create an add or delete patch for a single Dataset.
- Create a patch to represent the difference between two Datasets.
c                0   > Xl         [        TU ]	  U5        g N)storesuper__init__)selfr   	__class__s     Z/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/plugins/serializers/patch.pyr   PatchSerializer.__init__   s     $
    c                `  ^ ^^^^ UR                  S5      nUR                  S5      nUR                  S5      mUR                  S5      mT(       d  S[        5        3mT R                  mUb  [        R                  " S5        TbE  TR                  5       T R                  R                  5       :w  a  [        R                  " ST 35        UUUU4S	 jnSUU U4S
 jjnU(       a  U[        ;   d
   SU 35       eO	U(       d  SnU" 5         U(       a7  [        R                  U5      n	U" T R                  R                  5       U	5        OFU(       a?  T R                  U5      u  pU" U
R                  5       SSS9  U" UR                  5       SSS9  TR                  SR                  TS5      5        g)a  Serialize the store to the given stream.

Args:
    stream: The stream to serialize to.
    base: The base URI to use for the serialization.
    encoding: The encoding to use for the serialization.
    kwargs: Additional keyword arguments.

Supported keyword arguments:

- operation: The operation to perform. Either 'add' or 'remove'.
- target: The target Dataset to compare against.
NB: Only one of 'operation' or 'target' should be provided.
- header_id: The header ID to use.
- header_prev: The previous header ID to use.
	operationtarget	header_idheader_prevzuuid:Nz&PatchSerializer does not support base.zBPatchSerializer does not use custom encoding. Given encoding was: c                    > TR                  ST S3R                  T S5      5        T(       a%  TR                  ST S3R                  T S5      5        TR                  SR                  T S5      5        g )NzH id <z> .
replacezH prev <z>
zTX .
)writeencode)encodingr    r!   streams   r   write_header/PatchSerializer.serialize.<locals>.write_headerD   sa    LL6)E299(INOx}C8??)TULL9=>r   c           	        > U  Hs  nU(       d%  TR                   R                  UR                  5      nU H>  nTR                  TR	                  XCR                  U5      R                  TS5      5        M@     Mu     g )Nr#   )r   get_context
identifierr$   
_patch_rowr%   )contextsop_codeuse_passed_contextscontexttripler&   r   r'   s        r   write_triples0PatchSerializer.serialize.<locals>.write_triplesJ   sd    #*"jj44W5G5GHG%FLL0B0BGLSS$i & $r   zInvalid operation: r   r   T)r0   r   zTC .
r#   )F)getr   r&   warningswarnloweradd_remove_methodsr   r.   _diffr$   r%   )r   r'   baser&   kwargsr   r   r(   r3   operation_codeto_add	to_remover    r!   s   `` `        @@r   	serializePatchSerializer.serialize   sg   . JJ{+	H%JJ{+	jj/y)I==MMBCHNN$48K8K8M$MMM''/j2
	? 	?		 		  22U6I)4UU2 I/33I>N$**--/@ $

6 2F&//+SdK),,.NX__Xy9:r   c                B    XR                   -
  nU R                   U-
  nX#4$ r   r   )r   r   rows_to_addrows_to_removes       r   r:   PatchSerializer._difff   s%    zz)f,**r   c                    X R                   R                  R                  :X  a  U S[        U5       3$ U S[	        X5       3$ )N )r   default_contextr,   r
   r	   )r   r2   
context_idr   s       r   r-   PatchSerializer._patch_rowk   sE    33>>>['&/!233['&"=!>??r   rC   )r   r   )NN)
r'   z	IO[bytes]r;   Optional[str]r&   rL   r<   r   returnNone)__name__
__module____qualname____firstlineno____doc__r   r@   r:   r-   __static_attributes____classcell__)r   s   @r   r   r      sj       #"&	F;F; F;  	F;
 F; 
F;P+
@ @r   r   )
__future__r   r6   typingr   r   r   uuidr   rdflibr   !rdflib.plugins.serializers.nquadsr	   rdflib.plugins.serializers.ntr
   rdflib.serializerr   r9   r    r   r   <module>r^      s;    "  $ $   5 1 ( C0 `@j `@r   