
    01i>                       % S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	J
r
JrJrJrJrJrJr  SSKJrJr  \(       a(  SSKJrJrJrJrJrJr  SSKJrJr  SS	KJr  SS
K J!r!J"r"J#r#  Sr$Sr%Sr&Sr'S\(S'   \RR                  r)\RT                  r*\RV                  r+/ SQr, " S S\5      r- " S S\5      r. " S S\5      r/ " S S5      r0 " S S5      r1g)a  ## Types of store

`Context-aware`: An RDF store capable of storing statements within contexts
is considered context-aware. Essentially, such a store is able to partition
the RDF model it represents into individual, named, and addressable
sub-graphs.

Relevant Notation3 reference regarding formulae, quoted statements, and such:
http://www.w3.org/DesignIssues/Notation3.html

`Formula-aware`: An RDF store capable of distinguishing between statements
that are asserted and statements that are quoted is considered formula-aware.

`Transaction-capable`: capable of providing transactional integrity to the
RDF operations performed on it.

`Graph-aware`: capable of keeping track of empty graphs.
    )annotationsN)BytesIO)
TYPE_CHECKINGAnyDict	GeneratorIterableIteratorMappingOptionalTupleUnion)
DispatcherEvent)Graph_ContextType	_QuadType_TripleChoiceType_TriplePatternType_TripleType)QueryUpdate)Result)
IdentifierNodeURIRef   NoneUNKNOWN)StoreCreatedEventTripleAddedEventTripleRemovedEventNodePicklerStorec                      \ rS rSrSrSrg)r!   I   zoThis event is fired when the Store is created.

Attributes:
    configuration: String used to create the store
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r(       F/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/store.pyr!   r!   I   s    r0   r!   c                      \ rS rSrSrSrg)r"   Q   zThis event is fired when a triple is added.

Attributes:
    triple: The triple added to the graph.
    context: The context of the triple, if any.
    graph: The graph to which the triple was added.
r(   Nr)   r(   r0   r1   r"   r"   Q       r0   r"   c                      \ rS rSrSrSrg)r#   [   zThis event is fired when a triple is removed.

Attributes:
    triple: The triple removed from the graph.
    context: The context of the triple, if any.
    graph: The graph from which the triple was removed.
r(   Nr)   r(   r0   r1   r#   r#   [   r4   r0   r#   c                  j    \ rS rSrSS jrSS jrSS jrSS jr S     SS jjrSS jr	SS	 jr
S
rg)r$   e   c                V    0 U l         0 U l        U R                   R                  U l        g N)_objects_ids__getitem___get_objectselfs    r1   __init__NodePickler.__init__f   s"    (*$&	==44r0   c                Z     U R                   R                  U5      $ ! [         a     g f = fr:   )r<   get	TypeError)r@   keys     r1   _get_idsNodePickler._get_idsk   s,    	99==%% 		s    
**c                <    XR                   U'   X R                  U'   g r:   )r;   r<   )r@   objectids      r1   registerNodePickler.registerq   s    "b		&r0   c                    [        [        U5      5      nU R                  Ul         UR	                  5       $ ! [
         a  n[        SU-  5      eS nAff = f)Nz Could not find Node class for %s)	Unpicklerr   r>   persistent_loadloadKeyErrorUnpicklingError)r@   supes       r1   loadsNodePickler.loadsu   sU    wqz" "--	J779 	J!"Dq"HII	Js   7 
