
    4Yshq                     0   d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	m
Z
 	 d d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d!dZedk(  rd dlmZmZ d dlZ ee      Zej7                  d         ed ede      dz    ede      z         Zej;                  d        ej=                  ej>                  d         Z  e!e         e!e d    jE                  i              d dl#m$Z$m%Z% y)"    )
MethodType)OrderedDict)TokenConverterParseResultsoriginalTextFor)BNodeVariablec           	         t        |t              r|j                  |       S t        |t              rt	        d|z        t        |t
              r|D cg c]  }t        | |||       c}S t        |t        t        f      r3| j                  |      }t        |t              r|s|||S |r|S t        t        |t              rt        |      dk(  rt        | |d   ||      S |S c c}w )a  
    utility function for evaluating something...

    Variables will be looked up in the context
    Normally, non-bound vars is an error,
    set variables=True to return unbound vars

    Normally, an error raises the error,
    set errors=True to return error

    z$What do I do with this CompValue? %s   r   )
isinstanceExpreval	CompValue	Exceptionlistvaluer   r	   getSPARQLErrorNotBoundErrorr   len)ctxval	variableserrorsxrs         /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/sparql/parserutils.pyr   r   *   s     #txx}	C	#>DEE	C	:=>Qc1i0>>	C%*	+GGCLa%fG=H J	C	&3s8q=S#a&)V44
% ?s   C&c                       e Zd ZdZd Zd Zy)
ParamValuezq
    The result of parsing a Param
    This just keeps the name/value
    All cleverness is in the CompValue
    c                     || _         || _        t        |t        t        f      rt        |      dk(  r|d   }|| _        y )Nr   r   )isListnamer   r   r   r   	tokenList)selfr"   r#   r!   s       r   __init__zParamValue.__init__Y   s:    	i$!563y>Q;N!!I"    c                 <    d| j                   d| j                  dS )NzParam(z, ))r"   r#   r$   s    r   __str__zParamValue.__str__a   s    "&))T^^<<r&   N)__name__
__module____qualname____doc__r%   r*    r&   r   r   r   R   s    #=r&   r   c                       e Zd ZdZddZd Zy)Paramz
    A pyparsing token for labelling a part of the parse-tree
    if isList is true repeat occurrences of ParamList have
    their values merged in a list
    c                     || _         t        j                  | |       | j                  |       | j	                  | j
                         y N)r!   r   r%   setNameaddParseAction
postParse2)r$   r"   exprr!   s       r   r%   zParam.__init__l   s7    d+TDOO,r&   c                 D    t        | j                  || j                        S r3   )r   r"   r!   )r$   r#   s     r   r6   zParam.postParse2r   s    $))Y<<r&   N)F)r+   r,   r-   r.   r%   r6   r/   r&   r   r1   r1   e   s    -=r&   r1   c                       e Zd ZdZd Zy)	ParamListz1
    A shortcut for a Param with isList=True
    c                 4    t         j                  | ||d       y )NT)r1   r%   r$   r"   r7   s      r   r%   zParamList.__init__{   s    tT4.r&   N)r+   r,   r-   r.   r%   r/   r&   r   r:   r:   v   s    /r&   r:   c                       e Zd ZdZy)plistz:this is just a list, but we want our own type to check forN)r+   r,   r-   r.   r/   r&   r   r>   r>      s    Dr&   r>   c                   D    e Zd ZdZd Zd Zd Zd ZddZd Z	ddZ
d	 Zy
)r   zo
    The result of parsing a Comp
    Any included Params are available as Dict keys
    or as attributes

    c                 ^    t        j                  |        || _        | j                  |       y r3   )r   r%   r"   update)r$   r"   valuess      r   r%   zCompValue.__init__   s#    T"	Fr&   c                 .    t        | j                  fi | S r3   )r   r"   r)   s    r   clonezCompValue.clone   s    +d++r&   c                 L    | j                   dz   t        j                  |       z   S N_)r"   r   r*   r)   s    r   r*   zCompValue.__str__   s     yy3!4!4T!:::r&   c                 L    | j                   dz   t        j                  |       z   S rF   )r"   dict__repr__r)   s    r   rJ   zCompValue.__repr__   s    yy3t!444r&   c                 L    | j                   t        | j                   ||      S |S r3   )r   r   )r$   r   r   r   s       r   _valuezCompValue._value   s$    883	22Jr&   c                 L    | j                  t        j                  | |            S r3   )rL   r   __getitem__r$   as     r   rN   zCompValue.__getitem__   s    {{;224;<<r&   c                 R    | j                  t        j                  | ||      ||      S r3   )rL   r   r   )r$   rP   r   r   s       r   r   zCompValue.get   s"    {{;??4A6	6JJr&   c                 H    |dv r
