
    01i<                       S SK Jr  S SKrS SKrS SKrS SKJr  S SKJrJ	r	J
r
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  S SKJr  / SQrS SKr\	(       a  S SKJrJr  S S	K J!r!J"r"  S S
KJ#r#J$r$   " S S5      r% " S S5      r& " S S\'5      r( " S S5      r) " S S\\RT                  RF                  S4   5      r+ " S S5      r, " S S5      r- " S S5      r.g)    )annotationsN)BytesIO)IOTYPE_CHECKINGAnyBinaryIODictIteratorListMappingMutableSequenceOptionalTupleUnioncastoverload)urlparse)url2pathname)	ProcessorUpdateProcessorResult	ResultRowResultParserResultSerializerResultExceptionEncodeOnlyUnicode)Graph_TripleType)QueryUpdate)
IdentifierVariablec                  H    \ rS rSrSrSS jr0 0 S4         S	S jjrSrg)
r   -   z
Query plugin interface.

This module is useful for those wanting to write a query processor
that can plugin to rdf. If you are wanting to execute a query you
likely want to do so through the Graph class query method.
c                    g N selfgraphs     F/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/query.py__init__Processor.__init__6           Fc                    g r&   r'   )r)   
strOrQueryinitBindingsinitNsDEBUGs        r+   queryProcessor.query:   s     	r/   r'   Nr*   r   )
r1   zUnion[str, Query]r2   Mapping[str, Identifier]r3   Mapping[str, Any]r4   boolreturnr9   )__name__
__module____qualname____firstlineno____doc__r,   r5   __static_attributes__r'   r/   r+   r   r   -   sQ     24$&% / "	
  
 r/   r   c                  B    \ rS rSrSrSS jr0 0 4       SS jjrSrg)	r   D   a  Update plugin interface.

This module is useful for those wanting to write an update
processor that can plugin to rdflib. If you are wanting to execute
an update statement you likely want to do so through the Graph
class update method.

!!! example "New in version 4.0"
c                    g r&   r'   r(   s     r+   r,   UpdateProcessor.__init__O   r.   r/   c                    g r&   r'   )r)   r1   r2   r3   s       r+   updateUpdateProcessor.updateR   s     	r/   r'   Nr7   )r1   zUnion[str, Update]r2   r8   r3   r9   r;   None)r<   r=   r>   r?   r@   r,   rG   rA   r'   r/   r+   r   r   D   sD     24$&	& / "	
 
 r/   r   c                      \ rS rSrSrg)r   [   r'   N)r<   r=   r>   r?   rA   r'   r/   r+   r   r   [   s    r/   r   c                  2    \ rS rSrSrSS jrS rS	S jrSrg)
r   _   zBThis is a crappy work-around for http://bugs.python.org/issue11649c                    Xl         g r&   )_EncodeOnlyUnicode__stream)r)   streams     r+   r,   EncodeOnlyUnicode.__init__b   s    r/   c                    [        U[        5      (       a+  U R                  R                  UR	                  S5      5        g U R                  R                  U5        g )Nutf-8)
isinstancestrrO   writeencode)r)   args     r+   rV   EncodeOnlyUnicode.writee   s<    c3MM

7 34MM$r/   c                .    [        U R                  U5      $ r&   )getattrrO   r)   names     r+   __getattr__EncodeOnlyUnicode.__getattr__k   s    t}}d++r/   )__streamN)rP   r   r]   rU   r;   r   )	r<   r=   r>   r?   r@   r,   rV   r^   rA   r'   r/   r+   r   r   _   s    L%,r/   r   c                     ^  \ rS rSr% SrS\S'   SU 4S jjrSS jrSS jr\	SS j5       r
\	 S     SS	 jj5       r
 S     SS
 jjr
SS jrSrU =r$ )r   o   a  A single result row allows accessing bindings as attributes or with []

