
    4Ysh))                     @   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ g dZerd dlmZ d dlmZ  G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z y)    N)IOTYPE_CHECKINGListOptionalUnioncast)BytesIO)urlparse)	ProcessorResultResultParserResultSerializerResultException)Graph)Variablec                   $    e Zd ZdZd Zi i dfdZy)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                      y N selfgraphs     l/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/query.py__init__zProcessor.__init__           Fc                      y r   r   )r   
strOrQueryinitBindingsinitNsDEBUGs        r   queryzProcessor.query!   r   r   N)__name__
__module____qualname____doc__r   r"   r   r   r   r   r      s     .0% r   r   c                   "    e Zd ZdZd Zi i fdZy)UpdateProcessora!  
    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.

    .. versionadded:: 4.0

    c                      y r   r   r   s     r   r   zUpdateProcessor.__init__2   r   r   c                      y r   r   )r   r   r   r    s       r   updatezUpdateProcessor.update5   r   r   N)r#   r$   r%   r&   r   r+   r   r   r   r(   r(   %   s    
 /1 r   r(   c                       e Zd Zy)r   N)r#   r$   r%   r   r   r   r   r   9   s    r   r   c                   "    e Zd ZdZd Zd Zd Zy)EncodeOnlyUnicodezR
    This is a crappy work-around for
    http://bugs.python.org/issue11649


    c                     || _         y r   )_EncodeOnlyUnicode__stream)r   streams     r   r   zEncodeOnlyUnicode.__init__E   s	    r   c                     t        |t              r+| j                  j                  |j	                  d             y | j                  j                  |       y )Nutf-8)
isinstancestrr0   writeencode)r   args     r   r6   zEncodeOnlyUnicode.writeH   s9    c3MM

7 34MM$r   c                 .    t        | j                  |      S r   )getattrr0   r   names     r   __getattr__zEncodeOnlyUnicode.__getattr__N   s    t}}d++r   N)r#   r$   r%   r&   r   r6   r=   r   r   r   r.   r.   =   s    %,r   r.   c                   <     e Zd ZdZ fdZd Zd ZddZd Z xZ	S )	ResultRowa  
    a single result row
    allows accessing bindings as attributes or with []

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

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

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

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

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

    .. versionadded:: 4.0

    c                     t         t        |   | fd|D              }t        d t	        |      D              |_        |S )Nc              3   @   K   | ]  }j                  |        y wr   )get).0vvaluess     r   	<genexpr>z$ResultRow.__new__.<locals>.<genexpr>x   s     6Uvzz!}6Us   c              3   B   K   | ]  }t        |d          |d   f  yw)   r   N)r5   )rC   xs     r   rF   z$ResultRow.__new__.<locals>.<genexpr>y   s!     LQAaD	1Q40Ls   )superr?   __new__dict	enumeratelabels)clsrE   rN   instance	__class__s    `  r   rK   zResultRow.__new__v   s8    C06Uf6UVL)F:KLLr   c                 z    || j                   vrt        |      t        j                  | | j                   |         S r   )rN   AttributeErrortuple__getitem__r;   s     r   r=   zResultRow.__getattr__|   s5    t{{" &&  t{{4'899r   c                 P   	 t         j                  | |      S # t        $ r || j                  v r%t         j                  | | j                  |         cY S t	        |      | j                  v r.t         j                  | | j                  t	        |               cY S t        |      w xY wr   )rT   rU   	TypeErrorrN   r5   KeyErrorr;   s     r   rU   zResultRow.__getitem__   s    	!$$T400 	!t{{"((t{{4/@AA4yDKK'((t{{3t9/EFF4. 	!s    :B%AB%B%c                 0    	 | |   S # t         $ r |cY S w xY wr   )rX   )r   r<   defaults      r   rB   zResultRow.get   s%    	: 	N	s    c                 @     t         fd j                  D              S )Nc              3   8   K   | ]  }|   	||   f  y wr   r   )rC   rD   r   s     r   rF   z#ResultRow.asdict.<locals>.<genexpr>   s"     MQa9LQQLMs   
)rL   rN   r   s   `r   asdictzResultRow.asdict   s    M$++MMMr   r   )
r#   r$   r%   r&   rK   r=   rU   rB   r^   __classcell__)rQ   s   @r   r?   r?   R   s#    !F:
!Nr   r?   c            
           e Zd ZdZdefdZd Zd Z eeed      Z	e
	 	 	 dd	ee   d
