
    4Yshy                         d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
mZ d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zi fdZy)z+

Code for carrying out Update Operations

    )GraphVariable)QueryContext)_fillTemplate_join)evalBGPevalPartc                 Z    |dk(  r| j                   S | j                  j                  |      S )NDEFAULT)graphdatasetget_context)ctxgs     |/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/sparql/update.py_graphOrDefaultr      s(    I~yy{{&&q))    c                 Z   |dk(  r| j                   gS |dk(  rL| j                  j                         D cg c](  }|j                  | j                   j                  k7  s'|* c}S |dk(  r#t	        | j                  j                               S | j                  j                  |      gS c c}w )z!
    return a list of graphs
    r   NAMEDALL)r   r   contexts
identifierlistr   )r   r   cs      r   	_graphAllr      s     	I~		{	
g{{++-
AUAU1UA
 	
 
eCKK((*++''*++
s   (B(B(c                     |j                   r)| j                  |j                  d|j                          y| j                  |j                  d       y)z4
    http://www.w3.org/TR/sparql11-update/#load
    F)defaultpublicIDTr   N)graphiriloadiri)r   us     r   evalLoadr$   $   s9    
 	zz

;%r   c                     | j                   j                  |j                        }t        |      dkD  rt	        d|j
                  z        t	        d      )z6
    http://www.w3.org/TR/sparql11-update/#create
    r   zGraph %s already exists.zCreate not implemented!)r   r   r    len	Exceptionr   r   r#   r   s      r   
evalCreater)   /   sH     	

+A
1vz2Q\\ABB
-
..r   c                 \    t        | |j                        D ]  }|j                  d        y)z5
    http://www.w3.org/TR/sparql11-update/#clear
    NNNN)r   r    remover(   s      r   	evalClearr-   9   s+    
 sAJJ' %	#$%r   c                     | j                   j                  j                  rAt        | |j                        D ]'  }| j                   j                  j                  |       ) yt        | |       y)z4
    http://www.w3.org/TR/sparql11-update/#drop
    N)r   storegraph_awarer   r    remove_graphr-   r(   s      r   evalDropr2   B   sU     {{$$3

+ 	.AKK**1-	. 	#qr   c                     | j                   }||j                  z  }|j                  D ]/  }| j                  j	                  |      }||j                  |   z  }1 y)z:
    http://www.w3.org/TR/sparql11-update/#insertData
    Nr   triplesquadsr   r   r   r#   r   cgs       r   evalInsertDatar9   M   U    
 			ANA WW [[$$Q'
aggajr   c                     | j                   }||j                  z  }|j                  D ]/  }| j                  j	                  |      }||j                  |   z  }1 y)z:
    http://www.w3.org/TR/sparql11-update/#deleteData
    Nr4   r7   s       r   evalDeleteDatar<   \   r:   r   c                    t        | |j                        }|j                  D ]Z  }| j                  j	                  |      }| j                  |      }t        |t        t        ||j                  |                     }\ |D ]~  }| j                  }|t        |j                  |      z  }|j                  D ]H  }| j                  j	                  |j                  |            }|t        |j                  |   |      z  }J  y)z;
    http://www.w3.org/TR/sparql11-update/#deleteWhere
    N)r   r5   r6   r   r   	pushGraphr   r   r   r   get)r   r#   resr   r8   r   s         r   evalDeleteWhererA   k   s    
 #qyy
!CWW 7[[$$Q'MM"Cga4567
  /II	]199a(( 	/A((q2B-
A..B	/	/r   c                    | }|j                   rd}|j                   D ]w  }|j                  r=|st               }| j                  |      } d}| j	                  |j                  d       L|j
                  sY|j
                  }| j	                  |d       y |j                   sB|j                  r6| j                  j                  |j                        }| j                  |      } t        | |j                        }|j                   rFr|} |j                  r6| j                  j                  |j                        }| j                  |      } |D ]8  }| j                  }|j                  r|t        |j                  j                  |      z  }|j                  j                  j!                         D ]>  \  }}	| j                  j                  |j#                  |            }