AAANc                    [        5       n[        U5      nU R                  Ul        UR	                  U5        UR                  5       $ r:   )r   PicklerrG   persistent_iddumpgetvalue)r@   objprotocolbinsrcps         r1   dumpsNodePickler.dumps   s8     iCL --	s||~r0   c                    U R                   R                  5       nUS	 UR                  [        U R                  R                  5       5      [        U R                  R                  5       5      S.5        U$ )Nr>   )r<   r;   )__dict__copyupdatetupler<   itemsr;   r@   states     r1   __getstate__NodePickler.__getstate__   sY    ""$- 499??,-5ATATAV;WX	
 r0   c                    U R                   R                  U5        [        U R                  5      U l        [        U R                  5      U l        U R                  R
                  U l        g r:   )rf   rh   dictr<   r;   r=   r>   rk   s     r1   __setstate__NodePickler.__setstate__   sE    U#O	T]]+==44r0   )r>   r<   r;   returnr   )rF   r   rt   Optional[str])rJ   r   rK   strrt   r   )rT   bytesrt   r   NN)r^   r   r_   Optional[Any]r`   ry   )rt   Mapping[str, Any])rl   rz   rt   r   )r*   r+   r,   r-   rA   rG   rL   rW   rc   rm   rq   r/   r(   r0   r1   r$   r$   e   sE    5
J OS		#0	>K	5r0   r$   c                     \ rS rSr% SrS\S'   SrS\S'   SrS\S'   SrS\S'     S"   S#S	 jjr	\
S$S
 j5       rS%S jr S&     S'S jjrS&S(S jjrS%S jrS)S j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S,S0S jjr S,   S1S jjr            S2S jr            S3S jrS4S5S jjrS6S jrS7S jrS8S jrS)S jrS)S jrS9S jr S9S  jr!S!r"g):r%      Fboolcontext_awareformula_awaretransaction_awaregraph_awareNc                b    SU l         [        5       U l        U(       a  U R                  U5        gg)zInitialize the Store.

Args:
    identifier: URIRef of the Store. Defaults to CWD
    configuration: String containing information open can use to
        connect to datastore.
N)_Store__node_picklerr   
dispatcheropen)r@   configuration
identifiers      r1   rA   Store.__init__   s)     6:$,IIm$ r0   c                z   U R                   c  SSKJnJn  SSKJnJnJnJn  [        5       =U l         nUR                  U S5        UR                  US5        UR                  US5        UR                  US5        UR                  US5        UR                  US	5        UR                  US
5        U R                   $ )Nr   )r   QuotedGraph)BNodeLiteralr   VariableSUBLGQV)r   rdflib.graphr   r   rdflib.termr   r   r   r   r$   rL   )r@   r   r   r   r   r   r   nps           r1   node_picklerStore.node_pickler   s    &7DD'2}4D"KKc"KK$KKs#KK%KKs#KKS)KK#&"""r0   c                H    U R                   R                  [        US95        g )N)r   )r   dispatchr!   r@   r   s     r1   createStore.create   s      !2!OPr0   c                    [         $ )a  Opens the store specified by the configuration string.

Args:
    configuration: Store configuration string
    create: If True, a store will be created if it doesn't exist.
        If False and the store doesn't exist, an exception is raised.

Returns:
    One of: VALID_STORE, CORRUPTED_STORE, or NO_STORE

Raises:
    Exception: If there are insufficient permissions to open the store.
)r    )r@   r   r   s      r1   r   
Store.open   s	      r0   c                    g)zCloses the database connection.

Args:
    commit_pending_transaction: Whether to commit all pending
        transactions before closing (if the store is transactional).
Nr(   )r@   commit_pending_transactions     r1   closeStore.close       r0   c                    g)zwDestroys the instance of the store.

Args:
    configuration: The configuration string identifying the store instance.
Nr(   r   s     r1   destroyStore.destroy   r   r0   c                    g)z:Allows the store to perform any needed garbage collection.Nr(   r?   s    r1   gcStore.gc   s    r0   c                H    U R                   R                  [        XS95        g)a  Adds the given statement to a specific context or to the model.

Args:
    triple: The triple to add
    context: The context to add the triple to
    quoted: If True, indicates this statement is quoted/hypothetical
        (for formula-aware stores)

Note:
    It should be an error to not specify a context and have the quoted
    argument be True. It should also be an error for the quoted argument
    to be True when the store is not formula-aware.
triplecontextN)r   r   r"   )r@   r   r   quoteds       r1   add	Store.add   s    & 	  !1!QRr0   c           	     r    U H1  u  p#pEUc   SU< SU< SU< S35       eU R                  X#U4U5        M3     g)a  Adds each item in the list of statements to a specific context.