ee   fd       Z	 	 	 ddeeeef      ded	edee   fdZd Zd Zd Zd Zd Zy)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.

    type_c                 |    |dvrt        d|z        || _        d | _        d | _        d | _        d | _        d | _        y )N)	CONSTRUCTDESCRIBESELECTASKzUnknown Result type: %s)r   typevars	_bindings_genbindings	askAnswerr   )r   ra   s     r   r   zResult.__init__   sG    BB!";e"CDD	04	 #"
r   c                     | j                   r/| xj                  t        | j                         z  c_        d | _         | j                  S r   )rj   ri   listr]   s    r   _get_bindingszResult._get_bindings   s6    NNd4#4#455N $D~~r   c                     t        |t        j                  t        j                  f      r|| _        g | _        y || _        y r   )r4   typesGeneratorType	itertoolsislicerj   ri   )r   bs     r   _set_bindingszResult._set_bindings   s3    a%--y/?/?@A !DDNDNr   z$a list of variable bindings as dicts)docNformatcontent_typec                     ddl m} |r|}n|r|j                  dd      d   }nd} |j                  |t                     } |j
                  | fd|i|S )Nr   plugin;rH   xmlrx   )rdflibr{   splitrB   r   parse)sourcerw   rx   kwargsr{   
plugin_keyparsers          r   r   zResult.parse   s^     	"J%++C3A6JJ5J57v||FHHHHr   destinationencodingreturnc                 >   | j                   dv r  | j                  j                  |f||d|S 	 ddlm}  |j                  |t              |       }|:t               }t        |      } |j                  |fd|i| |j                         S t        |d      r-t        t        t           |      }	 |j                  |	fd|i| yt        t        |      }
t        |
      \  }}}}}}|dk7  rt!        d	       yt#        j$                         \  }}t'        j(                  |d
      }	 |j                  |	fd|i| |	j+                          t        t,        d      rt-        j.                  ||       yt-        j0                  ||       t'        j2                  |       y)a  
        Serialize the query result.

        The :code:`format` argument determines the Serializer class to use.

        - csv: :class:`~rdflib.plugins.sparql.results.csvresults.CSVResultSerializer`
        - json: :class:`~rdflib.plugins.sparql.results.jsonresults.JSONResultSerializer`
        - txt: :class:`~rdflib.plugins.sparql.results.txtresults.TXTResultSerializer`
        - xml: :class:`~rdflib.plugins.sparql.results.xmlresults.XMLResultSerializer`

        :param destination: Path of file output or BufferedIOBase object to write the output to.
        :param encoding: Encoding of output.
        :param format: One of ['csv', 'json', 'txt', xml']
        :param args:
        :return: bytes
        rc   rd   )r   rw   r   rz   Nr   r6    z<WARNING: not saving as locationis not a local file referencewbmove)rg   r   	serializer~   r{   rB   r   r	   r.   getvaluehasattrr   r   bytesr5   r
   printtempfilemkstemposfdopencloseshutilr   copyremove)r   r   r   rw   argsr{   
serializerstreambstream2r1   locationschemenetlocpathparamsr"   fragmentfdr<   s                      r   r   zResult.serialize   s   . 9911'4::''&.vAE  	4!9VZZ(89$?
&yG'0G J  D8DtD##%%;("U)[1F J  C(CdC$ ! C-H<DX<N9FFD&%|W '')HBYYr4(F J  C(CdCLLNvv&D$'  D$'		$r   c                     | j                   dk(  ry| j                   dk(  rt        | j                        S t        | j                        S )Nrf   rH   re   )rg   lenbindingsr   r]   s    r   __len__zResult.__len__  s:    99YY("t}}%%tzz?"r   c                 T    | j                   dk(  r| j                  S t        |       dkD  S )Nrf   r   )rg   rk   r   r]   s    r   __bool__zResult.__bool__  s&    99>>!t9q= r   c              #     K   | j                   dv r| j                  D ]  }|  y | j                   dk(  r| j                   y | j                   dk(  r| j                  rO| j                  D ]8  }|s| j                  j                  |       t        || j                         : d | _        y | j                  D ]  }|st        || j                          y y w)Nr   rf   re   )rg   r   rk   rj   ri   appendr?   rh   )r   trt   s      r   __iter__zResult.__iter__#  s     9911ZZ YY%.. YY("   ** 6A--a0'499556 %)! 6A'499556 #s   A/C2ACCc                 l   | j                   dv r(| j                  | j                  j                  | |      S | j                   dk(  rX|dk(  rSt        j                  dt
        d       | j                  D cg c]   t        fd| j                  D              " c}S t        d| d	|d      c c}w )