t               	 | |   S # t        $ r Y y w xY w)N)_OrderedDict__root_OrderedDict__end)AttributeErrorKeyErrorrO   s     r   __getattr__zCompValue.__getattr__   s4    ;; ""	7N 		s    	!!NFF)r+   r,   r-   r.   r%   rD   r*   rJ   rL   rN   r   rW   r/   r&   r   r   r      s0    
,;5=Kr&   r   c                   .     e Zd ZdZd fd	Zi fdZ xZS )r   z)
    A CompValue that is evaluatable
    c                 d    t        t        | 
  |fi | d | _        |rt	        ||       | _        y y r3   )superr   r%   _evalfnr   )r$   r"   evalfnrB   	__class__s       r   r%   zExpr.__init__   s4    dD"4262%fd3DL r&   c                     	 || _         | j                  |      d | _         S # t        $ r}|cY d }~d | _         S d }~ww xY w# d | _         w xY wr3   )r   r\   r   )r$   r   es      r   r   z	Expr.eval   sK    	DH<<$ DH  	HDH	 DHs$   ! 	=8=A  =A   	A	r3   )r+   r,   r-   r.   r%   r   __classcell__)r^   s   @r   r   r      s    4  r&   r   c                   "    e Zd ZdZd Zd Zd Zy)Compz
    A pyparsing token for grouping together things with a label
    Any sub-tokens that are not Params will be ignored.

    Returns CompValue / Expr objects - depending on whether evalFn is set.
    c                 n    || _         t        j                  | |       | j                  |       d | _        y r3   )r7   r   r%   r4   r]   r<   s      r   r%   zComp.__init__   s,    	d+Tr&   c                 @   | j                   r1t        | j                        }t        | j                   |      |_        nUt        | j                        }| j                  dk(  r1t        | j                        }|j                  |      d   d   }||d<   |D ]  }t        |t              s|j                  rN|j                  |vrt               ||j                  <   ||j                     j                  |j                         n|j                  ||j                  <    |S )NServiceGraphPatternr   service_string)r]   r   r"   r   r\   r   r   r7   searchStringr   r   r!   r>   appendr#   )r$   instringlocr#   ressgprg   ts           r   	postParsezComp.postParse   s    ;;tyy/C$T[[#6CKDII&Cyy11 &dii0!$!1!1(!;A!>q!A(6$% 	.A!Z(88vvS(&+gAFFK&&q{{3"#++CK	. 
r&   c                     || _         | S r3   )r]   )r$   r]   s     r   	setEvalFnzComp.setEvalFn   s    r&   N)r+   r,   r-   r.   r%   ro   rq   r/   r&   r   rc   rc      s    6r&   rc   c           	         g }t        | t              r| j                         D ]!  }|j                  t	        |||dz                # t        | j                               D ]@  \  }}|j                  |d|z  d|d       |j                  t	        |||dz                B nGt        | t              r}|j                  |d|z  d| j                  d       | j                         D ]C  \  }}|j                  |d|dz   z  d|d       |j                  t	        |||dz                E nt        | t              rW| j                         D ]C  \  }}|j                  |d|dz   z  d|d       |j                  t	        |||dz                E nSt        | t              r'| D ]!  }|j                  t	        |||dz                # n|j                  |d|z  d| d       dj                  |      S )	Nr   z  z- z:
z>    
 )r   r   asListri   prettify_parsetreesorteditemsr   r"   rI   r   join)rn   indentdepthoutr`   kvs          r   rw   rw      s   
C!\" 	AAJJ)!VUQY?@	A1779% 	ADAqJJua@AJJ)!VUQY?@	A 
Ay	!

FD5L!&&ABGGI 	ADAqJJ	0BAFGJJ)!VUQY?@	A 
At	GGI 	ADAqJJ	0BAFGJJ)!VUQY?@	A 
At	 	AAJJ)!VUQY?@	A 	

64%<;<773<r&   __main__)WordnumsNc                     t        | d         S )Nr   )int)r   s    r   <lambda>r     s    C!I r&   plusrP   +bc                 4    | j                   | j                  z   S r3   )rP   r   )r$   r   s     r   r   r     s    TVVdff_ r&   r   )r   r   rX   )ru   r   )&typesr   collectionsr   	pyparsingr   r   r   rdflibr   r	   r   objectr   r1   r:   r   r>   r   r   rc   rw   r+   r   r   sysNumbersetParseActionPlusrq   parseStringargvr   printr   rdflib.plugins.sparql.sparqlr   r   r/   r&   r   <module>r      s    # C C "B%P= =&=N ="/ /	D 	+ +\9 ,,> ,^2 z$$ZF
-.c6*S05f3EEFDNN45!%A	!H	!A$))B- D Cr&   