
    4Ysh                         d dl Z d dlmZmZmZmZmZmZ d dlm	Z	m
Z
mZmZ d dlmZmZmZmZ 	  G d de      Z G d de      Z G d	 d
e	      Zd Zd Zy)    N)IOAnyDictOptionalTextIOUnion)ResultResultExceptionResultSerializerResultParser)LiteralURIRefBNodeVariablec                       e Zd ZddZy)JSONResultParserNc                     |j                         }t        |t              r|j                  d      }t	        t        j                  |            S )Nzutf-8)read
isinstancebytesdecode
JSONResultjsonloads)selfsourcecontent_typeinps       /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/sparql/results/jsonresults.pyparsezJSONResultParser.parse   s8    kkmc5!**W%C$**S/**    N)__name__
__module____qualname__r     r!   r   r   r      s    +r!   r   c                   *    e Zd Zd ZddedefdZd Zy)JSONResultSerializerc                 0    t        j                  | |       y r"   )r   __init__)r   results     r   r*   zJSONResultSerializer.__init__   s    !!$/r!   Nstreamencodingc                    i }| j                   j                  dk(  ri |d<   | j                   j                  |d<   n_i |d<   i |d<   | j                   j                  |d   d<   | j                   j                  D cg c]  }| j                  |       c}|d   d<   t        j                  |dd      }|!|j                  |j                  |             y |j                  |       y c c}w )	NASKheadbooleanresultsvarsbindingsF)	allow_nanensure_ascii)
r+   type	askAnswerr3   r4   _bindingToJSONr   dumpswriteencode)r   r,   r-   resxrs         r   	serializezJSONResultSerializer.serialize    s     ;;u$CK![[22C	N  C	NCK"&++"2"2CK040D0D*+,##A&*C	N:& JJse%@LL(+,LLO*s   9C'c                 `    i }|D ]&  }t        | ||         }|t        | ||         ||<   ( |S r"   )
termToJSON)r   br=   varjs        r   r9   z#JSONResultSerializer._bindingToJSON5   sF     	4C43(A}%dAcF3C	4 
r!   r"   )r#   r$   r%   r*   r   strr@   r9   r&   r!   r   r(   r(      s    0 c *r!   r(   c                       e Zd Zd Zd Zy)r   c                    || _         d|v rd}nd|v rd}nt        d      t        j                  | |       |dk(  rt	        |d         | _        y | j                         | _        |d   d   D cg c]  }t        |       c}| _	        y c c}w )Nr1   r/   r2   SELECTzNo boolean or results in json!r0   r3   )
r   r
   r	   r*   boolr8   _get_bindingsr4   r   r3   )r   r   type_r>   s       r   r*   zJSONResult.__init__?   s    	E$E!"BCCe$E>!$y/2DN ..0DM.26l6.BC!CDICs   /B
c                     g }| j                   d   d   D ]D  }i }|j                         D ]  \  }}t        |      |t        |      <    |j	                  |       F |S )Nr2   r4   )r   itemsparseJsonTermr   append)r   retrowoutRowkvs         r   rK   zJSONResult._get_bindingsP   sh    99Y'
3 	CF		 71&3A&6x{#7JJv		
 
r!   N)r#   r$   r%   r*   rK   r&   r!   r   r   r   >   s    D"r!   r   c                    | d   }|dk(  rt        | d         S |dk(  r/t        | d   | j                  d      | j                  d            S |dk(  rt        | d   t        | d         	      S |d
k(  rt        | d         S t	        d|z        )zrdflib object (Literal, URIRef, BNode) for the given json-format dict.

    input is like:
      { 'type': 'uri', 'value': 'http://famegame.com/2006/01/username' }
      { 'type': 'literal', 'value': 'drewp' }
    r7   urivalueliteraldatatypexml:lang)rZ   langztyped-literal)rZ   bnodezjson term type %r)r   r   getr   NotImplementedError)dts     r   rO   rO   Z   s     	
&	AEzaj!!	
iqzAEE*,=AEE*DUVV	
o	qzF1Z=,ABB	
gQwZ  !"5"9::r!   c                 t   t        |t              rdt        |      dS t        |t              rOdt        |      d}|j                  t        |j                        |d<   |j
                  |j
                  |d<   |S t        |t              rdt        |      dS |y t        d|dt        |      d	      )
NrW   )r7   rX   rY   rZ   r[   r]   zUnknown term type: z ())	r   r   rF   r   rZ   languager   r
   r7   )r   termr?   s      r   rB   rB   o   s    $D	22	D'	"T3==$.AjM==$ MMAjM	D%	 #d)44	dDJOPPr!   )r   typingr   r   r   r   r   r   rdflib.queryr	   r
   r   r   rdflibr   r   r   r   r   r(   r   rO   rB   r&   r!   r   <module>ri      sP     9 9 P P 3 3	+| ++ D 8;*Qr!   