Nr   re   resultzPaccessing the 'result' attribute is deprecated. Iterate over the object instead.   )
stacklevelc              3   (   K   | ]	  }|     y wr   r   )rC   rD   rt   s     r   rF   z%Result.__getattr__.<locals>.<genexpr>B  s     3A1Q43s   'z' object has no attribute ')
rg   r   r=   warningswarnDeprecationWarningr   rT   rh   rS   )r   r<   rt   s     `r   r=   zResult.__getattr__7  s    9911djj6L::))$55YY("tx'7MM4"	 ?CmmLU333LL d!STT Ms   7%B1c                 N   	 | j                   |j                   k7  ry| j                   dk(  r| j                  |j                  k(  S | j                   dk(  r4| j                  |j                  k(  xr | j                  |j                  k(  S | j                  |j                  k(  S #  Y yxY w)NFrf   re   )rg   rk   rh   r   r   )r   others     r   __eq__zResult.__eq__F  s    
	yyEJJ&yyE!~~88h&yyEJJ.R4==ENN3RRzzU[[00	s   B  'B  AB  B   B$)NNN)Nr3   r}   )r#   r$   r%   r&   r5   r   rn   ru   propertyr   staticmethodr   r   r   r   r   r   r   r   r   r=   r   r   r   r   r   r      s    $
#c 
# }*PH  $&*II smI I* 15	9eCGn-9 9 	9 
%9v#!6(Ur   r   c                       e Zd Zd Zd Zy)r   c                      y r   r   r]   s    r   r   zResultParser.__init__U  r   r   c                      y)zreturn a Result objectNr   )r   r   r   s      r   r   zResultParser.parseX      r   N)r#   r$   r%   r   r   r   r   r   r   r   T  s    r   r   c                   *    e Zd ZdefdZddedefdZy)r   r   c                     || _         y r   )r   )r   r   s     r   r   zResultSerializer.__init__^  s	    r   r1   r   c                      y)z#return a string properly serializedNr   )r   r1   r   r   s       r   r   zResultSerializer.serializea  r   r   N)r3   )r#   r$   r%   r   r   r   r5   r   r   r   r   r   r   ]  s!    v  c r   r   )!r   rr   r   r   r   rp   typingr   r   r   r   r   r   ior	   urllib.parser
   __all__rdflib.graphr   rdflib.termr   objectr   r(   	Exceptionr   r.   rT   r?   r   r   r   r   r   r   <module>r      s    	      A A  !
X"$ "f (	i 	, ,*@N @NF|V |~6 v r   