```python
>>> from rdflib import URIRef, Variable
>>> rr=ResultRow({ Variable('a'): URIRef('urn:cake') }, [Variable('a')])

>>> rr[0]
rdflib.term.URIRef('urn:cake')
>>> rr[1]
Traceback (most recent call last):
    ...
IndexError: tuple index out of range

>>> rr.a
rdflib.term.URIRef('urn:cake')
>>> rr.b
Traceback (most recent call last):
    ...
AttributeError: b

>>> rr['a']
rdflib.term.URIRef('urn:cake')
>>> rr['b']
Traceback (most recent call last):
    ...
KeyError: 'b'

>>> rr[Variable('a')]
rdflib.term.URIRef('urn:cake')

```

!!! example "New in version 4.0"
zMapping[str, int]labelsc                   >^ [         [        U ]  U U4S jU 5       5      n[        S [	        U5       5       5      Ul        U$ )Nc              3  F   >#    U  H  nTR                  U5      v   M     g 7fr&   )get).0vvaluess     r+   	<genexpr>$ResultRow.__new__.<locals>.<genexpr>   s     6Ufvzz!}}fs   !c              3  H   #    U  H  n[        US    5      US   4v   M     g7f)   r   N)rU   )rh   xs     r+   rk   rl      s#     L:KQAaD	1Q40:Ks    ")superr   __new__dict	enumeraterd   )clsrj   rd   instance	__class__s    `  r+   rq   ResultRow.__new__   s:     C06Uf6UVL)F:KLLr/   c                z    XR                   ;  a  [        U5      e[        R                  X R                   U   5      $ r&   )rd   AttributeErrortuple__getitem__r\   s     r+   r^   ResultRow.__getattr__   s1    {{" &&  {{4'899r/   c                R    [         R                  X5      $ ! [         a    XR                  ;   a$  [         R                  X R                  U   5      s $ [	        U5      U R                  ;   a-  [         R                  X R                  [	        U5         5      s $ [        U5      ef = fr&   )rz   r{   	TypeErrorrd   rU   KeyErrorr\   s     r+   r{   ResultRow.__getitem__   s    		!$$T00 	!{{"(({{4/@AA4yDKK'(({{3t9/EFF4. 	!s    ;B&AB&B&c                    g r&   r'   r)   r]   defaults      r+   rg   ResultRow.get   s    ADr/   c                    g r&   r'   r   s      r+   rg   r      s      #r/   c                0     X   $ ! [          a    Us $ f = fr&   )r   r   s      r+   rg   r      s#    	: 	N	s    c                B   ^  [        U 4S jT R                   5       5      $ )Nc              3  B   >#    U  H  nTU   c  M  UTU   4v   M     g 7fr&   r'   )rh   ri   r)   s     r+   rk   #ResultRow.asdict.<locals>.<genexpr>   s!     M+QaLQQL+s   
)rr   rd   r)   s   `r+   asdictResultRow.asdict   s    M$++MMMr/   r'   )rj   zMapping[Variable, Identifier]rd   zList[Variable])r]   rU   r;   r!   )r]   zUnion[str, int, Any]r;   r!   )r]   rU   r   r!   r;   r!   ).)r]   rU   r   Optional[Identifier]r;   r   r&   )r;   zDict[str, Identifier])r<   r=   r>   r?   r@   __annotations__rq   r^   r{   r   rg   r   rA   __classcell__)rv   s   @r+   r   r   o   s    !F :
! D D9<##"6#	# #
 :>"6	N Nr/   r   .c                      \ rS rSrSrSS jr\SS j5       r\R                      SS j5       r\	   S         SS jj5       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rg)r      a  
A common class for representing query result.

There is a bit of magic here that makes this appear like different
Python objects, depending on the type of result.

If the type is "SELECT", iterating will yield lists of ResultRow objects

If the type is "ASK", iterating will yield a single bool (or
bool(result) will return the same bool)

If the type is "CONSTRUCT" or "DESCRIBE" iterating will yield the
triples.

`len(result)` also works.
c                    US;  a  [        SU-  5      eXl        S U l         S U l        S U l        S U l        S U l        g )N)	CONSTRUCTDESCRIBESELECTASKzUnknown Result type: %s)r   typevars	_bindings_genbindings	askAnswerr*   )r)   type_s     r+   r,   Result.__init__   sH    BB!";e"CDD	.2	9IMOS)-&*
r/   c                    U R                   (       a/  U =R                  [        U R                   5      -  sl        SU l         U R                  $ )z&
a list of variable bindings as dicts
N)r   r   listr   s    r+   bindingsResult.bindings   s8    
 NNd4#4#455N $D~~r/   c                    [        U[        R                  [        R                  45      (       a  Xl        / U l        g Xl        g r&   )rT   typesGeneratorType	itertoolsislicer   r   )r)   bs     r+   r   r      s6     a%--y/?/?@AA !DN Nr/   Nc                    SSK Jn  U(       a  UnOU(       a  UR                  SS5      S   nOSnUR                  U[        5      " 5       nUR
                  " U 4SU0UD6$ )z#Parse a query result from a source.r   plugin;rn   xmlcontent_type)rdflibr   splitrg   r   parse)sourceformatr   kwargsr   
plugin_keyparsers          r+   r   Result.parse   sg     	"J%++C3A6JJJ57 ||
!-
17
 	
r/   c                   U R                   S;   a  U R                  R                  " U4X#S.UD6$  SSKJn  UR                  U[        5      " U 5      nUc:  [        5       n[        U5      nUR                  " U4SU0UD6  UR                  5       $ [        US5      (       a-  [        [        [           U5      n	UR                  " U	4SU0UD6  g[        [        U5      n
[        U
5      u  ppnnUS:X  a"  US	:w  a  [!        S
U
< S35      e[#        U5      nOU
n[%        US5       n	UR                  " U	4SU0UD6  SSS5        g! , (       d  f       g= f)au  
Serialize the query result.


Args:
    destination: Path of file output or BufferedIOBase object
        to write the output to. If `None` this function
        will return the output as  `bytes`
    encoding: Encoding of output.
    format: The format used for serialization.
        See [sparql.results module][rdflib.plugins.sparql.results]
        for all builtin SPARQL result serialization.
        Further serializer can be loaded [as plugin][rdflib.plugin].
        Some example formats are
        [csv][rdflib.plugins.sparql.results.csvresults.CSVResultSerializer],
        [json][rdflib.plugins.sparql.results.jsonresults.JSONResultSerializer],
        [txt][rdflib.plugins.sparql.results.txtresults.TXTResultSerializer]
        or
        [xml][rdflib.plugins.sparql.results.xmlresults.XMLResultSerializer]

Returns:
    Serialized result, when destination is not given.
r   r   )encodingr   r   r   Nr   rV   file zthe file URI z2 has an authority component which is not supportedwb)r   r*   	serializer   r   rg   r   r   r   getvaluehasattrr   r   bytesrU   r   
ValueErrorr   open)r)   destinationr   r   argsr   
serializerstreambstream2rP   locationschemenetlocpathparamsr5   fragmentos_paths                     r+   r   Result.serialize  sh   < 9911 ::''&.AE  	4!ZZ(89$?
&yG'0G   D8DtD##%%;(("U)[1F  C(CdC  C-H<DX<N9FD%R<$'|3ef  't,"gt$$$VGhG$G % %$s   $E
Ec                    U R                   S:X  a  gU R                   S:X  a  [        U R                  5      $ [        U R                  5      $ )Nr   rn   r   )r   lenr   r*   r   s    r+   __len__Result.__len__V  s<    99YY("t}}%% tzz?"r/   c                V    U R                   S:X  a  U R                  $ [        U 5      S:  $ )Nr   r   )r   r   r   r   s    r+   __bool__Result.__bool___  s&    99>>!t9q= r/   c              #    #    U R                   S;   a  U R                   H  nUv   M	     g U R                   S:X  a  U R                  v   g U R                   S:X  a  U R                  (       aV  U R                   H>  nU(       d  M  U R                  R                  U5        [        X R                  5      v   M@     S U l        g U R                   H#  nU(       d  M  [        X R                  5      v   M%     g g 7f)Nr   r   r   )r   r*   r   r   r   appendr   r   )r)   tr   s      r+   __iter__Result.__iter__f  s      9911ZZ  YY%.. YY("   **Aq--a0'9955	 +
 %)!Aq'9955 ( #s   A=C6AC6C6c                |  ^ U R                   S;   a(  U R                  b  U R                  R                  X5      $ U R                   S:X  a[  US:X  aU  [        R                  " S[
        SS9  U R                   V^s/ s H"  m[        U4S jU R                   5       5      PM$     sn$ [        SU < S	U< S35      es  snf )
Nr   r   resultzPaccessing the 'result' attribute is deprecated. Iterate over the object instead.   )
stacklevelc              3  .   >#    U  H
  nTU   v   M     g 7fr&   r'   )rh   ri   r   s     r+   rk   %Result.__getattr__.<locals>.<genexpr>  s     3A1Q4s   'z' object has no attribute ')
r   r*   r^   warningswarnDeprecationWarningr   rz   r   ry   )r)   r]   r   s     `r+   r^   Result.__getattr__  s    9911djj6L::))$55YY("tx'7MM4"	 ?CmmLmU333mLL d!STT Ms   9)B9c                p    U R                   UR                   :w  a  gU R                   S:X  a  U R                  UR                  :H  $ U R                   S:X  a9  U R                  UR                  :H  =(       a    U R                  UR                  :H  $ U R                  UR                  :H  $ ! [
         a     gf = f)NFr   r   )r   r   r   r   r*   	Exception)r)   others     r+   __eq__Result.__eq__  s    
	yyEJJ&yyE!~~88h&yyEJJ.R4==ENN3RRzzU[[00 		s#   B( (B( AB( B( (
B54B5)r   r   r   r*   r   r   )r   rU   )r;   z.MutableSequence[Mapping[Variable, Identifier]])r   z^Union[MutableSequence[Mapping[Variable, Identifier]], Iterator[Mapping[Variable, Identifier]]]r;   rI   )NNN)
r   zOptional[IO]r   Optional[str]r   r   r   r   r;   r   )NrS   r   )
r   zOptional[Union[str, IO]]r   rU   r   rU   r   r   r;   zOptional[bytes])r;   int)r;   r:   )r;   z-Iterator[Union[_TripleType, bool, ResultRow]]ra   )r   r   r;   r:   )r<   r=   r>   r?   r@   r,   propertyr   setterstaticmethodr   r   r   r   r   r^   r   rA   r'   r/   r+   r   r      s    "+   __
 
  # $&*


 $
 	

 

 