|
t        |	|      z  }
@ |j$                  s|t        |j$                  j                  |      z  }|j$                  j                  j!                         D ]>  \  }}	| j                  j                  |j#                  |            }
|
t        |	|      z  }
@ ; y )NFTr   )usingr   r   r>   r!   named
withClauser   r   r	   wherer   deleter   r5   r6   itemsr?   insert)r   r#   originalctxotherDefaultddgr   r@   r   qr8   s              r   
evalModifyrO      s   K 	ww 	+Ayy#B--+C#'LD1GGE*	+0 77q||KK##ALL1mmA
3
 CwwC<<''5A--"C *YY88- 0 0!44B,,. *1[[,,QUU1X6mAq))* 88- 0 0!44B,,. *1[[,,QUU1X6mAq))**r   c                     |j                   \  }}t        | |      }t        | |      }|j                  |j                  k(  ry||z  }y)zY

    add all triples from src to dst

    http://www.w3.org/TR/sparql11-update/#add
    N)r   r   r   r   r#   srcdstsrcgdstgs         r   evalAddrV      sE     wwHC3$D3$D$//)DLDr   c                 `   |j                   \  }}t        | |      }t        | |      }|j                  |j                  k(  ry|j                  d       ||z  }| j                  j
                  j                  r&| j                  j
                  j                  |       y|j                  d       y)z

    remove all triples from dst
    add all triples from src to dst
    remove all triples from src

    http://www.w3.org/TR/sparql11-update/#move
    Nr+   )r   r   r   r,   r   r/   r0   r1   rQ   s         r   evalMoverX      s     wwHC3$D3$D$//)KK"#DLD
{{$$&&t,&'r   c                     |j                   \  }}t        | |      }t        | |      }|j                  |j                  k(  ry|j                  d       ||z  }y)zz

    remove all triples from dst
    add all triples from src to dst

    http://www.w3.org/TR/sparql11-update/#copy
    Nr+   )r   r   r   r,   rQ   s         r   evalCopyrZ      sR     wwHC3$D3$D$//)KK"#DLDr   c                 F   |D ]  }t        d |j                         D              }t        | |      }|j                  |_        	 |j                  dk(  rt        ||       n'|j                  dk(  rt        ||       n
|j                  dk(  rt        ||       n|j                  dk(  rt        ||       n|j                  dk(  rt        ||       n|j                  dk(  rt        ||       n|j                  d	k(  rt        ||       n~|j                  d
k(  rt        ||       nb|j                  dk(  rt        ||       nF|j                  dk(  rt        ||       n*|j                  dk(  rt        ||       nt!        d|       y#  |j"                  s Y xY w)ad  

    http://www.w3.org/TR/sparql11-update/#updateLanguage

    'A request is a sequence of operations [...] Implementations MUST
    ensure that operations of a single request are executed in a
    fashion that guarantees the same effects as executing them in
    lexical order.

    Operations all result either in success or failure.

    If multiple operations are present in a single request, then a
    result of failure from any operation MUST abort the sequence of
    operations, causing the subsequent operations to be ignored.'

    This will return None on success and raise Exceptions on error

    c              3   <   K   | ]  \  }}t        |      |f  y w)N)r   ).0kvs      r   	<genexpr>zevalUpdate.<locals>.<genexpr>  s     NAXa[!,Ns   )initBindingsLoadClearDropCreateAddMoveCopy
InsertData
DeleteDataDeleteWhereModifyzUnknown update operation: N)dictrH   r   prologuenamer$   r-   r2   r)   rV   rX   rZ   r9   r<   rA   rO   r'   silent)r   updatera   r#   r   s        r   
evalUpdaterr      s^   (  "N9K9K9MNN5|<zz	vva 7"#q!6!a 8#3"5Q6!a 6!a <'sA&<'sA&=(Q'8#3"! EFF?"@	88 s   EFF N)__doc__rdflibr   r   rdflib.plugins.sparql.sparqlr   rdflib.plugins.sparql.evalutilsr   r   rdflib.plugins.sparql.evaluater   r	   r   r   r$   r)   r-   r2   r9   r<   rA   rO   rV   rX   rZ   rr    r   r   <module>ry      sd    # 5 @ <*, &/%/(:*z$(8, ,. 6r   