The quoted argument is interpreted by formula-aware stores to indicate this
statement is quoted/hypothetical.

Note:
    The default implementation is a redirect to add.

Args:
    quads: An iterable of quads to add
NzContext associated with  z	 is None!)r   )r@   quadsrT   rb   ocs         r1   addN
Store.addN  sE      JA!= # =
 HHaAY"  r0   c                H    U R                   R                  [        XS95        g)z=Remove the set of triples matching the pattern from the storer   N)r   r   r#   )r@   r   r   s      r1   removeStore.remove  s     	  !36!STr0   c              #    #    Uu  p4n[        U[        5      (       a  [        U[        5      (       a   S5       e[        U[        5      (       a   S5       eU(       a2  U H+  nU R                  X4U4U5       H  u  u  pxpXxU	4U
4v   M     M-     gU R                  X4S4U5       H  u  u  pxpXxU	4U
4v   M     g[        U[        5      (       a~  [        U[        5      (       a   S5       eU(       a2  U H+  nU R                  XU4U5       H  u  u  pxpXxU	4U
4v   M     M-     gU R                  SXE4U5       H  u  u  pxpXxU	4U
4v   M     g[        U[        5      (       a  [        U[        5      (       a   S5       eU(       a2  U H+  nU R                  X<U4U5       H  u  u  pxpXxU	4U
4v   M     M-     gU R                  USU4U5       H  u  u  pxpXxU	4U
4v   M     gg7f)a  
A variant of triples that can take a list of terms instead of a single
term in any slot.  Stores can implement this to optimize the response
time from the default 'fallback' implementation, which will iterate
over each term in the list and dispatch to triples
z object_ / subject are both listsz"object_ / predicate are both listsNz"subject / predicate are both listsz"predicate / subject are both lists)
isinstancelisttriples)r@   r   r   subject	predicateobject_r^   s1p1o1cgsubjpreds                r1   triples_choicesStore.triples_choices  s    $ '-#Ggt$$!'400T2TT0!)T22X4XX2"C,0LL S17-(  "rlB..- # )-.)$LRR 2,**)
 &&!)T22X4XX2#D,0LL'2G-(  "rlB..- $ )-9.)$LRR 2,**)
 	4((!'400V2VV0%D,0LL 0'-(  "rlB..- & )-gtW5Mw(W$LRR2,** )X )s   GGc                    Uu  p4ng)a  
A generator over all the triples matching the pattern. Pattern can
include any objects for used for comparing against nodes in the store,
for example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph,
QuotedGraph, Date? DateRange?

Args:
    context: A conjunctive query can be indicated by either
        providing a value of None, or a specific context can be
        queries by passing a Graph instance (if store is context aware).
Nr(   )r@   triple_patternr   r   r   rJ   s         r1   r   Store.triplesZ  s      &4"Fr0   c                    g)a  
Number of statements in the store. This should only account for non-
quoted (asserted) statements if the context is not specified,
otherwise it should return the number of statements in the formula or
context given.

Args:
    context: a graph instance to query or None
Nr(   )r@   r   s     r1   __len__Store.__len__o  r   r0   c                    g)z
Generator over all contexts in the graph. If triple is specified,
a generator over all contexts the triple is in.

if store is graph_aware, may also return empty contexts

:returns: a generator over Nodes
Nr(   )r@   r   s     r1   contextsStore.contexts{  r   r0   c                    [         e)a  If stores provide their own SPARQL implementation, override this.

queryGraph is None, a URIRef or `__UNION__`
If None the graph is specified in the query-string/object
If URIRef it specifies the graph to query,
If  `__UNION__` the union of all named graphs should be queried
(This is used by ConjunctiveGraphs
Values other than None obviously only makes sense for
context-aware stores.)
NotImplementedError)r@   queryinitNsinitBindings
queryGraphkwargss         r1   r   Store.query  
    & "!r0   c                    [         e)a  If stores provide their own (SPARQL) Update implementation, override this.

queryGraph is None, a URIRef or `__UNION__`
If None the graph is specified in the query-string/object
If URIRef it specifies the graph to query,
If  `__UNION__` the union of all named graphs should be queried
(This is used by ConjunctiveGraphs
Values other than None obviously only makes sense for
context-aware stores.)
r   )r@   rh   r   r   r   r   s         r1   rh   Store.update  r   r0   c                    g)zBind a namespace to a prefix.

Args:
    prefix: The prefix to bind the namespace to.
    namespace: The URIRef of the namespace to bind.
    override: If True, rebind even if the given namespace is already bound
        to another prefix
Nr(   )r@   prefix	namespaceoverrides       r1   bind
Store.bind  r   r0   c                    g Nr(   )r@   r   s     r1   r   Store.prefix  r   r0   c                    gr   r(   )r@   r   s     r1   r   Store.namespace  r   r0   c              #     #    g7fr   r(   r?   s    r1   
namespacesStore.namespaces  s
     
 s   c                    gr   r(   r?   s    r1   commitStore.commit  r   r0   c                    gr   r(   r?   s    r1   rollbackStore.rollback  r   r0   c                    [        S5      e)zdAdd a graph to the store, no effect if the graph already
exists.

Args:
    graph: a Graph instance
,Graph method called on non-graph_aware store	Exceptionr@   graphs     r1   	add_graphStore.add_graph       FGGr0   c                    [        S5      e)zuRemove a graph from the store, this should also remove all
triples in the graph

Args:
    graphid: a Graph instance
r   r   r   s     r1   remove_graphStore.remove_graph  r   r0   )__node_picklerr   rx   )r   ru   r   zOptional[Identifier])rt   r$   )r   rv   rt   r   )F)r   zUnion[str, tuple[str, str]]r   r}   rt   zOptional[int])r   r}   rt   r   rs   )r   r   r   r   r   r}   rt   r   )r   zIterable[_QuadType]rt   r   r:   )r   r   r   Optional[_ContextType]rt   r   )r   r   r   r  rt   zKGenerator[Tuple[_TripleType, Iterator[Optional[_ContextType]]], None, None])r   r   r   r  rt   z>Iterator[Tuple[_TripleType, Iterator[Optional[_ContextType]]]])r   r  rt   int)r   zOptional[_TripleType]rt   z#Generator[_ContextType, None, None])r   zUnion[Query, str]r   rz   r   Mapping[str, Identifier]r   rv   r   r   rt   r   )rh   zUnion[Update, str]r   rz   r   r  r   rv   r   r   rt   r   )T)r   rv   r   r   r   r}   rt   r   )r   r   rt   ru   )r   rv   rt   zOptional[URIRef])rt   zIterator[Tuple[str, URIRef]])r   r   rt   r   )#r*   r+   r,   r-   r~   __annotations__r   r   r   rA   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   rh   r   r   r   r   r   r   r   r   r/   r(   r0   r1   r%   r%      s   M4M4#t#K (,+/%$% )%" # #"Q JO8BF	$ 	SS S 	S
 
S*#. +/U"U (U 
	U +/:+!:+ (:+
	:+@ +/4*4 (4 
H	4*	 /3
+
	,
" " "" /	"
 " " 
"*""" "" /	"
 " " 
".
HHr0   r%   )2r.   
__future__r   pickleior   typingr   r   r   r   r	   r
   r   r   r   r   rdflib.eventsr   r   r   r   r   r   r   r   r   rdflib.plugins.sparql.sparqlr   r   rdflib.queryr   r   r   r   r   VALID_STORECORRUPTED_STORENO_STOREr    r  rZ   rO   rS   __all__r!   r"   r#   r$   r%   r(   r0   r1   <module>r     s   & #     ,  ;#44   ..	(( u  15 15hMH MHr0   