2 15	@-@ @ 	@
 @ 
@D#!6	664U"r/   r   c                  $    \ rS rSrS rSS jrSrg)r   i  c                    g r&   r'   r   s    r+   r,   ResultParser.__init__  r.   r/   c                    g)zreturn a Result objectNr'   )r)   r   r   s      r+   r   ResultParser.parse      r/   r'   N)r   r   r   r   r;   r   )r<   r=   r>   r?   r,   r   rA   r'   r/   r+   r   r     s    r/   r   c                  ,    \ rS rSrSS jrSSS jjrSrg)	r   i  c                    Xl         g r&   r   )r)   r   s     r+   r,   ResultSerializer.__init__  s    r/   c                    g)z#return a string properly serializedNr'   )r)   rP   r   r   s       r+   r   ResultSerializer.serialize  r   r/   r   N)r   r   )rS   )rP   r   r   rU   r   r   r;   rI   )r<   r=   r>   r?   r,   r   rA   r'   r/   r+   r   r     s     r/   r   )/
__future__r   r   r   r   ior   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   urllib.parser   urllib.requestr   __all__rdflib.termr   rdflib.graphr   r   rdflib.plugins.sparql.sparqlr   r    r!   r"   r   r   r   r   r   termr   r   r   r   r'   r/   r+   <module>r     s    "         " '	 /:0 . .	i 	, , QNfkk,,c12 QNhY Yx  r/   